首页>计算机>软件水平考试>模拟试题>正文
面向对象程序设计试题(二)

www.zige365.com 2010-7-5 15:47:25 点击:发送给好友 和学友门交流一下 收藏到我的会员中心

int getx(); 
int gety(); 
}; 
void location::init (int initx, int inity) { 
x = initx; y = inity; 

int location::getx() { 
return x; 

int location::gety() { 
return y; 

#include  
void main() { 
location a1; 
_____________________ // 定义一个指向a1的指针pa1; 
_____________________ // 用pa1将对象a1的书籍成员x和y分别初始化为6和8 

五、 程序分析题(5×6): 
31、 
# include  
class a { 
int * a; 
public: 
a (int x) { a = new int(x); cout<<"*a = "<<*a<}; 
void main() { 
a x(3), *p; 
p = new a (5); 
delete p; 

32、 
# include  
template  
void f (t &x, q &y) { 
if (sizeof (t) > sizeof (q)) x = (t)y; 
else y = (q)x; 

void main() { 
double d; 
int i; 
d = 9999; i = 88; 
f (d,i); 
cout << "d=" << d << " i= " << i << endl;

d = 88; i = 9999; 
f (i,d); 
cout << "d=" << d << " i= " << i << endl; 

33、 
# include  
class base { 
public: 
virtual int func () { return 0; } 
}; 
class derived: public base { 
public: 
int func() { return 100; } 
}; 
void main() { 
derived d; 
base& b = d; 
cout << b.func() << endl; 
cout << b.base::func() << endl; 

34、 
# include  
class test { 
private: 
static int val; 
int a; 
public: 
static int func(); 
static void sfunc(test &r); 
}; 
int test::val = 20; 
int test::func() { 
val += val; 
return val; 

void test::sfunc(test &r) { 
r.a = 25; 
cout << " result3 = " << r.a; 

void main() { 
cout << "result1 = " << test::func() << endl; 
test a; 
cout << "result2 = " << a.func(); 
test::sfunc(a); 
}

本新闻共3页,当前在第3页  1  2  3  

我要投稿 新闻来源: 编辑: 作者:
相关新闻
面向对象程序设计试题(一)