What will be the output of the following C++ code? [code] #include <iostream> using namespace std; class sample; class

Lan Anh

New member
What will be the output of the following C++ code?
Code:
    #include <iostream>
    using namespace std;
    class sample;
    class sample1 
    {
        int width, height;
        public:
        int area ()
        {
            return (width * height);}
            void convert (sample a);
        };
    class sample 
    {
        private:
        int side;
        public:
        void set_side (int a)
        { 
            side = a;
        }
        friend class sample1;
    };
    void sample1::convert (sample a) 
    {
        width = a.side;
        height = a.side;
    }
    int main () 
    {
        sample sqr;
        sample1 rect;
        sqr.set_side(6);
        rect.convert(sqr);
        cout << rect.area();
        return 0;
    }
A. 24
B. 35
C. 16
D. 36
 

Tìm kiếm

Back
Top