(1)请写出下列程序的输出内容
代码如下:
1 #include <iostream> 2 using namespace std; 3 4 class A 5 { 6 public: 7 A() 8 { 9 cout << "A::A()" << endl; 10 } 11 virtual ~A() 12 { 13 cout << "A::~A()" << endl; 14 } 15 void fun1() const 16 { 17 cout << "A::fun1()" << endl; 18 } 19 virtual void fun2() const 20 { 21 cout << "A::fun2()" << endl; 22 } 23 }; 24 25 class B : public A 26 { 27 public: 28 B() 29 { 30 cout << "B::B()" << endl; 31 } 32 ~B() 33 { 34 cout << "B::~B()" << endl; 35 } 36 void fun1() const 37 { 38 cout << "B::fun1()" << endl; 39 } 40 void fun2() const 41 { 42 cout << "B::fun2()" << endl; 43 } 44 }; 45 46 void Test1(const A * pA) 47 { 48 pA->fun1(); 49 pA->fun2(); 50 delete pA; 51 } 52 53 void Test2(const B * pB) 54 { 55 pB->fun1(); 56 pB->fun2(); 57 delete pB; 58 } 59 60 void main() 61 { 62 cout << "=====Test1====" << endl; 63 Test1(new B()); 64 cout << "====Test2====" << endl; 65 Test2(new B()); 66 system("pause"); 67 } 68 69 // run out: 70 /* 71 =====Test1==== 72 A::A() 73 B::B() 74 A::fun1() 75 B::fun2() 76 B::~B() 77 A::~A() 78 ====Test2==== 79 A::A() 80 B::B() 81 B::fun1() 82 B::fun2() 83 B::~B() 84 A::~A() 85 请按任意键继续. . . 86 */
输出内容如上注释。
(2)请写出下列程序的输出内容
代码如下:
1 #include <iostream> 2 using namespace std; 3 4 void main() 5 { 6 for (int i = 10; --i >= 0; i = i>>1) 7 { 8 cout << (i + 1) << endl; 9 } 10 11 system("pause"); 12 } 13 14 // run out: 15 /* 16 10 17 4 18 1 19 请按任意键继续. . . 20 */
输出内容如上注释
(3)请写出下列程序的输出内容
代码如下:
输出内容如上注释。
Good Good Study, Day Day Up.
顺序 选择 循环 总结
时间: 2024-12-15 03:17:40