Advertisement
nikitakrut58

1.2.2

Apr 6th, 2020
565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.19 KB | None | 0 0
  1. #include <iostream>
  2. #include "Treu.h"
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     Treu tr;
  8.         tr.schet();
  9.         tr.kol();
  10.         tr.vivod();
  11.         tr.reverse();
  12.         cout << "\n";
  13.         tr.vivod();
  14. }
  15. ==============================
  16. #ifndef Treu_h
  17. #define Treu_h
  18.  
  19. class Treu {
  20. private:
  21.     int n_n, * mas;
  22. public:
  23.     Treu();
  24.     void kol();
  25.     void schet();
  26.     void vivod();
  27.     void reverse();
  28.     ~Treu();
  29. };
  30. #endif
  31. ========================================
  32. #include "Treu.h"
  33. #include <iostream>
  34. #include <string>
  35.  
  36. using namespace std;
  37.  
  38. Treu::Treu() {
  39.     cin >> n_n;
  40.     if (n_n <= 10) {
  41.         mas = new int[n_n];
  42.     }
  43.     else {
  44.         exit(1);
  45.     }
  46. }
  47.  
  48. void Treu::kol() {
  49.     cout << "N" << " " << "=" << " " << n_n << endl;
  50. }
  51.  
  52. void Treu::schet() {
  53.         for (int i = 0; i < n_n; i++) {
  54.             cin >> mas[i];
  55.         }
  56. }
  57. void Treu::vivod() {
  58.     string res = "";
  59.     for (int i = 0; i < n_n; i++) {
  60.         string buf = "";
  61.         buf = to_string(mas[i]);
  62.         for (int j = 0; j < (5 - (int)buf.length()); j++) {
  63.             res = res + " ";
  64.         }
  65.         res = res + buf;
  66.     }
  67.     cout << res;
  68. }
  69. void Treu::reverse()
  70. {
  71.     for (int i = 0; i < n_n / 2; i++)
  72.     {
  73.         int t = mas[i];
  74.         mas[i] = mas[n_n - i - 1];
  75.         mas[n_n - i - 1] = t;
  76.     }
  77. }
  78. Treu::~Treu() {
  79.     delete[]mas;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement