adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    using namespace std;
    class p 
    {
        protected:
        int width, height;
        public:
        void set_values (int a, int b)
        {
            width = a; height = b; 
        }
        virtual int area (void) = 0;
    };
    class r: public p
    {
        public:
        int area (void)
        { 
            return (width * height);
        }
    };
    class t: public p 
    {
        public:
        int area (void)
        {
            return (width * height / 2); 
        }
    };
    int main () 
    {
        r rect;
        t trgl;
        p * ppoly1 = &rect;
        p * ppoly2 = &trgl;
        ppoly1->set_values (4, 5);
        ppoly2->set_values (4, 5);
        cout << ppoly1 -> area() ;
        cout << ppoly2 -> area();
        return 0;
    }

a.

1020

b.

20

c.

10

d.

2010

Answer: (d).2010

Engage with the Community - Add Your Comment

Confused About the Answer? Ask for Details Here.

Know the Explanation? Add it Here.

Q. What is the output of this program?