{
public:
B(){cout<<\ ~B(){cout<<\ }; void main() {
B b; }
结果:1342
8.#include
int n=10; int* pn=&n; int* &rn=pn; (*pn)++;
cout<<\ (*rn)++;
cout<<”n=”<
{ int n=0,j=0,s=0;
for (int i=8;i<=20;i++) { n++;i++; if (i%4==0) j++; else s++;
} cout<<\}
10. #include
void fun(int i); void main( ) { int n;
for (n=1;n<5;n++) fun(n); }
void fun(int i ) { static s=0; s+=i;
cout<
}
11. #include
void main()
{ int i,a[]={1,2,3,4,5,6,7,8},*p=a; for (i=1;i<5;i++)
p[i]=a[i-1]+a[i+1]; cout<
}
12. class mystr
{ char string[81];int len; public:
mystr(char *s){strcpy(string,s);}
void getvalue(char *s,int &n)
{strcpy(s,string); n=len; }
friend mystr operator+(mystr a,mystr b) {mystr c(\
strcpy(c.string,a.string); strcat(c.string,b.string); c.len=strlen(c.string); return c;} };
void main()
{ char st[81]; int l;
mystr a(\ c=a+b;
c.getvalue(st,l);
cout << st< 13. #include #include Point(){x=1;y=1;count++;} ~Point(){count--;} friend void display(); }; void display() {cout <<\void main() { Point a; display(); { Point b[5]; display(); } display(); } 14.#include class base { public: virtual void show() {cout<<\}; class derived:public base {public: void show() {cout<<\}; void display(base *obj) {obj->show();} void main() { base demo1; derived demo2; display(&demo1); display(&demo2); } 9-14运行结果: 9.n=7 i=22 s=7 10.1 3 6 10 11.13 12.Hello everybody! Len=16 13.There are 1points, There are 6points, There are 1points, 14.class base show() is called. class derived show() is called. 15.阅读以下程序,写出输出结果。 #include using namespace std; int main() { int a = 0, b = 1; switch( a ) { case 0: switch( b ) { case 0 : cout<<\ case 1 : cout<<\ } case 1: a++; b++; cout<<\ } } 【解答】 a=0 b=1 a=1 b=2 16.阅读以下程序,写出输出结果。 #include else cout << i << endl; } 【解答】 4 7 10 17.阅读以下程序,写出输出结果。 #include T( int x, int y ) { a = x ; b = y ; cout << \调用构造函数.\ cout << a << '\\t' << b << endl ; } T( T &d ) { cout << \调用构造函数.\ cout << d.a << '\\t' << d.b << endl ; } ~T() { cout << \调用析构函数.\ int add( int x, int y = 10 ) { return x + y ; } private : int a, b ; }; int main() { T d1( 4, 8 ) ; T d2( d1 ) ; cout << d2.add( 10 ) << endl ; } 【解答】 调用构造函数1. 4 8 调用构造函数2. 4 8 20 调用析构函数. 调用析构函数. 18.阅读以下程序,写出输出结果。 #include int *p = &a, *q = &b; *p = *p * *q; int & ra = a; ra=a; int * & rt = q; *rt = 30;