SHARE
TWEET

Untitled

a guest Apr 23rd, 2019 123 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. const double pi = 3.14159265;
  7.  
  8. class Figure {
  9. public:
  10.     virtual double area() = 0;
  11.     virtual double perimeter() = 0;
  12. };
  13.  
  14. class Rectangle: public Figure {
  15. protected:
  16.     int w;
  17.     int h;
  18.  
  19. public:
  20.     Rectangle(int w, int h)
  21.     {
  22.         this->w = w;
  23.         this->h = h;
  24.     }
  25.  
  26.     int width()
  27.     {
  28.         return w;
  29.     }
  30.     int height()
  31.     {
  32.         return h;
  33.     }
  34.     virtual double area()
  35.     {
  36.         return w * h;
  37.     }
  38.     virtual double perimeter()
  39.     {
  40.         return 2 * (w + h);
  41.     }
  42.     friend istream& operator>> (istream&, Rectangle&);
  43.     friend ostream& operator<< (ostream&, const Rectangle&);
  44. };
  45.  
  46. istream& operator>> (istream& in, Rectangle& rect)
  47. {
  48.     in >> rect;
  49.     return in;
  50. }
  51.  
  52. ostream& operator<< (ostream& out, const Rectangle& rect)
  53. {
  54.     out << &rect;
  55.     return out;
  56. }
  57.     double array_area(Figure** array, int n)
  58.     {
  59.         double area = 0;
  60.         for (size_t i = 0; i < n; i++)
  61.         {
  62.             area += array[i]->area();
  63.         }
  64.         return area;
  65.     }
  66.     double array_perimeter(Figure** array, int n)
  67.     {
  68.         double perimeter = 0;
  69.         for (size_t i = 0; i < n; i++)
  70.         {
  71.             perimeter += array[i]->perimeter();
  72.         }
  73.         return perimeter;
  74.     }
  75.  
  76. class Circle: public Figure {
  77. protected:
  78.     int r;
  79.  
  80. public:
  81.     Circle(int r)
  82.     {
  83.         this->r = r;
  84.     }
  85.     int radius()
  86.     {
  87.         return r;
  88.     }
  89.     virtual double area()
  90.     {
  91.         return pi * r*r;
  92.     }
  93.     virtual double perimeter()
  94.     {
  95.         return 2 * pi * r;
  96.     }
  97.  
  98.     friend istream& operator>> (istream&, Circle&);
  99.     friend ostream& operator<< (ostream&, const Circle&);
  100. };
  101.  
  102. istream& operator>> (istream& in, Circle& circle)
  103. {
  104.     in >> circle;
  105.     return in;
  106. }
  107. ostream& operator<< (ostream& out, const Circle& circle)
  108. {
  109.     out << circle;
  110.     return out;
  111. }
  112.  
  113. int main()
  114. {
  115.     int n;
  116.     string command = "";
  117.     Figure* figures = new Figure[n];
  118.     cin >> n;
  119.     for (size_t i = 0; i < n; i++)
  120.     {
  121.         cin >> command;
  122.         if (command == "Rectangle")
  123.         {
  124.  
  125.         }
  126.         else if (command == "Circle")
  127.         {
  128.  
  129.         }
  130.     }
  131. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top