Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Figure
- {
- };
- class Square : public Figure
- {
- private:
- double a;
- public:
- double calculateSquare() override
- {
- return a * a;
- }
- double calculatePerimeter()
- {
- return 4 * a;
- }
- Square(int a)
- {
- this->a = a;
- }
- void setA(double a){
- this->a = a;
- }
- double getA(){
- return a;
- }
- };
- class Circle : public Figure
- {
- private:
- double radius;
- public:
- double calculateSquare()
- {
- return M_PI * radius * radius;
- }
- double calculatePerimeter()
- {
- return 2 * M_PI * radius;
- }
- Circle(double r)
- {
- radius = r;
- }
- void setRadius(double r){
- this->radius = r;
- }
- double getRadius(){
- return radius;
- }
- };
- class Rectangle : public Figure
- {
- private:
- double a;
- double b;
- public:
- double calculateSquare()
- {
- return a * b;
- }
- double calculatePerimeter()
- {
- return 2 * a + 2 * b;
- }
- Rectangle(double a, double b)
- {
- this->a = a;
- this->b = b;
- }
- void setA(double a){
- this->a = a;
- }
- double getA(){
- return a;
- }
- void setB(double b){
- this->b = b;
- }
- double getB(){
- return b;
- }
- };
- int main()
- {
- Rectangle Pr(1, 2.0);
- Circle Kr(1);
- Square Kv(2);
- Figure* mas[3] = { &Pr,&Kr,&Kv };
- Figure ** arr = new Figure * [3];
- 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;
- 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;
- 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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement