当前位置:首页 > 四川大学C++面向对象程序设计模拟试题3
C++面向对象程序设计模拟试题三参考答安全
一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。 1.C) 6.A)
2.D) 7.C)
3.A) 8.C)
4.B) 9.C)
5.D) 10.A)
二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。错填或不填均无分。 1.参考答案:virtual int fun() = 0; 2.参考答案:static 3.参考答案:CTest 4.参考答案:构造函数 5.参考答案:private或私有
三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。 1.参考答案: A() A() ~A() end ~A()
2.参考答案: 8 2 3 4 5 3.参考答案: A B A B
4.参考答案: 15 1 2 1.1 2.2
5.参考答案: 1 8 6 13
6.参考答案: 2
8 0 end
四、完成程序填题(本大题共4个小题,每小题3分,共12分)下面程序都留有空白,请将程序补充完整。
1.参考答案:[1] static
2.参考答案:[2] a + i.a或this->a + i.a 3.参考答案:[3] char * 4.参考答案:[4] virtual
五、编程题(本大题共2小题,第1小题12分,第2小题16分,共28分) 1.参考程序:
#include
template
T Average(T a[], int n) { T s = 0; for (int i = 0; i < n; i++) s = s + a[i]; return s / n; }
int main() { double a[] = {11.8, 2, 3, 4, 5.5, 6.8, 7, 8, 9}; cout << Average(a, 9) << endl; return 0; }
2.参考程序:
#include
class Person {
protected: char name[18]; int age; char sex[3];
public: Person(char nm[], int ag, char sx[]) { strcpy(name, nm); age = ag; strcpy(sex, sx); } void Show() const { cout << \姓名:\ cout << \年龄:\ cout << \性别:\ } };
class Teacher: virtual public Person {
protected: char title[18]; public: Teacher(char nm[], int ag, char sx[], char tl[]): Person(nm, ag, sx) { strcpy(title, tl); } void Show() const { Person::Show(); cout << \职称:\ cout << endl; } };
class Cadre: virtual public Person {
protected: char post[18]; public: Cadre(char nm[], int ag, char sx[], char pt[]): Person(nm, ag, sx) { strcpy(post, pt); } void Show() const { Person::Show(); cout << \职务:\ cout << endl; } };
class TeacherCadre: public Teacher, public Cadre {
protected: double wages; public: TeacherCadre(char nm[], int ag, char sx[], char tl[], char pt[], double wg) : Person(nm, ag, sx), Teacher(nm, ag, sx, tl), Cadre(nm, ag, sx, pt) { wages = wg; } void Show() const { Person::Show(); cout << \职称:\ cout << \职务:\ cout << \工资:\元\ cout << endl; } };
int main() { Teacher objTeacher(\文冠杰\男\教授\ Cadre objCadre(\周杰\男\院长\ TeacherCadre objTeacherCadre(\李靖\女\教授\院长\ objTeacher.Show(); objCadre.Show(); objTeacherCadre.Show(); return 0; }
共分享92篇相关文档