问答题
综合应用题 使用VC6打开考生文件夹下的工程kt11_3。此工程包含一个kt11_3.cpp,其中定义了类queue,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。 (1)完成类queue的无参数的构造函数的定义,要求把数据成员bl和el都初始化为0,同时输出queueinitialized。请在注释“//**1**”之后添加适当的语句。 (2)完成类queue的成员函数qput(intj)的定义,它的功能是把新的元素加入队列,过程是先依据bl的值判断数组是否已经满了,如果是就输出queueisfull,否则bl自加一,并且把参数j的值存入bl指向的数组元素中,请在注释“//**2**”之后添加适当的语句。 (3)完成类queue的成员函数qget()的定义,它的功能是把队列开头的元素提取出队列,并返回该值,过程是先比较el和bl的值判断队列是否已空,如果是就输出queueisempty, 否则el自加一,并且把el指向的数组元素返回,请在注释“//**3**”之后添加适当的语句。 程序输出结果如下: queueinitialized queueinitialized 3311 4422 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 源程序文件kt11_3.cpp清单如下: #include
classqueue { intq[100]; intbl,el; public: queue(); voidqput(intj); intqget(); }; queue::queue() { //**1** } voidqueue::qput(intj) { //**2** { cout<<"queueisfull\n"; return; } bl++; q[bl]=j; } intqueue::qget() { //**3** { cout<<"queueisempty\n"; return0; } el++; returnq[el]; } voidmain() { queueaa,bb; aa.qput(11); bb.qput(22); aa.qput(33); bb.qput(44); cout<
【参考答案】
(1)bl=el=0; cout<<"queue initialized\n"; (2)if(bl==100) (3)i......
(↓↓↓ 点击下方‘点击查看答案’看完整答案、解析 ↓↓↓)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
改错题 使用VC6打开考生文件夹下的工程kt11_1,此工程包含一个源程序文件kt11_1.cpp,但该程序运行有问题,请改正函数中的错误,使该程序的输出结果为: Valuesare:1,2and3 Pressanykeytocontinue 源程序文件kt11_1.cpp清单如下: #include classCommonBase { public: intx; }; *****************found***************** classDeriveCommonA::publicCommonBase { public: inty; }; classDeriveCommonB:publicCommonBase { public: intz; }; *****************found***************** classOverlapping:publicDeriveCommonA;publicDeriveCommonB { public: voidDisplay() { cout<< Valuesare: <<DeriveCommonA::x<< , <<y<< and <<z<<endl; } }; intmain() { Overlappingov; *****************found***************** ov.x=1; ov.y=2; ov.z=3; ov.Display(); return0; }
点击查看答案&解析
相关试题
简单应用题 请编写函数fun(),该函数的...