Advertisement
vertexofvortex

pr10matveeva

Dec 10th, 2020
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.35 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class MyClass {
  6. protected:
  7.     int c_x, c_y, result;
  8.  
  9. public:
  10.     void setX(int x) {
  11.         c_x = x;
  12.     }
  13.     void setY(int y) {
  14.         c_y = y;
  15.     }
  16.     int getX() {
  17.         return c_x;
  18.     }
  19.     int getY() {
  20.         return c_y;
  21.     }
  22.     int getResult() {
  23.         if (c_x < c_y) {
  24.             result = c_x * c_x;
  25.         }
  26.         if (c_x > c_y) {
  27.             result = c_y * c_y;
  28.         }
  29.  
  30.         return result;
  31.     }
  32. };
  33. class MyClass2 : public MyClass {
  34. private:
  35.     int c_z, new_result;
  36. public:
  37.     void setZ(int z) {
  38.         c_z = z;
  39.     }
  40.     int getZ() {
  41.         return c_z;
  42.     }
  43. };
  44.  
  45. int main() {
  46.     setlocale(LC_ALL, "rus");
  47.  
  48.     MyClass class1;
  49.     MyClass2 class2;
  50.     int x, y, z;
  51.  
  52.     cout << "Введите Х: ";
  53.     cin >> x;
  54.     cout << "Введите Y: ";
  55.     cin >> y;
  56.  
  57.     class1.setX(x);
  58.     class1.setY(y);
  59.  
  60.     cout << "Квадрат меньшего из введенных чисел равен: " << class1.getResult() << endl;
  61.  
  62.     cout << "Введите Z: ";
  63.     cin >> z;
  64.  
  65.     class2.setZ(z);
  66.  
  67.     if (class1.getX() < class1.getY()) {
  68.         cout << "Произведение Z на меньшее из введённых чисел равно: " << class2.getZ() * class1.getX() << endl;
  69.     }
  70.     if (class1.getX() > class1.getY()) {
  71.         cout << "Произведение Z на меньшее из введённых чисел равно: " << class2.getZ() * class1.getY() << endl;
  72.     }
  73.  
  74.     system("pause");
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement