adplus-dvertising
frame-decoration

Question

What is the output of this program?
    #include <iostream>
    using namespace std;
    class polygon 
    {
        protected:
        int width, height;
        public:
        void set_values (int a, int b)
        { 
            width = a; height = b;}
        };
        class output1 
        {
            public:
                void output (int i);
        };
    void output1::output (int i) 
    {
        cout << i << endl;
    }
    class rectangle: public polygon, public output1 
    {
        public:
        int area ()
        { 
            return (width * height); 
        }
    };
    class triangle: public polygon, public output1 
    {
        public:
        int area ()
        {
            return (width * height / 2); 
        }
    };
    int main () 
    {
        rectangle rect;
        triangle trgl;
        rect.set_values (4, 5);
        trgl.set_values (4, 5);
        rect.output (rect.area());
        trgl.output (trgl.area());
        return 0;
    }

a.

20

b.

10

c.

20

d.

None of the mentioned

Answer: (c).20

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?