Question 1
#include <iostream>
using namespace std;
class A
{
protected:
int x;
public:
A() {x = 0;}
friend void show();
};
class B: public A
{
public:
B() : y (0) {}
private:
int y;
};
void show()
{
A a;
B b;
cout << \"The default value of A::x = \" << a.x << \" \";
cout << \"The default value of B::y = \" << b.y;
}
Question 2
Predict the output the of following program.
#include <iostream>
using namespace std;
class B;
class A {
int a;
public:
A():a(0) { }
void show(A& x, B& y);
};
class B {
private:
int b;
public:
B():b(0) { }
friend void A::show(A& x, B& y);
};
void A::show(A& x, B& y) {
x.a = 10;
cout << \"A::a=\" << x.a << \" B::b=\" << y.b;
}
int main() {
A a;
B b;
a.show(a,b);
return 0;
}
Question 4
There are 4 questions to complete.