Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- #define PI 3.14
- class Shape{
- public:
- shape(){}
- virtual int getArea() const { return 0;}
- };
- class Circle : public Shape {
- private:
- double r;
- public:
- Circle(int _r) {r=_r;}
- int getArea() const { return PI*r*r;}
- };
- class Rectangle : public Shape{
- private:
- int width, length;
- public:
- Rectangle(int w, int l){width =w; length = l;}
- int getArea() const { return width * length; }
- };
- void displayArea(const Shape *p)
- {
- cout << "Area = " << p->getArea() << endl;
- }
- int main()
- // Bo away ba automaticy bot bkat
- {
- // Shape s;
- // Circle c(10);
- // Rectangle r(2,6);
- // displayArea(&s);
- // displayArea(&c);
- // displayArea(&r);
- // Shape *p;
- // Bo away dana ba dana bikay
- // Shape s;
- // Circle c(10);
- // Rectangle r(2,6);
- //
- // p = &s;
- // cout << "Shape area = " << p-> getArea() << endl;
- // p = &c;
- // cout << "Cricle area = " << p-> getArea() << endl;
- // p = &r;
- // cout << "Rectangle area = " << p-> getArea() << endl;
- //shewazeke tr
- Shape s;
- Circle c(10);
- Rectangle r(2,6);
- Shape *list[3] = { &s, &c, &r };
- for (int i=0; i<3; i++)
- cout << "Area = " << list[i]->getArea()
- << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement