Examen Program Are II - Grila2
Examen Program Are II - Grila2
c)
d)
A()
A(A&)
A(A&)
B(A a)
A()
A()
A(A&)
A(A&)
B(A a)
delete tab[0];
delete tab[1];
_getch();
return 0;
};
}
A(int xx) {x = xx;
cout << "A(int)" << endl;
}
virtual ~A() {
cout << "~A()" << endl;
_getch();
}
virtual void f() {cout << "A::f()" << endl;}
virtual void g() {cout << "A::g()" << endl;}
void h() {cout << "A:h()" << endl;}
class B: public A{
private:
int z;
public:
B(){
z = 0;
cout << "B()" << endl;
}
B(int x): A(x) {
z = 2 * x;
cout << "B(int)" << endl;
}
~B() {
cout << "~B()" << endl;
}
void f() {cout << "B::f()" << endl;}
void g() {cout << "B::g()" << endl;}
void h() {cout << "B:h()" << endl;}
};
class C: public B {
protected:
int y;
public:
C(){
y = 0;
cout << "C()" << endl;
}
C(int x) {
y = x;
cout << "C(int)" << endl;
}
~C() {
cout << "~C()" << endl;
}
void f() {cout << "C::f()" << endl;}
void g() {cout << "C::g()" << endl;}
void h() {cout << "C::h()" << endl;}
};
int main() {
A* pa = new C(5);
pa -> f();
pa -> g();
pa -> h();
delete pa;
B * pb = new C(6);
pb -> f();
pb -> g();
pb -> h();
_getch();
return 0;
}
A()
B()
C(int)
C::f()
C::g()
B:h()
c)
A()
B()
C(int)
C::f()
C::g()
A:h()
~C()
~B()
~A()
A()
B()
C(int)
B::f()
B::g()
B:h()
A()
B()
C(int)
C::f()
C::g()
B:h()
~C()
~B()
~A()
d)
A()
B()
C(int)
C::f()
C::g()
A:h()
~C()
~B()
~A()
A()
B()
C(int)
B::f()
B::g()
B:h()
~C()
~B()
~A()
};
}
B(int x): A(x) {
cout << "B(int)" << endl;
}
~B() {
cout << "~B()" << endl;
}
class C: public A{
public:
C(){
cout << "C()" << endl;
}
C(int x): A(x) {
cout << "C(int)" << endl;
}
~C() {
cout << "~C()" << endl;
}
};
class D: public B, public C{
public:
D(int x): C(x) {
cout << "D(int)" << endl;
}
~D() {
cout << "~D()" << endl;
}
};
int main() {
D d(5);
_getch();
return 0;
}
c)
A(int)
C(int)
A()
B()
D(int)
~D()
~B()
~A()
~C()
~A()
~A()
d)
A()
B()
C(int)
D(int)
~D()
~C()
~B()
~A()