Examveda

What will be the output of the following C++ code?
#include <iostream>
using namespace std;
class Rect
{
    int x, y;
    public:
    void set_values (int,int);
    int area ()
    {
        return (x * y);
    }
};
void Rect::set_values (int a, int b) 
{
    x = a;
    y = b;
}
int main ()
{
    Rect recta, rectb;
    recta.set_values (5, 6);
    rectb.set_values (7, 6);
    cout << "recta area: " << recta.area();
    cout << "rectb area: " << rectb.area();
    return 0;
}

A. recta area: 30 rectb area: 42

B. recta area: 20 rectb area: 34

C. recta area: 30 rectb area: 21

D. recta area: 30 rectb area: 33

Answer: Option A


Join The Discussion

Related Questions on Classes and Objects in C plus plus