加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

2016-2017面向对象程序设计试卷(A)

(2018-06-25 09:53:41)

一、单项选择题(每题2分,总计20分)

1.

若定义语句为const char *ptr; , ptr应该是______

A. 指向字符变量的指针     B. 指向字符的常量指针

C. 指向字符串常量的指针   D. 指向字符串的常量指针

2.

对定义重载函数的下列要求中,_____是错误的。

A. 要求参数的个数不同

B. 要求参数中至少有一个类型不同

C. 要求参数个数相同时,参数类型不同

D. 要求函数的返回值不同

3.

有以下类的说明,请指出ABCD四个语句错误的是_____

class CSample

  int a=2.5;            //A

CSample( );          //B

public:

CSample(int val);     //C

~CSample( );         //D

};

4.

一个类的友元函数能够访问该类的_____

A. 私有成员

B. 保护成员

C. 公有成员

D. 所有成员

5.

下列运算符中,_____运算符在C++中不能重载。

A. ?:      B. +      C. –      D. <=   

6.

以下对模板的说明,正确的是_____

A. template                     B. template      

C. template          D. template

7.

关于多继承二义性的描述中,_____是错误的。

A. 一个派生类的两个基类中都有某个同名成员,在派生类中对这个成员的访问可能出现二义性

B. 解决二义性的最常用的方法是对成员名的限定

C. 基类和派生类中出现同名函数,也存在二义性问题

D. 一个派生类是从两个基类派生来的,而这两个基类又有一个共同的基类,对该基类成员进行访问时,也可能出现二义性

8.

以下基类中的成员函数,哪个表示纯虚函数_____

A. virtual void vf(int);       B. void vf(int)=0;

C. virtual void vf()=0;       D. virtual void vf(int){ }

9.

C++中,打开一个文件就是将这个文件与一个_____建立关联;关闭一个文件就取消这种关联。

A.       B.       C. 对象     D. 结构

10

现有语句int iarray[] = { 0, 1, 2, 3, 4, 5, 6, 6, 6, 7, 8 };

vector ivector(iarray, iarray + sizeof(iarray) / sizeof(int));

请问要找出ivector之中小于7的元素个数,采用下面哪个算法_____

A. find_if        B. count         C. sort      D. count_if

二、程序填空题(每空2分,总计20分)

1.

请在下面程序的横线处填上适当内容,以使程序完整,并使运行结果为:2/10/2004

#include

static int dys[]={31,28,31,30,31,30,31,31,30,31,30,31};

class date

     int mo,da,yr;

public:

       date(int m,int d,int y)  {mo=m;da=d;yr=y;}

       date()     {}

       void disp()     {cout<<mo<<"/"<<da<<"/"<<yr<<endl;}

       friend date operator+(_____(1)_____)

           date dt;

              dt.mo=d.mo;

              dt.yr=d.yr;

              day+=d.da;          

              while(_____(2)_____)

                  if(dt.yr%4==0&&dt.yr0!=0||dt.yr@0==0)

                         dys[1]=29;

            else dys[1]=28;

                     day-=dys[dt.mo-1];

                     if(++dt.mo==13)

                         dt.mo=1;

                            dt.yr++;

                     }

              }

              dt.da=day;

              return dt;

       }

};

int main()

     date d1(2,10,2003),d2;

       d2=d1+365;

       d2.disp();

}

2.

请在下面程序的横线处填上适当内容,以使程序完整,并使程序的输出为 n=30

#include

template

class Sample

     T n;

public:

           Sample(){}

           Sample(T i){n=i;}

           Sample  operator+(const Sample &);

           void disp(){cout<<"n="<<n<<endl;}

};

template

Sample  Sample::operator+(const Sample &s)

     Sample temp;

           _______(3)_______;

       return temp;

}

int main()

     Sample s1(10),s2(20),s3;

           s3=s1+s2;

           _______(4)_______;

}

 

3.

请在下面程序的横线处填上适当字句,以使程序完整,并使程序的输出为

A Constructor2

B Constructor2

x1=12

x2=2

 

#include

class A

{

public:

       A(){cout<<"A Constructor1"<<endl;}

       A(int i){x1=i;cout<<"A Constructor2"<<endl;};

       void dispa(){cout<<"x1="<<x1<<endl;}

private:

       int x1;

};

class B:public A

{

public:

       B(){cout<<"B Constructor1"<<endl;}

