Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2022
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. #include <windows.h>
  2. #include <iostream>
  3. #include <iomanip>
  4. #include <string>
  5. #include <math.h>
  6.  
  7. using namespace std;
  8. ////////////////////////
  9. void RusText(void);
  10.  
  11. class AnyClass
  12. {
  13. public:
  14. //переменные
  15. int n;
  16.  
  17. int *arr;
  18. int *arrNew;
  19.  
  20. int cnt;
  21. int indx;
  22.  
  23. /////////////
  24.  
  25. void Inputer()
  26. {
  27. int a;
  28. arr= new int [cnt];
  29. if (arr==NULL)
  30. {
  31. delete [] arr;
  32. cout << "Ошибка Выделения Основной Памяти" << endl;
  33. return;
  34. }
  35. do
  36. {
  37. cout << "Вводите корректные целые числа..." << endl; cin >> n;
  38.  
  39. if (!(n%3))
  40. {
  41. cout << "Индекс= " << indx << endl;
  42.  
  43. if (indx==cnt)
  44. {
  45. cnt=cnt +3;
  46. arrNew= new int [cnt];
  47. if (arrNew==NULL)
  48. {
  49. cout << "Ошибка Выделения Дополнительной Памяти" << endl;
  50. delete [] arr; delete [] arrNew;
  51. return;
  52. }
  53.  
  54. for (a=0; a< indx; a++) arrNew[a]= arr[a];
  55.  
  56. delete [] arr;
  57. arr= arrNew;
  58. }
  59. arr[indx]= n; indx++;
  60. }
  61. else cout << "Число 'НЕКРАТНОЕ 3' в массив не попало" << endl;
  62.  
  63. } while (cin.good());
  64.  
  65. cout << "Останов: некорректное целое число. Смотрим результат" << endl;
  66.  
  67. int ln=3; indx--;
  68. for (a=0; a< indx; a++)
  69. {
  70. if (!ln) { cout << endl; ln= 3; }
  71. ln--;
  72. cout << arr[a] << "\t";
  73. }
  74.  
  75. }
  76.  
  77. //////////////Конструктор
  78.  
  79. AnyClass ()
  80. {
  81. cnt= 3; indx=0;
  82. }
  83.  
  84. //////////////Деструктор
  85.  
  86. ~AnyClass()
  87. {
  88. delete [] arrNew;
  89. }
  90. };
  91.  
  92. int main(int argc, char **argv)
  93. {
  94. RusText();
  95.  
  96. AnyClass a;
  97.  
  98. a.Inputer();
  99.  
  100. cout << endl; system("pause");
  101. return 0;
  102. }
  103.  
  104. ////////// Руссификация сообщений //////////////////////////////////
  105.  
  106. void RusText(void)
  107. {
  108. system("chcp 1251 > nul");
  109. SetConsoleTitle(TEXT("ОтветыМейлРу")); //Для совместимости с VS
  110. return;
  111. }
  112.  
  113.  
  114.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement