2013面向对象程序设计期末考试试卷A.doc_第1页
2013面向对象程序设计期末考试试卷A.doc_第2页
2013面向对象程序设计期末考试试卷A.doc_第3页
2013面向对象程序设计期末考试试卷A.doc_第4页
2013面向对象程序设计期末考试试卷A.doc_第5页
已阅读5页,还剩1页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

专业 班级 学号 姓名 温馨提示:端正考风、严肃考纪、诚信参加考试 凡是代考、使用通讯设备作弊、二次作弊,一经发现开除学籍。东华理工大学2013 2014学年第 一 学期考试试卷(A) 面向对象程序设计 课程 闭/开卷 课程类别:考试/考查题号一二三四五六七八九总分分数评卷人一、 程序填空题(20分,每空2分)1、以下程序主要实现了动态申请存储空间,使用完成后能够释放申请的空间。根据注释信息,请在_上填入正确内容。#include using namespace std;int main() int *s; s=new int(60)_; /为s动态申请一个int类型的空间并存入数值60if (s=NULL) exit(0); cout *s endl; delete s_; /释放s所指向的空间。return 0;2、以下程序主要实现了Point类的定义,完成拷贝函数的填写。根据注释信息,请在_上填入正确内容。class Point public: Point(int xx=0,int yy=0)x=xx; y=yy; /构造函数 Point(Point& p); /拷贝构造函数 int GetX() return x; int GetY() return y_; /返回y坐标 private: int x,y;Point:Point (Point& p) x=p.x_; y=p.y;3、以下程序主要利用类的友元函数实现了运算符的重载,根据注释信息,请在_上填入正确内容。#include using namespace std;class Complex /复数类定义public:/外部接口Complex(double r = 0.0, double i = 0.0) : real(r), imag(i) /构造函数friend Complex operator + (const Complex &c1, const Complex &c2);/运算符+重载private:/私有数据成员double real;/复数实部double imag;/复数虚部;Complex operator + (const Complex &c1, const Complex &c2) complex temp_; /定义临时变量 temp.real=c1.real+c2.real; temp.imag=c1.imag+c2.imag_; return temp;4、以下程序主要实现类的继承,根据注释信息,请在_上填入正确内容。#include using namespace std;class Point /基类Point点类的定义public: Point(float x1, float y1 ) x = x1; y = y1; private:float x, y; /定义坐标点;class Rectangle: public Point_/派生类Rectangle为矩形类,公有继承Point类public: Rectangle(float c, float d, float w, float h) :Point(c,d)_ /形参c,d用于初始化基类的数据成员x,ywidth = w;heigh = h;private: float width, heigh; /定义矩形的高、宽;5、在下面程序的横线处填上适当的语句,使该程序执行结果为10#include class MyClass public: MyClass(int a) x = a; int GETNUM()_ /定义函数 return x_; /取x值 private:int x; ; int main() MyClass my(10); coutmy.GETNUM()ENDL; return 0; 二、程序改错题(20分,每题5分)以下每个程序各有两个错误,请改正,使其能按照要求得到正确的运行结果,可以直接在错误的语句边修改。1、定义类Point,并在main函数中定义Point对象并显示其位置。#includeusing namespace std;class Pointprivate:int x,y=20; /此行有错int x,y;public: init(int a,int b) /构造函数,此行有错Point(int a,int b); x=a;y=b;void show() coutx= x y=y; ;void main() Point pt(24,50); pt.show(); 2、函数swapint用于实现两个整数交换,输出结果是。#includeusing namespace std;void swapint(int a,int b);void main()int a1=1,b1=2;couta1=a1,b1=b1endl;call swapint(a1,b1); /此行有错swapint(a1,b1);couta1=a1,b1=b1endl;void swapint(int a,int b) /引用形参,此行有错void swapint(int &a,int &b)int t;t=a;a=b;b=t;3、生成具有10个元素的动态数组,并对其进行输出。#include using namespace std;void main()int a10;/动态数组定义,此行有错int *a=new int10;for(int i=0;i10;i+)ai=i;coutaiendl;delete a;/此行有错delete a;4、定义类A,max函数是A的友元函数,通过max实现两个A类对象的较大值。#include using namespace std;class Aprivate:int x;public:A(int i)x=i;A()x=0;int max(A a,A b);/此行有错freind int max(A a,A b);int max(A a,A b) return (a.xb.x)?a.x:b.x;void main() A a(3),b(5);couta.max(a,b)endl; /此行有错coutmax(a,b)endl;三、读程题,写出程序的运行结果。(每小题6分,共30分)1、#includevoid swap(int x,int &y,int *z);void main( ) int a,b(10),c; a=b/3;c=a/2;couta=a,b=b”c=”cendl; swap(a,b,&c); couta=a,b=b”c=”cendl;void swap(int x,int &y, int *z) int t; t=x; x=y; y=t;*z=t;a=3,b=10,c=1a=3,b=3,c=3Press any key to continue_2、#include using namespace std;void fun(int a,int b = 2,int c = 3) cout a b c endl;void main()fun(10);fun(10,20); fun(10,20,30);10 2 310 20 310 20 30Press any key to continue_3、void main()int a=5,6,3,7,4,8,9,2;int *p=a;int min,max;min=max=0;for(int i=1;ipi) min=i; if(pmaxpi) max=i; coutmax” “pmax” “min” “pminendl;9 6 2 7Press any key to continue_4、#include#includeclass person int age; char name10;public:person(int i=0, char *str=xxx)age=i; strcpy(name,str);void display()coutname is age years old.n; ;void main() person d1(20); d1.display(); person d2(50,li-gang); d2.display();xxx is 20 years old.li-gang is 50 years old.Press any key to continue_5、#include using namespace std;class A public: A( ) virtual void func( ) cout Destructor Aendl;A( ) func(); ; class B:public A public: B( ) void func()coutDestructor B func();a.func(); 5.Destructor BDestructor B Destructor APress any key to continue_四、编程题。(每题10分,共30分)1.编写从键盘输入一行字符,统计出这行字符的字母个数、数字个数和其他符号的个数(提示读一行字符用cin.getline( s,80) ,s为数组名)。#include#includeusing namespace std;void main()char s80;int a=0,b=0,c=0;cin.getline(s,80);for(int i=0;ia&siA&si0&si9)b=b+1;elsec=c+1;cout字母个数:aendl数字个数:bendl其他字符个数:cendl;2. 有一圆环,其中小圆半径为3.5,大圆半径为8。编程定义一个circle类,含有私有变量半径r,构造函数能够初始化r、成员函数Area能计算圆面积。主函数中通过定义2个对象(大圆和小圆)来计算出圆环的面积。#includeusing namespace std;class circleprivate:double r;public:circle(double rr)r=rr;double area()return 3.14*r*r;void main()circle c1(3.5);circle c2(8);cout圆环的面积为:c2.area()-c1.area()endl; 3. 设计类Car,私有数据成员有名字name、车龄age,重量weigth,初始化函数init( )初始化各各数据成员,成员函数disp输出各数据成员。主函数创建对象C1,调用init函数初始化C1的名字:宝马,车龄:1,重量 2.5吨,调用成员函数输出C1的名字、车龄和重量。#include#includeusing namespace st

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论