Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 KB | None | 0 0
  1. #include "pch.h"
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. class chlen { // объявление класса
  7. protected: // переменные, которые будем передавать во второй класс
  8. int n, m;
  9. float **mas;
  10. public:
  11. chlen() {} // конструктор по умолчанию
  12. chlen(float **mas) { // конструктор с параметром
  13. this->mas = mas;
  14. }
  15. ~chlen() { // деструктор
  16. for (int i = 0; i < n; i++) {
  17. delete[] mas[i];
  18. }
  19. delete[] mas;
  20. }
  21. void setarray() { // выделение памяти под массив
  22. cout << "Введите размер матрицы: ";
  23. cin >> n >> m;
  24. cout << endl;
  25. mas = new float*[n];
  26. for (int i = 0; i < n; i++) {
  27. mas[i] = new float[m];
  28. }
  29. }
  30. void zapolnenie() { // рандомное заполнение массива, ничего необычного
  31. cout << "Введите массив: " << endl;
  32. for (int i = 0; i < n; i++) {
  33. for (int j = 0; j < m; j++) {
  34. cin >> mas[i][j];
  35. }
  36. }
  37. }
  38. void showarray() { // вывод массива на экран, тоже все как обычно
  39. cout << "Массив:" << endl;
  40. for (int i = 0; i < n; i++) {
  41. for (int j = 0; j < m; j++) {
  42. cout << mas[i][j] << "\t";
  43. }
  44. cout << endl;
  45. }
  46. }
  47. };
  48.  
  49. class Jepa : public chlen
  50. {
  51. private:
  52. int max;
  53. float x;
  54. public:
  55. Jepa(){}
  56. Jepa(int max, float x) : chlen(mas)
  57. {
  58. this->max = max;
  59. this->x = x;
  60. }
  61. void fun1()
  62. {
  63. max = 0;
  64. for (int j = 0; j < m; j++) {
  65. for (int i = 0; i < n; i++) {
  66. if (mas[i][j] > max) {
  67. max = mas[i][j];
  68. }
  69. }
  70. mas[0][j] = max;
  71. max = 0;
  72. }
  73. }
  74.  
  75. bool fun2()
  76. {
  77. cout << "Введите желаемую величину: ";
  78. cin >> x;
  79. for (int i = 0; i < n; i++) {
  80. if (mas[i] < &x)
  81. {
  82. return true;
  83. }
  84. }
  85. return false;
  86. }
  87.  
  88. void fun3()
  89. {
  90. if (fun2() == true)
  91. {
  92. for (int i = 0; i < n; i++) {
  93. for (int j = 0; j < m; j++) {
  94. mas[n - 1][j] = mas[n - 1][j] / mas[0][j];
  95. }
  96. }
  97. }
  98. if(fun2() == false)
  99. {
  100. cout << "chlen" << endl;
  101. }
  102. }
  103. };
  104.  
  105.  
  106.  
  107. int main()
  108. {
  109. setlocale(LC_ALL, "Russian");
  110. Jepa obj;
  111. obj.setarray();
  112. obj.zapolnenie();
  113. obj.fun1();
  114. obj.fun3();
  115. obj.showarray();
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement