C++卷1

2020-04-15 13:36

浙江省高校计算机专业课程统考

《C++程序设计》

考 试 试 卷(2小时)

题类 得分 一 二 三 四 五 总分 学校: 学号: 姓名:

一、 单项选择题(30分,共15题,每小题2分)

1若A是类名,则下列定义中,定义指向对象数组的指针p的是____。

A) A *p[3]; B) A (*p)[3]; C) (A *)p[3]; D) A *p();

2. 一段程序的定义如下,在函数f()中将动态对象的成员n的值改为20的语句应该为____。 class A { int n;

public: set(int nl) {n=nl;}

A(int x) : n (x) {} } int f() {A * ptr = new A(10);... }

A) A(20); B) ptr.set(20); C) ptr->set(20); D) set(20); 3. 语句 int (*p)( ); 的含义是____。

A) p 是一个指向函数的指针变量,该函数的返回值是一个整型数据 B) p 是指针变量,指向一个整型数据 C) p 是一个指向一维数据的指针变量 D) p 是函数, 该函数返回整形指针

4.设int a=2,b=3,c=4;表达式(a+b)>c&&b==c的值是____。

A) 2 B) -1 C) 0 D) 1 5. 通常,拷贝构造函数的参数是____。

A)某个对象名 B)某个对象的成员名 C)某个对象的引用名 D)某个对象的指针名

6. 在下列关键字中, 用以说明类中公有成员的是 ____。

A) public B) private C) protected D) friend 7. 不正确的标识符是____ 。

A) _a2 B) 2ai C) a2_i D) INt

8. 在C++的类中重载二元运算符为成员运算符时,只能指定____。

A) 一个参数 B) 两个参数 C) 二个参数 D) 不能指定参数 9. 若 p1 、 p2 都是指向类类型的指针, p1 已经指向对象 x ,要使 p2 也指向 x ,正确的是____ 。

A) p2=p1 ; B) p2=**p1 ; C) p2=&p1 ; D) p2=*p1 ; 10. 假定A为一个类,则该类的拷贝构造函数的声明语句为____。

A) A& (A x); B) A(A x) C) A(const A &); D) A(A* x) 11. 下列的 ____是引用调用。

A) 形参是指针,实参是地址值 B) 形参和实参都是变量 C) 形参是数组名,实参是数组名 D) 形参是引用,实参是变量 12. 通过 ____调用虚函数时,采用动态绑定(binding)。

A) 对象指针 B) 对象名 C) 成员名限定 D) 派生类名 13. 下述静态数据成员的特性描述中, ____ 是错误的。

A) 说明静态数据成员时要加修饰符static B) 静态数据成员要在类体外进行初始化

C) 引用静态数据成员时, 可在静态数据成员名前加<类名>和作用域运算符 D) 静态数据成员不是所有对象所共用

14. 下列带缺省值参数的函数声明中,正确的声明是____。

A)int Fun(int x,int y=2,int z=3); B)int Fun(int x=1,int y,int z=3);

第 1 页

浙江省高校计算机专业课程统考

C)int Fun(int x,int y=2,int z); D)int Fun(int x=1,int y,int z); 15. 关键字 ____ 可以用来说明常量。

A) malloc B) new C) const D) class

二、是非判断题(10分,共2题,每小题2分)(请在题号上打√或X)

□ 1. C/C++ 程序中的变量,必须先定义 ( 声明 ) ,才能使用。

□ 2. 对象数组的元素可以是不同类的对象。

□ 3. 任何数据成员只有借助于类的实例才能访问。 □ 4. 在一个类中可以重载多个析构函数。 □ 5. 类的成员也可以是其他类的对象。

三、读程序,写运行结果(30分)

1. (7分)

#include using namespace std; template

