电大形成性考核册c++第四次作业及答案

上传人:1777****777 文档编号:36379385 上传时间:2021-10-30 格式:DOC 页数:10 大小:138.02KB
收藏 版权申诉 举报 下载
电大形成性考核册c++第四次作业及答案_第1页
第1页 / 共10页
电大形成性考核册c++第四次作业及答案_第2页
第2页 / 共10页
电大形成性考核册c++第四次作业及答案_第3页
第3页 / 共10页
资源描述:

《电大形成性考核册c++第四次作业及答案》由会员分享,可在线阅读,更多相关《电大形成性考核册c++第四次作业及答案(10页珍藏版)》请在装配图网上搜索。

1、专业好文档计算机应用专业“C+语言程序设计”课程作业第四次作业一、 填空题1. 在定义类对象的语句执行时,系统在建立每个对象的过程中将自动调用该类的_构造函数_使其初始化。2. 当一个类对象被撤消时将自动调用该类的_析构函数_。3. 对基类数据成员的初始化是通过执行派生类构造函数中的_初始化表_来实现的。4. 对一个类中的数据成员的初始化可以通过构造函数中的_初始化表_实现,也可以通过构造函数中的_赋值语句_实现。5. 在一个派生类中,对基类成员、类对象成员和非类对象成员的初始化次序的先基类成员,后类对象成员,最后非对象成员。6. 当撤消一个含有基类和类对象成员的派生类对象时,将首先完成派生类

2、本身的析构函数定义体的执行,接着完成类对象成员的析构函数定义体的执行,最后完成基类成员的析构函数定义体的执行。7. 设PX是指向一个类动态对象的指针变量,则执行“delete px;”语句时,将自动调用该类的析构函数。8. 当一个类对象离开它的作用域时,系统将自动调用该类的析构函数。9. 假定一个类对象数组为AN,当离开它的作用域时,系统自动调用该类析构函数的次数为N次。10. 假定AB为一个类,则执行“AB a10;”语句时,系统自动调用该类构造函数的次数为10次。11. 假定拥护没有给一个名为AB的类定义构造函数,则系统为其隐含定义的构造函数为空构造函数。12. 假定用户没有给一个名为AB

3、的类定义析构函数,则系统为其隐含定义的析构函数为空析构函数。13. 若需要把一个函数“void f(); ”定义为一个类AB的友元函数,则应在类AB的定义中加入一条语句:friend void f();。14. 若需要把一个类AB定义为一个类CD的友元类,则应在类CD的定义中加入一条语句:friend class AB;。15. 假定一个类AB中有一个静态整型成员bb,在类外为它进行定义并初始化为0时,所使用写法为AB:bb = 0;。16. 假定类AB中有一个公用属性的静态数据成员bb,在类外不通过对象名访问该成员 bb的写法为AB:bb。17. 当类中一个字符指针成员指向具有n个字节的储存

4、空间时,它所能储存字符串的最大长度为n-1。18. 假定AB为一个类,则该类的拷贝构造函数的声明语句为AB:AB(AB &)。19. 对类对象成员初始化是通过执行构造函数中的初始化表完成的。20. 对于类中定义的成员,其隐含访问权限为private,对于结构中定义的成员,其隐含访问权限为public。21. 一个类的友元函数或友元类能够通过成员操作符访问该类的所有数据成员和函数成员。22. 假定要对类AB定义加号操作符重载成员函数,实现两个AB类对象的加法,并返回相加结果,则该成员函数的声明语句为:AB operator +(AB, AB);。23. 在C+流类库中,根基类为ios。24. 在

5、C+流类库中,输入流类和输出流类的名称分别为istream和ostream。25. 若要在程序文件中进行标准输入输出操作,则必须在开始的#inlude命令中使用iosteam.h头文件。26. 若要在程序文件中进行文件输入输出操作,则必须在开始的#inlude命令中使用fstream.h头文件。27. 当从字符文件中读取回车和换行两个字符时,被系统看作为一个换行符。28. 当使用ifstream流类定义一个流对象并打开一个磁盘文件时,文件的隐含打开方式为 读取的文本文件,当使用ofstream 流类定义一个流对象并打开一个磁盘文件时,文件的隐含打开方式为写入的文本文件。29. 当需要使用ist

6、rstream流类定义一个流对象并联系一个字符串时,应在文件开始使用#include命令,使之包含strstrea.h文件。二给出下列程序运行后的输出结果1#includeclass Aint a, b;public: A( ) a=b=0;A( int aa, int bb) a=aa; b=bb; couta bendl;void main( ) A x,y(6,3), z(8,10);6 38 102#includeclass Aint a, b;public:A(int aa= 0, int bb= 0): a(aa),b(bb)coutConstructor! a + bendl;v

7、oid main()A x, y(2,5), z(y);Constructor!0Constructor!73#includeclass Aint * a;public:A(int aa= 0)a = new int(aa);coutConstructor! * aendl;void main()A x2;A * p = new A(5);delete p;Constructor!0Constructor!0Constructor!54#includeclass Aint a;public:A(int aa= 0): a(aa)A()coutDestructor! a endl; void m

8、ain()A x(5);A * p = new A(10);delete p;Destructor!10Destructor!55#includeclass A int * a;public:A(int x)a = new int(x);coutConstructor! * aendl;A()delete a;coutDestructor!endl;void main()A x(9),* p;p = new A(12);delete p;Constructor!9Constructor!12Destructor!Destructor!6#includeclass Aint a;public:A

9、(int aa= 0): a(aa)coutConstructor A! aendl;class B:public Aint b;public:B(int aa, int bb): A(aa), b(bb)coutConstructor B! bendl;void main()B x(2,3),y(4,5);Constructor A!2Constructor B!3Constructor A!4Constructor B!57#includeclass Aint a;public:A(int aa= 0)a = aa;A()coutDestructor A! aendl;class B:pu

10、blic Aint b;public:B(int aa= 0, int bb= 0): A(aa)b = bb;B()coutDestructor B!bendl;void main()B x(5),y(6,7);Deconstructor B!7Deconstructor A!6Deconstructor B!0Deconstructor A!58#include#includeclass Aint a,b;char op;public:A(int aa, int bb, char ch)a = aa;b = bb;op = ch;int Comp()switch(op)case + :re

11、turn a + b;case - :return a - b;case * :return a * b;case / :if(b!=0)return a/b;else exit(1);case % :if(b!=0)return a%b;else exit(1);default:exit(1);void SetA(int aa, int bb, char ch)a = aa;b = bb;op = ch;void main(void)A x(3,5,*);int a = x.Comp();x. SetA(4,9, +);a += x.Comp();x. SetA(13,8, %);a +=

12、x.Comp();couta=aendl;a=339#includeclass Bint a,b;public:B()a = b = 0;B(int aa, int bb)a = aa;b = bb;B operator +(B& x)B r;r . a = a + x . a;r . b = b + x . b;return r;B operator -(B& x)B r;r . a = a - x . a;r . b = b - x . b;return r;void OutB()cout a b endl;void main()B x(6,5),y(13,3), z1, z2;z1 =

13、x + y;z2 = x - y;z1.OutB();z2.OutB();19 8-7 210#includetemplateclass FFTT a1,a2,a3;public:FF(TT b1, TT b2, TT b3)a1 =b1;a2 =b2;a3 =b3;TT Sum()return a1 + a2 + a3;void main()FF x(8,3,4),y(5,9,11);cout x. Sum() y. Sum()endl;15 25二、 写出下列每个函数的功能1include include include void JA(char * fname) / /可以把fname所

14、指字符串作为文件标识符的文件称为fname文件ofstream fout(fname);char a20;cin a;whlie(strcmp(a,”end”)!=0)fout a a;将键盘输入的字符串(上限为19个字符)写入到fname文件中。2include include void JB(char * fname) / /可把以fname所指字符串作为文件标识符的文件称为fname文件 / /假定该文件中保存着一批字符串,每个字符串的长度均小于20。 ifstream fin(fname);char a20;int i = 0;whlie(fin a)cout a endl;i + +

15、;fin.close();cout ”i = ” i endl;将fname文件输出到标准输出流(屏幕)上,最后显示字符串的数量。3include include void JC(chat * fname, int n) / /可把以fname所指字符串作为文件标识符的文件称为fname文件ofstream fout(fname, ios : : out | ios : : binary);int x;for(int i = 0;I x;fout.write(char * )&x, sizeof(x);fout.close();从键盘输入n个数,并以二进制的方式写到fname文件中。4incl

16、udeincludevoid JD(char * fname) / /可把以fname所指字符串作为文件标识符的文件称为fname文件, / /假定该文件保存着一批整数。ifstream fin(fname, ios : : in | ios : : nocreate | ios : : binary);int x, s = 0, n = 0;whlie(fin.read(char * )&x, sizeof(x)s + = x;n + +;cout n s float(s)/nendl;fin.close();输出fname文件中保存的整数的个数、总加值以及平均值。If we dont do

17、 that it will go on and go on. We have to stop it; we need the courage to do it.His comments came hours after Fifa vice-president Jeffrey Webb - also in London for the FAs celebrations - said he wanted to meet Ivory Coast international Toure to discuss his complaint.CSKA general director Roman Babae

18、v says the matter has been exaggerated by the Ivorian and the British media.Blatter, 77, said: It has been decided by the Fifa congress that it is a nonsense for racism to be dealt with with fines. You can always find money from somebody to pay them.It is a nonsense to have matches played without sp

19、ectators because it is against the spirit of football and against the visiting team. It is all nonsense.We can do something better to fight racism and discrimination.This is one of the villains we have today in our game. But it is only with harsh sanctions that racism and discrimination can be washe

20、d out of football.The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.I am going to be at the match tomorrow and

21、 I have asked to meet Yaya Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experience was.Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win.Michel Platini, president of Euro

22、pean footballs governing body, has also ordered an immediate investigation into the referees actions.CSKA said they were surprised and disappointed by Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA.Baumgartner the disappointing news: Mission abo

23、rted.The supersonic descent could happen as early as Sunda.The weather plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move th

24、rough the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere.

25、 As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The balloon will slowly drift to the edge of space at 120,000 feet ( Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bot

26、tom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end.Skydiver preps for the big jumpWhen he jumps, he is expected to reach t

27、he speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization para

28、chute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will h

29、ave a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).cause there

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

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!