面向对象技术与C考试A卷答案.doc

上传人:xt****7 文档编号:126350063 上传时间:2020-03-24 格式:DOC 页数:8 大小:93.50KB
返回 下载 相关 举报
面向对象技术与C考试A卷答案.doc_第1页
第1页 / 共8页
面向对象技术与C考试A卷答案.doc_第2页
第2页 / 共8页
面向对象技术与C考试A卷答案.doc_第3页
第3页 / 共8页
面向对象技术与C考试A卷答案.doc_第4页
第4页 / 共8页
面向对象技术与C考试A卷答案.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《面向对象技术与C考试A卷答案.doc》由会员分享,可在线阅读,更多相关《面向对象技术与C考试A卷答案.doc(8页珍藏版)》请在金锄头文库上搜索。

1、一、程序填空题(共5题,每空2分,共30分)1、#include class A _(1)_ void f(int i)coutit; void g()coutgn; ; class B:private A public: void h()couthn; _(2)_ ; void main() B d; d.f(6); d.h(); 输出: 6 h参考答案:(1) public: (2) void f(int i) A:f(i);/coutit;2、#include class p_class int num ; public : void set_num ( int val ) num =

2、val ; void show_num ( ) ; ; void p_class : show_num ( ) cout num t ; void main ( ) p_class ob3 , * p ; for ( int i = 0; i show_num ( ) ; _(4)_; p - show_num ( ) ; _(5)_; p - show_num ( ) ; 输出: 20 30 10参考答案:(3)p=&ob1 (4) p=&ob2 (5)p=&ob03、#include class Tdate int month ; int day ; int year ; int IsLe

3、apYear() return(year%4=0&year%100!=0)|(year%400=0); _(6)_ void Set (int m, int d, int y) month=m; day=d; year=y; _(7)_; ; _(8)_Print() cout month / day / yearendl ; if(IsLeapYear()coutThis year Is leapyear.n ; else coutThis year Is not leapyear.n; void main() Tdate a ; a.Set ( 2, 4, 2000 ) ; a.Print

4、() ; 参考答案:(6) public:(7) void Print()(8) void Tdate:4、#include class Time public: Time(int h, int m) hours=h; minutes=m; void Time12(); _(9)_ Time24(Time time); private: int hours, minutes; ; _(10)_ Time12() if(hours12) couthours-12:minutesPMn ; else couthours:minutesAMn ; void Time24(Time time) cou

5、t_(11)_ void main() Time T1(20,30), T2(10,45); T1.Time12(); Time24(T1); T2.Time12(); Time24(T2); 输出: 8:30PM 20:30 10:45AM 10:45参考答案:(9) void friend (10) void Time: (11) time.hours:time.minutesendl; 5、已知一维数组类ARRAY的定义如下,构造函数的作用是把参数n的值赋给s,给v动态分配长度为n的数组空间,接着利用数组参数a初始化v所指向的数组。ARRAY与普通一维数组区别是:其重载的运算符 要对下标

6、是否越界进行检查。#include iostream.h#includestdlib.hclass ARRAY int *v; /指向存放数组数据的空间 int s; /数组大小 public: ARRAY(int a, int n); ARRAY()delete v; int size() return s; int& operator(int n); ;ARRAY: ARRAY(int a, int n) if(n=0) v=NULL;s=0;return; s=n; v=_(12)_; for(int i=0; in; i+) _(13)_;_(14)_ operator(int n)

7、/ 的运算符成员函数定义 if(n=s) cerr下标越界!; exit(1); return _(15)_;参考答案:(12) new ints (13) vi=ai(14) int & ARRAY: (15) vn二、写出程序的运行结果(共7题,每题5分,共35分)1、#include int f (int a 3 ,int row,int col) int i,j,t= 1;for(i=0;irow;i+) for(j=0;jcol;j+) aij+; if (i=j) t*=aij; return t; void main() int a 3=0,1,2,3,4,5,6,7,8;cou

8、tf(a,3,3)endl; 参考答案:452、#include class test private: int num; public: test( ); int geint( )return num; test( ); ; test : test( ) cout constructor is active! endl; num=0; test: test( ) cout Destructor is active! endl; void main( ) test x2; cout Exiting main endl; 3、#include class Base1 public: Base1(

9、 int i ) cout Base1 construct i endl ; ; class Base2 public: Base2( int j ) cout Base2 construct j endl ; ; class A: public Base1, public Base2 public: A( int a, int b, int c, int d ) : Base2(b), Base1(c), b2(a), b1(d) coutA construct: a+b+c+d endl; private: Base1 b1; Base2 b2; ; void main() A obj(

10、1, 2, 3, 4 ); 4、#include class Location public: Location( int xx = 0 , int yy = 0 ) X = xx ; Y = yy ; cout Constructor Object.n ; Location( Location & p ) /复制构造函数 X = p.X ; Y = p.Y ; cout Copy_constructor called. endl ; Location() cout X , Y Object destroyed. endl ; int GetX () return X ; int GetY () return Y ; private : int X , Y ; ;void f ( Location p ) cout Funtion: p.GetX() , p.GetY() endl ; void main() Location A ( 1, 2 ) ; f ( A ) ;5、#includeclass A public:A( ) coutcall A( )n;

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 中学教育 > 试题/考题

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号