Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class MyClass {
- protected:
- int c_x, c_y, result;
- public:
- void setX(int x) {
- c_x = x;
- }
- void setY(int y) {
- c_y = y;
- }
- int getX() {
- return c_x;
- }
- int getY() {
- return c_y;
- }
- int getResult() {
- if (c_x < c_y) {
- result = c_x * c_x;
- }
- if (c_x > c_y) {
- result = c_y * c_y;
- }
- return result;
- }
- };
- class MyClass2 : public MyClass {
- private:
- int c_z, new_result;
- public:
- void setZ(int z) {
- c_z = z;
- }
- int getZ() {
- return c_z;
- }
- };
- int main() {
- setlocale(LC_ALL, "rus");
- MyClass class1;
- MyClass2 class2;
- int x, y, z;
- cout << "Введите Х: ";
- cin >> x;
- cout << "Введите Y: ";
- cin >> y;
- class1.setX(x);
- class1.setY(y);
- cout << "Квадрат меньшего из введенных чисел равен: " << class1.getResult() << endl;
- cout << "Введите Z: ";
- cin >> z;
- class2.setZ(z);
- if (class1.getX() < class1.getY()) {
- cout << "Произведение Z на меньшее из введённых чисел равно: " << class2.getZ() * class1.getX() << endl;
- }
- if (class1.getX() > class1.getY()) {
- cout << "Произведение Z на меньшее из введённых чисел равно: " << class2.getZ() * class1.getY() << endl;
- }
- system("pause");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement