Advertisement
Roctik

Untitled

Jun 24th, 2019
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.66 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. class Quad{
  6.     public:
  7.     int a,b;
  8.     Quad(){
  9.         cout << "Конструктор чотирикутник " << endl;
  10.     }
  11.    
  12.     void setSide(){
  13.       cout<<"Введіть сторону а: ";
  14.       cin>>a;
  15.       cout<<"Введіть сторону б: ";
  16.       cin>>b;
  17.   }
  18.   double getPer(){
  19.       return 2*(a+b);
  20.   }
  21.   double getSquare(){
  22.       return a*b;
  23.   }
  24.    
  25.     ~Quad(){}
  26.    
  27. };
  28. class Square : public Quad{
  29.   public:
  30.  
  31.   Square(){
  32.       cout<<"Конструктор квадрат "<<endl;
  33.   }
  34.   double getPer(){
  35.       return 2*(a+b);
  36.   }
  37.   double getSquare(){
  38.       return a*b;
  39.   }
  40.   ~Square(){}
  41. };
  42.  
  43. class Rectangle: public Quad{
  44.   public:
  45.   Rectangle(){
  46.       cout<<"Конструктор прямокутник "<<endl;
  47.   }
  48.   double getPer(){
  49.       return 2*(a+b);
  50.   }
  51.   double getSquare(){
  52.       return a*b;
  53.   }
  54.   ~Rectangle(){}
  55. };
  56. int main()
  57. {
  58.     Quad objQuad;
  59.     Square objSquare;
  60.     Rectangle objRect;
  61.     cout<<"Введіть сторони чотирикутника"<<endl;
  62.     objQuad.setSide();
  63.     cout<<"Периметр: "<<objQuad.getPer()<<endl;
  64.     cout<<"Площа: "<<objQuad.getSquare<<endl;
  65.    
  66.     cout<<"Введіть сторони квадрата"<<endl;
  67.     objSquare.setSide();
  68.     cout<<"Периметр: "<<objSquare.getPer()<<endl;
  69.     cout<<"Площа: "<<objSquare.getSquare<<endl;
  70.    
  71.     cout<<"Введіть сторони прямокутника"<<endl;
  72.     objRect.setSide();
  73.     cout<<"Периметр: "<<objRect.getPer()<<endl;
  74.     cout<<"Площа: "<<objRect.getSquare<<endl;
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement