****题二、选择题( 20 分) 1. 关键字____________ 说明对象或变量初始化后不会被修改。 a. static b. public c. const d. inline 2. 如果调用带有默认参数的函数时缺少一个参数,则______________ 参数就作为这一参数。 a. 第一个 b. 最后一个 c. 中间一个 d. 以上都不是 3. 成员函数可声明为静态的,条件是它不访问__________ 类成员。 a. 静态 b. 常数 c. 非静态 d. 公共 4. 内联函数执行起来比标准函数_______________ 。 a. 更慢 b. 更快 c. 次数更多 d. 以上都不是 5. 默认参数的值由___________________ 提供。 a. 该函数 b. 调用程序 c. 上述二者 d. 以上都不是 C++ 中,混合类型表达式_____________ 。 a. 允许存在 b. 为一错误 int到 float float 到 int 7. 表达式 long(intVar) 也可表示为_______________ 。 a. intvar = long; b. intVar(long) c. (long)intVar d. 以上都不是 8. 静态数据成员的生存期_________________ 。 a. 与整个程序相同 b. 不长于类的生存期 c. 取决于创建的对象数 d. 以上都不是 9. 要让一个类中的所有对象具有共同的数据,请使用__________________ 。 a. 常数成员变量 b. 私有数据成员 c. 静态数据成员 d. 以上都是 10. 设置虚基类的目的是: a. 简化程序 b. 消除二义性 c. 提高运行效率 d. 减少目标代码四、写出下面程序的执行结果:( 15 分) 1) #include <iostream> using namespace std; class A {friend double count(A&); public: A(double t, double r):total(t),rate(r){} private: double total; double rate; }; double count(A& a) { +=*; return ; } int main(void) {A x(80,),y(100,); cout<<count(x)<<','<<count(y)<<'\n'; cout<<count(x)<<'\n'; return 0; } 执行结果: 2) #include<iostream> 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