简答题 | 使用VC++6.0打开考生文件夹下的源程序文件2.cpp。请完成函数fun(intx)的定义,该函数功能是判定x的所有约数,并且在函数中调用写函数WriteFile将结果输出到2.txt文件中。 例如:x=100的约数为124510202550100。 注意:不要改动main函数,不得增行或删行,也不得更改程序的结构。 试题程序: #include<iostream) #include(fstream) #include(cmath) usingnamespacestd; voidWriteFile(intc) { ofstreamout1; out1.open("2.txt",ios_base::binary|ios_base::app); out1<<c<<'';’ out1.close(); } voidfun(intx) { } voidClearFile() { ofstreamout1; out1.open("2.txt"); out1.close(); } intmain() { ClearFile(); fun(100); return0; } |
查看答案 |
简答题 | 使用VC++6.0打开考生文件廷下的源程序文件3.cpp。其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整,使其输出的结果为 TCA TCB TCC (1)完成类B虚继承于A,请在注释1后添加适当的语句。 (2)完成类C虚继承于A,请在注释2后添加适当的语句。 (3)完成类D继承于B,C,请在注释3后添加适当的语句。 (4)函数fun通过调用基类的fun,完成所输出的内容,请在注释4后添加适当的语句。 注意:增加或者修改代码的位置已经用符号表示出来,请不要修改其他的程序代码。 试题程序: #include classTCA { public: voidfun() { cout<<"TCA"< } }; //********1********classTCB { public: voidfun() { cout<<"TCB"< } }; //********2********classTCC { public: voidfun() { cout<<"TCC"< } }; //********3********classTCD { public: voidfun() { //********4********} }; voidmain() { TCDtest; test.fun(); return; }; |
查看答案 |
简答题 | 使用VC++6.0打开考生文件夹下的源程序文件1.cpp,该程序运行时有错误,请改正其中的错误,使得程序正确运行。 程序输出: s1:n=20 s2:n=10 执行s3.add(s1,s2) s3:n=30 s4:n=30 注意:不要改动main函数,不能增加或删除行,也不能更改程序的结构,错误的语句在//******error******的下面。 试题程序: #include<iostream.h) classTC { intn; public: TC(){} TC(intm) { n=m: } //********error******** TCadd(TCs1,s2) { this->n=s1.n+s2.n; //********error******** return(this); } voiddisp() { cout<<"n一="<<n< } //********error******** } voidmain() { TCs1(20),s2(10),s3,s4; cout<<"s1:"; s1.disp(); cout<<"s2:"; s2.disp(); s4=s3.add(s1,s2); cout<("执行s3.add(s1,s2)\ns3:"; s3.disp(); COUt<<"s4:";s4.disp(); } |
查看答案 |
简答题 | 使用VC++6.0打开考生交件夹下的源程序文件2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(intN[4])的功能是用4个数字,组成互不相同且无重复数字的3位数,并将满足所有条件的数字输出到屏幕, 并且每输出一个3位数就换一行。 程序分析:可填在百位、十位、个位的数字都是1、2、3、0。组成所有的排列后再去掉不满足条件的排列。如果判定第一个数字是0,则也去掉。 试题程序: #include voidfun(intN[4]) { } intmain() intN[4]={1,2,3,0}; fun(N): return0; } |
查看答案 |
简答题 | 使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示雇员的Employee类,但类Em-ployee的定义并不完整。请按要求完成下列操作,将类TC的定义补充完整。 (1)定义私有数据成员name、street、city、zipcode和age分别用于表示姓名、街道、城市、邮编、年龄,除年龄是整型外,其余都是char型的数据。请在注释1之后添加适当的语句。 (2)完成默认构造函数TC的定义,使其把参数传递给私有数据成员name、streel、city、zipcode和age。请在注释2之后添加适当的语句。 (3)完成成员函数aherName(char*newName)的定义。请在注释3之后添加适当的语句。 (4)完成成员函数IsEqual(char*ename)的定义,实现当name相等时返回真,否则返回假的功能。请在注释4之后添加适当的语句。 注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。 试题程序: #include #include<string.h) #defineMAXLEN20 classTC { private: //********、******** intage; public: TC(char*newName,char*newStreet,char* newCt,char*newZp,intnewAge); voidalterName(char*newName); voiddisplay(); boolIsEqual(char*ename); }; TC::TC(char*newName,char*newStreet,char* newCt,char*newZp,intnewAge) { //********2******** age=newAge; } voidTC::alterName(char*newName) { //********3******** } boolTC::IsEqual(char*ename) { //********4******** } voidTC::display() { cout<<name<<""<<street<<""; cout<<city<<""<<zipcode<<""<<age< } voidmain(void) { TCemployee[4]= { TC("张三","海淀区复兴路l号","北京","000001",18), TC("李四","海淀区复兴路2号","北京","000002",19), TC("王五","海淀区复兴路3号","北京","000003",20), TC("赵六","海淀区复兴路4号","北京","000004",21) }; for(inti=0;i<4;i++) employee[i].display(); cout<<"\n修改\"李四\"的名字为\"李小四\"\n"< for(intj=0;j<4;j++) { if(employee[j].IsEqual("李四")) { employee[j].aherName("李小四"); employee[j].display(); break; } } } |
查看答案 |
简答题 | 使用VC++6.0打开考生文件夹下的源程序文件1.cpp,该程序运行时有错误,请改正其中的错误,使程序正确运行,并且使程序输出的结果为0K 注意:错误的语句在//******error******的下面,修改该语句即可。 试题程序: #include classTC { public: TC() { a=b=0: } private: inta,b; }; classTCl:publicTC { public: TC1() { } //******error****** virtualvoidfunc(); }; classTC2:publicTCl { public: TC2() { a=0: b=0: } voidfunc() { //******error****** cout<<"OK" } private: inta; intb; }; voidmain() { TC20bj; //******error****** TCl*p=(TCl*)obj; p->func(); } |
查看答案 |
简答题 | 使用VC++6.0打开考生文件夹下的源程序文件2.cpp。阅读下列函数说明和代码,补充空出的代码。函数sum(intn)用于计算在n范围内,能被7和11整除的所有整数的和(包括n在内)。 注意:不能修改程序的其他部分,只能补充sum函数。 试题程序: #include doublesum(intn) { } voidmain() { cout<cout<cout<return; } |
查看答案 |
简答题 | 使用VC++6.0打开考生文件夹下的源程序文件3.cpp,其中定义了用于表示日期的类Date,但类Date的定义并不完整,按要求完成下列操作,将类的定义补充完整。 (1)定义私有成员变量year、month、day。分别表示年、月、日,类型为int。请在注释1后添加适当的语句。 (2)完成构造函数,分别给year、month、day赋值,请在注释2后添加适当的语句。 (3)完成重载符号“十=”的定义,请在注释3后添加适当的语句。 (4)完成print打印函数,输出到屏幕和文件的格式相同,请在注释4后添加适当的语句。 注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。 程序正常运行,输出的结果为2008年11月813。 试题程序: #include(iostream.h) #include(fstream) #include(iomanip) #include<cmath) usingnamespacestd; voidWriteFile(intc) { ofstreamout1; out1.open("3.txt",ios_base::app); out1<<c<<''; out1.close(); } voidWriteFile(char*str) { ofstreamoutl; out1.open("3.txt",ios_base::app); out1< out1.close(); } voidClearFile() { ofstreamout1; out1.open("3.txt"); out1.close(); } classDate { public: Date(inty,intm,intd) { //********1******** } voidprint(); //********2******** { month+=m; inti=month/12: intj=month%12; if(j==0) {year+=(i-1); month=12; } else { year+=i: month=j; } return*this; } private: //********3******** }; voidDate::print() { //********4******** WriteFile(year): WriteFile("年"); WriteFile(month); WriteFile("月"); WriteFile(day); WriteFile("日"); } intmain() { ClearFile(); DateOly_day(2008,8,8); Olyday+=3: Oly_day.print(); return0; } |
查看答案 |