       B(int i): _____(5)_____{x2=i;cout<<"B Constructor2"<<endl;}

       void dispb()

           _____(6)_____;

              cout<<"x2="<<x2<<endl;

       }

private:

       int x2;

};

int main()

     B b(2);

       b.dispb();

}

 

4.

请在下面程序的横线处填上适当字句,以使程序完整,并使程序的输出为

构造base对象

调用base::f()

构造derive对象

调用derive::f()

 

#include

class base

{

public:

       base()

           cout<<"构造base对象"<<endl;

              f();                             

       }

       _________(7)_________{cout<<"调用base::f()"<<endl;}

};

class derive:public base

{

public:

       derive()

           cout<<"构造derive对象"<<endl;

              _________(8)_________;                  

       }

       void f(){cout<<"调用derive::f()"<<endl;}

};

int main()

{

       derive d;

}

 

5.

下面程序用STL的条件计数算法和自定义的函数对象对一个存放在整数向量类对象中的学生成绩进行统计及格人数并显示结果。请在下面程序的横线处填上适当字句,以使程序完整。

#include

#include

#include

#include

using namespace std;

 

class Pass

{

public:

____________________(9)___________________

{

       return x>=60;

}

};

 

int main()

{

vector a;

int count;

a.push_back(78);

a.push_back(92);

a.push_back(52);

count = ____________________(10)___________________;

cout<<"count="<<count<<endl;

}

 

三、程序阅读题(每题6分,总计30分)

1.

#include

class CSample

{

private:

       int n;

       static int k;

public:

       CSample(int i){n=i;k++;}

       void disp();

};

void CSample::disp()

     cout<<"n="<<n<<",k="<<k<<endl;}

int CSample::k=0;

int main()

     CSample a(10),b(20),c(30);

       a.disp();

       b.disp();

       c.disp();

}

 

2.

#include

class Sample

   int n;

public:

      Sample(){}

      Sample(int m){n=m;}

      Sample operator--(int)

          Sample old=*this;

          n--;

             return old;

      }

      void disp(){cout<<"n="<<n<<endl;}

};

int  main()

   Sample s(10);

      s--;

      s.disp();

}

 

3.

#include

#include

template

T max(T x, T y)                               

{

       return (x > y ? x : y);

}

char *max(char *x, char *y)            

{

       if (strcmp(x, y) >= 0)

              return x;

       else

              return y;

}

int main()

{

       cout << max(2, 5) << endl;

       cout << max(3.14,4.12) << endl;

       cout << max("China", "Beijing") << endl;

}

 

4.

#include

#include

#include

using namespace std;

int main() {

      stack s;

      string str;

      cin >> str;     //从键盘输入字符串LoveChina

      for (string::iterator iter = str.begin(); iter != str.end(); ++iter)

             s.push(*iter);

      while (!s.empty()) {

             cout << s.top();

             s.pop();

      }

      cout << endl;

}

 

5.

#include

using namespace std;

int divide(int x, int y) {

       if (y == 0)

              throw x;

       return x / y;

}

int main() {

       try {

              cout << "8/3 = " << divide(8, 3) << endl;

              cout << "6/0 = " << divide(6, 0) << endl;

              cout << "9/2 = " << divide(9, 2) << endl;

       } catch (int e) {

              cout << e << " is divided by zero!" << endl;

       }

       cout << "That is ok." << endl;  

}

 

四、编程题(每题15分,总计30分)

1. 编程实现小型公司的工资管理。该公司主要有4类人员:经理(manager)、兼职技术人员(technician)、销售员(salesman)和销售经理(salesmanager)。要求存储这些人员的编号、姓名和月工资,计算月工资并显示全部信息。月工资计算办法是:经理拿固定月薪8000元,兼职技术人员按每小时100元领取月薪,销售员按当月销售额的4%提成,销售经理既拿固定月工资也领取销售提成,固定月工资为5000元,销售提成为所管辖部门当月销售总额的千分之五。兼职技术人员一个月工作小时数、销售员一个月销售额、销售经理所管辖部门一个月销售总额由各个类的成员函数完成设置。(要求用抽象类和类继承)

2. 定义一个矩阵类(Matrix),设计相关的构造函数、析构函数等,采用运算符重载方式实现矩阵的加、减、乘运算。编写main函数,对以上所有功能进行测试。注意:按照实际情况大小使用内存空间,矩阵的加、减、乘运算不要造成内存浪费。

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有