杭州电子科技大学C++面向对象程序设计-期末考试试题(A)卷 联系客服

发布时间 : 星期五 文章杭州电子科技大学C++面向对象程序设计-期末考试试题(A)卷更新完毕开始阅读7dd3322a541252d380eb6294dd88d0d233d43c2a

一、 a. 允许存在 b. 为一错误 c. 判断题(15分)(对的打√,错的打╳)从 int 到 float d. 从 float 到 int 1. 友元函数用于允许一个函数访问不7. 表达式 long(intVar) 也可表示为 相关类的私有部分。 _______________。 2. 构造函数可以被继承。 a. intvar = long; b. intVar(long)

3. 动态绑定的多态性是通过虚函数实c. (long)intVar d. 以上都不是 现的。 8. 静态数据成员的生存期4. 在c++中,传引用调用等同于传地_________________。 址调用。 a. 与整个程序相同 b. 不长于类5. 重载函数必须有不同的参数列表。 的生存期 6. 可以用delete释放不是用new运算c. 取决于创建的对象数 d. 以上符分配的内存。 都不是 7. 类成员的默认访问模式是private。 9. 要让一个类中的所有对象具有共同的数8. 在类Time中的析构函数可以声明据,请使用__________________。 为:void ~Time(int); a. 常数成员变量 b. 私有数据成9. const对象必须初始化。 员 10. 在c++中,只能重载已有的运算符。 c. 静态数据成员 d. 以上都是 10. 设置虚基类的目的是: 二 、选择题(20分) a.简化程序 b.消除二义性 c.提1. 关键字 ____________ 说明对象或变量高运行效率 d.减少目标代码 初始化后不会被修改。 三 、指出下列程序片段中的错误标号,写 a. static b. public c. const d. inline 出正确语句或解释错在何处。(20分) 2. 如果调用带有默认参数的函数时缺少一1) ①int index=675; 个参数,则______________参数就作为这一②const int *ptr=&index; 参数。 ③int *const ntptr=&index; a. 第一个 b. 最后一个 c. 中④*ptr=555; 间一个 d. 以上都不是 ⑤*ntptr=666; 3. 成员函数可声明为静态的,条件是它不访⑥int another=8; 问 __________类成员。 ⑦ptr=&another; a. 静态 b. 常数 c. 非静态 ⑧ntptr=&another; d. 公共 4. 内联函数执行起来比标准函数2) ①int arrp; _______________。 ②arrp=new int[15]; a. 更慢 b. 更快 c. 次数更多 ③delete arrp; d. 以上都不是 5. 默认参数的值由___________________提3)下面程序为什么会编译错误,并改正错供。 误(提出解决办法)。 a. 该函数 b. 调用程序 c. 上述 class window 二者 d. 以上都不是 { 6. 在 C++ 中,混合类型表达式 protected: _____________。 int basedata; }; class border: public window { }; class menu: public window { }; class border_and_menu: public border, public menu { public: int show() { return basedata; } 4)改正下面程序段中的错误,写出整个正确的程序段 double rate; }; double count(A& a) { a.total+=a.rate*a.total; return a.total; } int main(void) { A x(80,0.5),y(100,0.2); cout< using namespace std; class Count{ private: static int counter; int obj_id; public: Count(); //constructor static void display_total(); //static function void display(); ~Count(); //destructor }; int Count::counter; //definition of static data member Count::Count() //constructor { counter++; obj_id = counter; } Count::~Count() //destructor { counter--; template void print(T *a) { cout< using namespace std; class A {friend double count(A&); public: A(double t, double r):total(t),rate(r){} private: double total;