问题
问答题
(以下试题六至试题八任选一题)
阅读下列说明和C++代码,请回答问题1至问题3。
【说明】已知下列程序运行时的输出应为:
1:1
1:1
1:1
【C++程序】
01 #include <iostream>
02 using namespace std;
03 class Stock{
04 protect:
05 (1) {};
06 Stock(iht n, int pr=1){
07 shares = n; share_val=pr;
08 };
09 void~Stock(){};
10 public:
11 //成员函数
12 void output(){
13 (2) << shares << ":" << share val << endl;
14 }
15 private:
16 //成员变量
17 int shares;
18 int share_val;
19 };
20
21 void main(){
22 Stock a(1); a.output();
23 Stock b; b.output();
24 Stock c = Stock(); c.output();
25 }
【问题2】 类Stock的定义中有两处错误,请指出错误所在行号并给出该行修改后的完整结果。 |
答案
参考答案:
错误1 第4行,修改为:public:
错误2 第9行,修改为:~Stock(){}