未分类题

阅读下列说明和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 }
请补齐下述代码中的空缺1和2。

A.output();
B.output();
C.output();

【参考答案】

(1)Stock():shares(1)share_val(1) 或Stock():share_val(1)shares......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题