下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 装 订 线 西安工业大学试题纸学年学期20092010学年第一学期课程名称 面向对象技术与C+ A卷/B卷命题教师审 批考试形式开卷/闭卷考试类型考试/考查使用班级070601、02、03、09、10考试时间2009.12.22 1:303:30考试地点C101、C102学生班级姓 名学 号备 注一、程序填空题(共5题,每空2分,共30分)2、#include class p_class int num ; public : void set_num ( int val ) num = val ; void show_num ( ) ; ; void p_class : show_num (
2、 ) 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 101、#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 h3
3、、#include class Tdate int month ; int day ; int year ; int IsLeapYear() 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 l
4、eapyear.n; void main() Tdate a ; a.Set ( 2, 4, 2000 ) ; a.Print() ; 3、#include class Base1 public: Base1( 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),
5、 Base1(c), b2(a), b1(d) coutA construct: a+b+c+d endl; private: Base1 b1; Base2 b2; ; void main() A obj( 1, 2, 3, 4 ); 2、#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
6、active! endl; void main( ) test x2; cout Exiting main endl; 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 destr
7、oyed. 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、#include iostream.h#includestdlib.hclass ARRAY int *v; /指向存放数组数据的空间 int s; /数组大小 public: ARRAY(int a, int n);
8、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) / 的运算符成员函数定义if(n=s) cerr下标越界!; exit(1); return _(15)_;4、#include class Time public: Time(int h, int m) hours=h; minutes
9、=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) cout_(11)_ void main() Time T1(20,30), T2(10,45); T1.Time12(); Time24(T1); T2.Time12(); Time24(T2); 输出: 8:30PM 20:30 10:
10、45AM 10:45二、写出程序的运行结果(共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;coutf(a,3,3)endl; 7、#include class Bclass public: Bclass( int i, int j ) x = i; y = j; virtual int fun
11、() return 0 ; int getx()return x; int gety()return y; protected: int x, y ; ; class Iclass:public Bclass public : Iclass(int i, int j, int k):Bclass(i, j) z = k; int fun() return ( x + y + z ) / 3; int getz()return z; private : int z ; ;void main() Iclass obj( 2, 4, 10 ); Bclass p1 = obj; cout p1.fu
12、n() endl; Bclass & p2 = obj ; cout p2.fun() endl; cout p2.Bclass : fun() endl; Bclass *p3 = &obj; cout fun() endl; coutgetz()endl; 5、#includeclass A public:A( ) coutcall A( )n; virtual A( ) coutcall A( )n; ;class B:public A char* buf;public:B( ) buf=new char100; coutcall B( )n; B( ) delete buf; coutcall B( )n; ;void main( ) A *p=new B; delete p; 6、#include iostream.hvoid main() int a33=1,2,3,4,5,6,7,8,9; cout*(a1+2);三 编程题(1、2每小题10分,第3题15分,共35分):1、 用面向对象的方法,编程实现求100300以内的所有素数。2、利用静态数据成员的概念,编写一个类,可以统计目前存在多少个该类的对象,并在主程序中使用这个类。3、 定义一个字符
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 营销新年活动策划方案(3篇)
- PLC课程设计反思
- 基于强化学习的广告创意优化课程设计
- 健康宣教传播
- 2026年中国高强料行业市场规模及投资前景预测分析报告
- 2025年公共卫生资格冲刺模拟卷
- 2025年公共卫生执业医师专项训练卷
- 2025年兴业银行总行社会招聘备考题库及一套参考答案详解
- 绿化造园工岗前安全素养考核试卷含答案
- 五年级数学(小数乘法)计算题专项练习及答案汇编
- 2026年包头钢铁职业技术学院单招职业适应性测试题库及1套参考答案详解
- 2026黑龙江省交通运输厅所属事业单位招聘86人考试参考题库及答案解析
- 2026年春季学期学校教学工作计划:一个中心、两大驱动、三条主线、四项保障
- 城市供水管网巡检与维修操作手册(标准版)
- 2026年荆门市急需紧缺人才引进1502人笔试备考题库及答案解析
- 产业园停车制度规范
- 2026年山东司法警官职业学院单招综合素质笔试参考题库含详细答案解析
- 医院管理委员会与职责
- 2026江苏苏州高新区狮山横塘街道招聘11人备考题库(含答案详解)
- (新教材)2026年春期人教版三年级下册数学教学计划+教学进度表
- 风沙天气安全培训课件
评论
0/150
提交评论