#include<iostream> usingnamespace std; class A{ public: void f(){ cout << ”Af” << endl; } virtualvoid g(){ cout << ”Ag” << endl; } }; class B : public A{ public: void f(){ cout << ”Bf” << endl; } virtualvoid g(){ cout << ”Bg” << endl; } }; class C : public B{public: void f(){ cout << ”Cf” << endl; } }; int main() { A a; C b; A∗ p; C∗ q; p = &a; p>f(); p>g(); p = &b; p>f(); p>g(); q = &b; q>f(); p>g(); q = (C ∗) &a; q>f(); p>g(); }
Show the output of the following program.
#include<iostream> usingnamespace std; namespace days { class cls { public: void speak(){ cout<<”Su Mo Tu We Th Fr Sa∖n”; } }; } namespace months { class cls { public: void speak(){ cout<<”Ja Fe Ma Ap My Ju Jl Au Se Oc No De∖n”; } }; } int main (){ days::cls w; months::cls d; {using months::cls; cls d; d.speak(); } {usingnamespace days; cls w; w.speak(); } w.speak(); d.speak(); return 0; }
#include<iostream> usingnamespace std; int main () { char name[11] = {’0’, ’1’ }; cout << name << endl; return 0; }
Provide the missing code so that the program
will produce the following output. The
code is not allowed to contain output
instructions.
01.......9
Consider the following incomplete program.
int main() { A ∗a, ∗b; a = new A [3] ( ”obj x” ); b = new A [3] ( ”obj y” ); a>copy(b,3); delete [] a; delete [] b; return 0; }
Provide the missing code so that the
program will produce the following
output.
new obj: obj x
new obj: obj x
new obj: obj x
new obj: obj y
new obj: obj y
new obj: obj y
dead obj: obj y
dead obj: obj y
dead obj: obj y
dead obj: obj y
dead obj: obj y
dead obj: obj y