当前位置:首页 > 面向对象程序设计模拟试卷
面向对象程序设计模拟试卷一
一. 单选题(15)。
1. 关于构造的叙述_____正确: A. 最先构造虚基类 B. 最先构造基类 C. 最先构造派生类的对象成员 D. 都不对 2. 关于静态数据成员的叙述_____正确: A. 公有的可在类体外初始化 B. 私有的不能在类体外初始化 C. 私有和保护的不能在类体外初始化 D. 都可以且必须在体外初始化 3. 若派生类函数不是基类的友元,关于该函数访问基类成员_____正确: A. 公有的可被派生类函数访问 B. 都可以被派生类函数访问 C. 公有和保护的可被派生类函数访问 D. 都不对 4. 关于函数的所有缺省参数的叙述_____正确: A. 只能出现在参数表的最左边 B. 只能出现在参数表的最右边 C. 必须用非缺省的参数隔开 D. 都不对 5. 使用friend、virtual、static说明函数的叙述_____正确: A. 必须同时使用三个 B. 只能同时用其中两个 C.只能独立单个地使用 D. 都不对 二. 指出各类的成员及其存取属性(20) 。
class A{ int a; protected: int b; public: }; int c; class C: A{ int g;protec ted: int h;publ ic: int i;}; class D: B, C int j;protec ted: B ::b; int k;priva te: }; int n;class B: protected A{ int d; protected: int e; public: A::c; }; int f;
三. 指出main中每行的输出结果(20) 。
#include
struct A{A( ){ cout<<'A';}}; struct B{B( ){ cout<<'B';}}; struct C: A{C( ){ cout<<'C';}};
struct D: virtual B, C{D( ){ cout<<'D';}}; struct E: A{ C c;
E( ): c( ){ cout<<'E';} };
struct F: virtual B, C, D, E{ F( ){ cout<<'F';} };
void main( ){
A a; cout<<'\\n'; B b; cout<<'\\n'; C c; cout<<'\\n'; D d; cout<<'\\n'; E e; cout<<'\\n'; F f; cout<<'\\n'; }
四. 指出以下程序的语法错误及其原因(15) 。
class A{
static int a=0; protected: int b; public: int c; A(int);
operator int( ); } a(1, 2); class B: A{ B(int);
virtual int d; int e; public: A::b;
friend int operator =(B); static B(int, int); } b=5; class C: B{ public:
int operator++(double); };
int main( ){
int *A::*p, i; i=a.a;
i=A(4); i=b.c; p=&A::c; i=b; return ; }
五. 指出main变量i在每条赋值语句执行后的值(15) 。
int x=2, y=x+30; struct A{
static int x; int y; public:
operator int( ){ return x-y; }
A operator ++(int){ return A(x++, y++); }
A(int x=::x+2, int y=::y+3){ A::x=x; A::y=y; } int &h(int &x); };
int &A::h(int &x) {
for(int y=1; y!=1|| x<201; x+=11, y++) if(x>200) { x-=21; y-=2;} return x-=10; }
int A::x=23; void main( ){
A a(54, 3), b(65), c;
int i, &z=i, A::*p=&A::y; z=b.x; i=a.x; i=c.*p; i=a++; i=::x+c.y; i=a+b; b.h(i)=7; }
六. 为了没有误差地表示分数,定义类FRACTION来表示分数,请编程实现分数类中的除
cmd外的所有函数(15)。
class FRACTION{ //对于7,numerator存分子6,denominator存分母7 int numerator, denominator; static int cmd(int x, int y); public:
int operator>(const FRACTION&)const; FRACTION(int num, int den=1); FRACTION operator*( )const;
//大于比较,例7>3 //分数约简,*36=6 //加法,7+3=21
621246232305626 //求整数x,y的最大公约数
//num、den各为分子和分母
FRACTION operator+(const FRACTION&)const;
FRACTION operator*(const FRACTION&)const; //乘法,7*3=21=7 };
int FRACTION::cmd(int x, int y){ int r;
if(x return x; }
共分享92篇相关文档