首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #include <iostream.h> using namespace std; class Stack { public: Stack (unsigned n=10):size (n) {re
有如下程序: #include <iostream.h> using namespace std; class Stack { public: Stack (unsigned n=10):size (n) {re
admin
2013-02-27
51
问题
有如下程序: #include <iostream.h> using namespace std; class Stack { public: Stack (unsigned n=10):size (n) {rep_=new int [size]; top=0;} Stack (stack&s}: size (s.size) { rep_new int[size]; for (int i=0;i<size;i++ rip_
-s.rep_
; top=s.top; } ~Stack() {delete[]rep_;} void poush (int a) {rep_[topj=a; top++;} int pep() { --top; return rep_[top];} bool isEmpty() cons5 [return Top ==0;} private: int*rep_; unsigned size, top; }; int main() { Stack s1; for(int i=1;i<5;i++) s1.push(i); Stack s2(s1); for(i=1;i<3;i++} cout<<s2.pop()<<’,’; s2.push(6); s1.push(7); while(!s2.isEmpty()) cout<<s2.pop()<<’,’; return 0; } 执行上面程序的输出是
选项
A、4,3,2,1,
B、4,3,6,7,2,1,
C、4,3,6,2,1,
D、1,2,3,4,
答案
C
解析
本题是一个综合应用考题,考核知识点包括类与对象的应用(包括构造函数、拷贝构造函数),循环语句的使用、指针的使用。 分析程序:类Stack的构造函数中默认参数为 10,即构造大小为10的堆栈,成员函数push用于将数据压入堆栈中,pop用于将数据弹出堆栈。主函数main中,先定义了类Stack的对象引,初始大小为10,通过for循环先后将值1,2,3、4压入堆栈内,然后定义对象s2,并用对象s1来初始化,所以对象s2的堆栈大小也为10,同时也已压入数值1、 2、3、4,第二个for循环将4、3弹出并输出,然后将数值6压入s2的堆栈,最后将s2堆栈中所剩下的值全部弹出,即6、2、1。
转载请注明原文地址:https://www.kaotiyun.com/show/NeVp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
有以下程序:#include<stdio.h>intf(intn){staticinta=1;n+=a++;returnn;}main(){inta=3,s:s=f(a);s=s+f(a);printf("%d\n",
有以下程序:#include<stdio.h>main(){intcase;floatprintF;printf("请输入2个数:");scanf("%d%f",&case,&printF):printf("%d%f\n",case,p
有以下程序:#include
有以下程序:#include<stdio.h>main(){staticchara[]="Program",*ptr;for(ptr=a;ptr<a+7;ptr+=2)putchar(*ptr);}程序运行后的结果为(
有以下程序:#include<stdio.h>main(){inta[2]E3]={{1,2,3},(4,5,6));intb[3][2],i,j;for(i=0;i<=1;i++){for(j=0;j<=2;j++)b[j][i]
以下叙述中正确的是()。
对软件系统总体结构图,下面描述中错误的是()。
以下数组定义中错误的是()。
以下属于白盒测试方法的是()。
在重载运算符函数时,下面运算符必须重载为类的成员函数的是()。
随机试题
在下述电工仪表中,准确度差的是()。
Whentwohandsmeet,wepassonsomethingofourselves.After【C1】______toMarkTwain,Helen—whowasbothdeafandblind—commente
男性,14岁,8个月前开始左上臂肿胀、疼痛,入院诊断为左肱骨上端骨肉瘤,优选的治疗方案是()(2004年)
发生额试算平衡,是指某一个账户借方发生额等于贷方发生额。( )
()优先于普通股的股票称为优先股。
可供出售金融资产应当按取得该金融资产的公允价值和相关交易费用之和作为初始确认金额。支付的价款中包含的已到付息期但尚未领取的债券利息或已宣告但尚未发放的现金股利也作为初始确认金额计入成本。()
病例:患者,男,28岁,胸部外伤致右侧第5肋骨骨折并发气胸,呼吸极度困难,发绀,出冷汗。检查:血压10.6/8kPa(80/60mmHg),气管向左侧移位,右胸廓饱满,叩诊呈鼓音,呼吸音消失,颈胸部有广泛皮下气肿等。医生采用胸膜腔闭式引流治疗。关于
劳动教养行政复议的申请期限是自知道劳动教养决定之日起()内。
下列有关类继承的表述中,错误的是
Hiscompositionisquitegood______afewminorgrammaticalmistakes.
最新回复
(
0
)