Advertisement
_DeNiS_On4Ik_

Untitled

Dec 30th, 2021
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.07 KB | None | 0 0
  1. class Figure
  2. {
  3. };
  4. class Square : public Figure
  5. {
  6. private:
  7.     double a;
  8. public:
  9.     double calculateSquare() override
  10.     {
  11.         return a * a;
  12.     }
  13.     double calculatePerimeter()
  14.     {
  15.         return 4 * a;
  16.     }
  17.     Square(int a)
  18.     {
  19.         this->a = a;
  20.     }
  21.     void setA(double a){
  22.         this->a = a;
  23.     }
  24.     double getA(){
  25.         return a;
  26.     }
  27. };
  28. class Circle : public Figure
  29. {
  30. private:
  31.     double radius;
  32. public:
  33.     double calculateSquare()
  34.     {
  35.         return M_PI * radius * radius;
  36.     }
  37.     double calculatePerimeter()
  38.     {
  39.         return 2 * M_PI * radius;
  40.     }
  41.     Circle(double r)
  42.     {
  43.         radius = r;
  44.     }
  45.     void setRadius(double r){
  46.         this->radius = r;
  47.     }
  48.     double getRadius(){
  49.         return radius;
  50.     }
  51. };
  52. class Rectangle : public Figure
  53. {
  54. private:
  55.     double a;
  56.     double b;
  57. public:
  58.     double calculateSquare()
  59.     {
  60.         return a * b;
  61.     }
  62.     double calculatePerimeter()
  63.     {
  64.         return 2 * a + 2 * b;
  65.     }
  66.     Rectangle(double a, double b)
  67.     {
  68.         this->a = a;
  69.         this->b = b;
  70.     }
  71.     void setA(double a){
  72.         this->a = a;
  73.     }
  74.     double getA(){
  75.         return a;
  76.     }
  77.     void setB(double b){
  78.         this->b = b;
  79.     }
  80.     double getB(){
  81.         return b;
  82.     }
  83. };
  84. int main()
  85. {
  86.     Rectangle Pr(1, 2.0);
  87.     Circle Kr(1);
  88.     Square Kv(2);
  89.     Figure* mas[3] = { &Pr,&Kr,&Kv };
  90.     Figure ** arr = new Figure * [3];
  91.     cout <<"Rectangle: " << endl <<"The perimeter of the rectangle is: "<< mas[0]->calculatePerimeter() << " (m)" << endl << "The area of ​​the rectangle is: " << mas[0]->calculateSquare() << " (m)" << endl;
  92.     cout <<"Circle: "<< endl <<"The perimeter of the circle is: " << mas[1]->calculatePerimeter() << " (m)" << endl <<"The area of ​​the circle is: " << mas[1]->calculateSquare() << " (m)" << endl;
  93.     cout <<"Square: "<< endl << "The perimeter of the square is: " << mas[2]->calculatePerimeter() << " (m)" << endl << "The area of ​​the square is: "<< mas[2]->calculateSquare() << " (m)" << endl;
  94.  
  95.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement