-> -> ->
2010计算机等级考试二级(C++)笔试125(二)
时间:2011-01-15 09:59:54
微信搜索关注"91考试网"公众号,领30元,获取事业编教师公务员等考试资料40G
内容。----------------------------------------33、关于关键字class 和typename,下列表述正确的是______ 。 A.程序中所有的tyeame都可以替换为claB.程序中所有的cla都可以替换为tyeameC.A)和B)都正确D.A)和B)都不正确 参考答案: A typename的相关内容。----------------------------------------34、 有如下程序: #include <iostream> #include <iomanip> using namespace std; class CSum {int x,y; public: CSum(int x0,int y0):x(x0),y(y0) {} friend ostream& operator<<(ostream & os, const CSum& xa) { os<<setw(5)<<xa.x+xa.y; return os; } int main() { CSum y(3,5); cout<<setfill(''''*'''')<<8; cout<<y; return 0; } 执行上面程序的输出是______。 A.88B.****88C.****8****8D.8****8 参考答案: D setw 设置输出宽度。----------------------------------------35、 有如下程序: #include <iostream> using namespace std; class Stack { public: Stack(unsigned n= 10):size(n) {rep_=ew int[size]; top=0;} Stack(Stack& s):size(s.size) { rep_=new int[size]; for(int i=0;i<size;i++) rep_[i]=s.rep_[i]; top=s.top; } ~Stack() {delete []rep_;} void push(int a) {rep_[top]=a; top++;} int pop() {--top;return rep_[top];} bool isEmpty() const {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); si.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 栈是“先进后出”的数据结构。
微信搜索关注"91考试网"公众号,领30元,获取公务员事业编教师考试资料40G