194k views
4 votes
What is the output of the program?

#include
using namespace std;
class bClass
{
public:
a. void print() const;
bClass(int a = 0, int b = 0);
//Postcondition: x = a; y = b;
private:
int x;
int y;
};
class dClass: public bClass
{
public:
b. void print() const;
dClass(int a = 0, int b = 0, int c = 0);
//Postcondition: x = a; y = b; z = c;
private:
int z;
};
int main()
{
bClass bObject(2, 3);
dClass dObject(3, 5, 8);
bObject.print();
cout << endl;
dObject.print();
cout << endl;
return 0 ;
}
c. void bClass::print() const
{
cout << x << " " << y << endl;
}
bClass::bClass(int a, int b)
{
x = a;
y = b;
}
d. void dClass::print() const
{
bClass::print(); //added second colon
cout << " " << z << endl;
}
dClass::dClass(int a, int b, int c)
: bClass(a, b)
{
z = c;
}

User Jipumarino
by
6.1k points

1 Answer

6 votes

Answer:

the output of the above program is

2 3

3 5

8

Step-by-step explanation:

It seems the program is trying to pair two numbers into one and leaving the unpaired number (in a case of odd number of numbers) as a separate output.

This is why numbers 2 and 3 form 23, numbers 3 and 5 form 35 and 8 is another output of the program.

User Jeff Victorino
by
5.8k points