资源描述
程序设计与C++语言C试卷参考答案
一、简答题(每题1分,共3分)
1.答:定义类时成员数据不分配内存,不可加存储类型说明。
2.答:析构函数是无参函数。
3.答:函数swap的参数应该用引用,传值调用数据交换是在副本上做的。
二、程序阅读与修改题(第1题3分,第2~4题5分,共18分)
5.0/2.0=2.5
被0除异常
说明:每行1.5分,如果多出一行“9.0/2.0=4.5”扣1分
1.
我的名字是:#
我的学号是:06007126 我的名字是:沈洁
我的专业是:计算机 我的名字是:陈棣
删去virtual后程序输出:
我的名字是:#
我的名字是:沈洁
我的名字是:陈棣
说明:第1和4行各0.5分,每行1分。
2.
The watermelon weight is:12.5
Total weight is:12.5
Total number is:1
The watermelon weight is:10.7
Total weight is:23.2
Total number is:2
Total weight is:10.7
Total number is:1
说明:每次售瓜2分退瓜1分
3.
输出:
1 3 5 11 13 17 19 23 29 (1分)
1 3 5 7 11 11 11 11 11 11 (1分)
原因:(1分)
未能从表最后位置向前依次后移
正确代码:(2分)
for(j=last;j>i;j--) slist[j]=slist[j-1];
4.
四、程序填空(共39分,每空1.5分):
1.(1) friend int operator = =(Complex &,Complex &)
(2) operator double ( )
(3) Complex operator ++(int)
(4) Complex Complex::operator +(Complex &c)
(5) c1.re= =c2.re&&c1.im==c2.im
(6) ostream & operator <<(ostream &out,Complex &c)
(7) return out
(8) in>>c.re>>c.im
(9) *this
2.(10) MakeEmpty()
(11) tempP->link
(12)tempP->info!=data //12、13可以互换
(13)tempP!=NULL
(14) tail->link=p
(15)new Node<T>
(16) tempP->link=NULL
(17) tempP->link!=p
(18) tempP
(19) list1.CreatNode(m)
(20) list1.Find ( j )
3.(21) new T[Maxsize]
(22)elements[i]
(23) (i+1)%(last+1)
(24) elements[i]==1
(25) elements[i]=0
(26) seq.Josephus(a,m)
展开阅读全文