T f(T*a,T*b,int n){ T s=(T)0;

for(int i=0;i

void main() {

double c [4]={1.1,2.2,3.3,4.4},d[4]={10, 0,100, 0}; cout<

#include using namespace std; const double PI = 3.14;

class CShape { public :

virtual int GetArea () = 0;

virtual int GetPerimeter () = 0; virtual void Draw () = 0; };

class CRectangle : CShape { public : CRectangle () : m_width (10), m_length (20) {} CRectangle (int width, int length) : m_width (width), m_length (length) {} int GetArea () { return m_width * m_length; } int GetPerimeter () { return 2 * (m_width + m_length); } void Draw (); private : int m_width, m_length; };

第 2 页

浙江省高校计算机专业课程统考

void CRectangle::Draw () { cout << \}

class CCircle : CShape { public : CCircle () : m_radius (10) {} CCircle (int radius) : m_radius (radius) {} int GetArea () { return (int)(PI * m_radius * m_radius + 0.5); } int GetPerimeter () { return (int)(2 * PI * m_radius + 0.5); } void Draw ();

private : int m_radius; };

void CCircle::Draw () { cout << \}

void main () {

CShape *pShape [2];

pShape [0] = (CShape *) new CRectangle; pShape [1] = (CShape *) new CCircle;

pShape [0]->Draw ();

cout << \ << \ << endl;

pShape [1]->Draw ();

cout << \ << \ << endl;

delete pShape [0]; delete pShape [1]; } 3.(8分)

#include #include #include using namespace std; void main ()

{ vector > datas; ifstream ifs (\ int m, n; ifs >> m >> n; int i, j;

第 3 页

浙江省高校计算机专业课程统考

for (i = 0; i < m; i ++) { vector V; for (j = 0; j < n; j ++ ) { int x; ifs >> x; V.push_back (x); } datas.push_back (V); }

for (i = 0; i < m; i ++) { for (j = 0 ;j < n; j ++) { cout.width (4); cout << datas [i][j]; } cout << endl; }

}

文件Test.dat内容如下 :

4 3 1 2 3 4 5 6 7 8 9 10 11 12

4. (8分)

#include using namespace std; class FunArray{ int *pa; int size; public:

FunArray(int a[ ],int thesize):pa(a),size(thesize){ } int Size( ){return size;} int& operator[ ](int index){ if (index >= size) throw index; return pa[index]; } };

int main( ) {

int s[ ]={3,7,2,1,5,4}; try { FunArray ma(s, sizeof(s)/sizeof(int)); ma[3]=9; for(int i=0; ; i++) cout<

四、填空题(10分,共5空,每小空2分)

1. 完成求最大值函数模板的定义。 #include using namespace std; template T Max(T x, T y) {

return ( x>y ? x : y ); }

第 4 页

浙江省高校计算机专业课程统考

①________

T Max(T x, T y, T z) {

T t = Max(x,y);

return ( ②________________ ); }

void main() {

int x; double y;

x = Max(1,2); y = Max(2.3, 3.4, 7.8); cout << \}

2.完成如下的程序,使得输出为: base::1 base::2 derived::3

#include using namespace std; class base { int x; public:

base(int a) :x(a){ } _________①__________ };

class derived:public base { int y; public:

derived(int a,int b): _________②________ { y=b; } _________③_________; };

void main() { base b(1),*p;

derived d(2,3); b.print(); p=&d;

p->print(); }

五、设计题(20分,共4题,每题10分,选2题做)

1 下面是测试时钟类CClock的一个程序和输出结果, 请设计并实现符合本例要求的CClock类。 #include using namespace std;

...// CClock类的声明和实现 int main() {

CClock t1, t2 (12, 0,1); t1.Set (11,59,59); cout << t1 << endl; cout << t2 << endl; CClock t3; t3 = ++ t1;

cout << t3 << endl; t3 = t1++;

cout << t3 << endl; if (t1.Equal (t2)) cout << “Equal” << endl;

第 5 页


C++卷1.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:成都西充商会目录

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: