C++程序设计试题和答案1
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。
void Simple::copy(Simple&s) {
x=s.x;y=s.y; }
void func(Simple s1.Simple&s2) {
s1.setxy(30,40); s2.setxy(70.80); }
void main() {
Simple obj1(1.2).obj2; obj2.copy(obj1); func(obj1.obj2); obj1.print(); obj2.print(); } x=1,y=2 x=70,y=80
53.给出下面程序的输出结果 #include\
. .
int main() {
int i=17; while(i>=10)
if(--i%4==3)continue; else
cout<<\; }
i=16 i=14 i=12 i=10 54.给出下面程序的输出结果 #include using namespace std; void main() {
int num=300; int &ref=num; cout< cout<<\;
. .
}
300 200 150
六、程序设计题(本大题共1小题.共10分)
55.定义堆栈类模板Stack(先进后出).栈的大小由使用者确定。要求该类模板对外提供 如下二种基本操作:
(1)push入栈(2)pop出栈.用数组来实现 #include using namespace std; template class Stack{ T x[size]; int current; public:
Stack(){current=0;} ....push(....); ....pop(....); };
请写出两个函数的过程(如果需要形式参数.请给出形参类型和数量.以及返回值类型) void Satck::push(T t){ if (current= =size) {
cout<<“The Stack is full!”<. .
else {x[current]=t;current++;} //新元素入栈并修改栈顶指针 }
T Stack::pop( ){ if (current= =0){
cout<<”There is no object in the Stack!”<. .
C++程序设计试题和答案1.doc
将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印