Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. #define PI 3.14
  6.  
  7. class Shape{
  8. public:
  9. shape(){}
  10. virtual int getArea() const { return 0;}
  11. };
  12.  
  13.  
  14. class Circle : public Shape {
  15. private:
  16. double r;
  17. public:
  18. Circle(int _r) {r=_r;}
  19.  
  20. int getArea() const { return PI*r*r;}
  21.  
  22. };
  23.  
  24. class Rectangle : public Shape{
  25. private:
  26. int width, length;
  27. public:
  28. Rectangle(int w, int l){width =w; length = l;}
  29. int getArea() const { return width * length; }
  30. };
  31. void displayArea(const Shape *p)
  32. {
  33. cout << "Area = " << p->getArea() << endl;
  34. }
  35. int main()
  36. // Bo away ba automaticy bot bkat
  37. {
  38. // Shape s;
  39. // Circle c(10);
  40. // Rectangle r(2,6);
  41. // displayArea(&s);
  42. // displayArea(&c);
  43. // displayArea(&r);
  44. // Shape *p;
  45.  
  46. // Bo away dana ba dana bikay
  47. // Shape s;
  48. // Circle c(10);
  49. // Rectangle r(2,6);
  50. //
  51. // p = &s;
  52. // cout << "Shape area = " << p-> getArea() << endl;
  53. // p = &c;
  54. // cout << "Cricle area = " << p-> getArea() << endl;
  55. // p = &r;
  56. // cout << "Rectangle area = " << p-> getArea() << endl;
  57.  
  58. //shewazeke tr
  59.  
  60. Shape s;
  61. Circle c(10);
  62. Rectangle r(2,6);
  63.  
  64. Shape *list[3] = { &s, &c, &r };
  65.  
  66. for (int i=0; i<3; i++)
  67. cout << "Area = " << list[i]->getArea()
  68. << endl;
  69.  
  70. return 0;
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement