川大c++期末复习题

更新时间:2023-12-20 13:12:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

C++面向对象程序设计模拟试题一

一、单项选择题(本大题共10小题,每小题2分,共20分)在每小题列出的四个备选项中,只有一个是符合题目要求的,请将其代码填写在题后的括号内。错选、多选或未选均无分。

1.说明虚函数的关键字是( )。

A)inline B)virtual C)define D)static

2.在标准C++中,每个程序中都必须包含有这样一个函数,该函数的函数名为( )。

A)main B)MAIN C)name D)function 3.cout是某个类的标准对象的引用,该类是( )。 A)ostream B)istream C)stdout D)stdin

4.如果在类外的非类的成员函数中有函数调用CPoint::func();则函数func()是类CPoint的( )。 A)私有静态成员函数 B)公有非静态成员函数 C)公有静态成员函数 B)友元函数

5. 如果class类中的所有成员在定义时都没有使用关键字public、private或protected,则所有成员缺省定义为( )。

A)public B)protected C)private D)static 6.一个类的所有对象共享的是( )。 A)私有数据成员 B)公有数据成员 C)保护数据成员 D)静态数据成员 7.动态联编所支持的多态性称为( )。 A)虚函数 B)继承 C)编译时多态性 D)运行时多态性 8.定义类模板时要使用关键字( )。 A)const B)new C)delete D)template 9.对虚基类的定义( )。 A)不需要使用虚函数 B)必须使用虚函数 C)必须使用private D)必须使用public 10.类类型转换函数( )。 A)不能带有参数 B)只能带一个参数 C)只能带2个参数 D)只能带3个参数 二、填空题(本大题共5小题,每小题2分,共10分)不写解答过程,将正确的答案写在每小题的空格内。错填或不填均无分。

1.在用C++进行程序设计时,最好用( )代替malloc。

2.函数模板中紧随template之后尖括号内的类型参数都要寇以保留字( )。 3.编译时多态性可以用( )函数实现。

4.拷贝构造函数用它所在类的( )作为参数。 5.用关键字static修饰的类的成员称为( )成员。

三、程序分析题(本大题共6小题,每小题5分,共30分)给出下面各程序的输出结果。 1.阅读下面程序,写出输出结果。 #include using namespace std;

class Array {

public: Array(int a[], int iSize):elem(a), size(iSize) { } int GetSize() { return size; } int &operator[](int i) { return elem[i - 1]; }

private: int *elem; int size; };

int main() { int s[]={3, 7, 2, 1, 5}; Array ar(s, 5); ar[1] = 9; for (int i = 1; i <= 5; i++) { cout << ar[i] << \ \ } cout << endl; return 0; }

上面程序的输出结果为:

2.阅读下面程序,写出输出结果。

#include using namespace std;

template void Print(Type a[], int n) { for (int i = 0; i < n; i++) { cout << a[i] << \ \ } }

int main() { int a[] = { 5, 6, 8}; double b[] = {6.8, 9.6}; Print(a, sizeof(a) / sizeof(int)); Print(b, 2); cout << endl; return 0; }

上面程序的输出结果为:

3.阅读下面程序,写出输出结果。 #include using namespace std;

class Test {

public: Test(int n):num(n) { count++; } ~Test() { } void Print() const;

static int GetCount() { return count; }

private: int num; static int count; };

int Test::count = 0;

void Test::Print() const { cout << this->num << \ \ \}

int main() { Test oTest1(6); oTest1.Print(); Test oTest2(8); oTest2.Print(); cout << Test::GetCount(); cout << endl; return 0; }

上面程序的输出结果为:

4.阅读下面程序,写出输出结果。 #include using namespace std;

class Test {

public: Test(int a = 0, int b = 0, int c = 0):x(a), y(b), z(c) {} void Print() {

cout << x << endl; cout << y << endl; } void Print() const { cout << z << endl; }

private: int x, y; const int z; };

int main() { Test obj1; obj1.Print(); Test obj2(1, 6, 8); obj2.Print(); const Test obj3(6, 0, 18); obj3.Print(); cout << endl; return 0; }

上面程序的输出结果为:

5.阅读下面程序,写出输出结果。 #include using namespace std;

class MyClass {

private: static int n;

public: MyClass() { n += 1; }

本文来源:https://www.bwwdw.com/article/wpw5.html

Top