首页
外语
计算机
考研
公务员
职业资格
财经
工程
司法
医学
专升本
自考
实用职业技能
登录
计算机
有如下程序: #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
16
问题
有如下程序: #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://kaotiyun.com/show/NeVp777K
本试题收录于:
二级C题库NCRE全国计算机二级分类
0
二级C
NCRE全国计算机二级
相关试题推荐
下列叙述中错误的是()。
请编写函数fun,其功能是:计算并输出给定数组(长度为9)中每相邻两个元素的平均值的平方根之和。例如,若给定数组中的9个元素依次为12.0、34.0、4.0、23.0、34.0、45.0、18.0、3.0、11.0,则输出应为s=35.951014。注
有以下程序:#include<stdio.h>##definef(x)X*X*xmain(){inta=3,s,t;s=ffa+1):t=f((a+1));printf("%d,%d\n",s,t);}程序运行后的输出结果是(
在软件开发中,需求分析阶段产生的主要文档是()。
下列关于线性链表的叙述中,正确的是()。
下列定义数组的语句中,正确的是()。
以下能正确定义字符串的语句是()。
以下不属于结构化程序设计原则的是()。
关于new运算符的下列描述中,错误的是()。
软件工程包括三个要素,分别为方法、工具和【】。
随机试题
郭小川诗歌《望星空》前半部分中,“我”望星空时的心情是()
心源性水肿常先出现于
女性,25岁,右足癣并感染1周,2d前开始出现右小腿有片状红疹,颜色鲜红,中间较淡,边缘清楚,右腹股沟淋巴结肿大。为预防复发,在全身和局部症状消失后仍继续使用抗生素()
作为施工项目负责人的注册建造师不得同时担任两个及以上建设工程施工的项目经理,但下列选项中的()情况例外。
关于企业使命的描述中,不正确的有()。
【2012年下】依据《中华人民共和国预防未成年人犯罪法》,下列选项中,学校应当及时与其父母或法定监护人取得联系的学生行为是()。
某带链的队列初始状态为front=rear=NULL。经过一系列正常的入队与退队操作后,front=10,rear=5。该队列中的元素个数为()。
Qusetions5-10AnswerthefollowingquestionsusingNOMORETHANTHRESSWORDSAND/ORANUMBERforeachanswerNUMBERforeach
SavingfortheFuture-Purposeofsaving1.Womensavea.fortheirchildren’s【T1】______【T1】______b.fora【T2】____
Fromthefirstparagraph,weknow______.Bysaying"toomanycorporations...speedandaccessibility"(Lines3-4,Para.3),th
最新回复
(
0
)