请打开考生文件夹下的解决方案文件proj1,程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出结果应为: value=63 number=1 注意:只修改每个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。#includeiost reamusing namespace std;class MyClass{ int*p; const int N;public://ERROR ****found**** MyClass(int val):N=1 { p=new int; *p=val; )//ERROR ********found******** ~MyClass() {delete*p;} friend void print(MyClas sobj);};//ERROR ********found********void MyClass::print(MyClassobj){ cout"value=" *(obj.p)endl; cout"number=”obj.Nendl;}int msin(){ Myclass obj(63); print(obj); return 0;}
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明了MiniComplex是一个用于表示复数的类。请编写这个operator+运算符函数,以实现复数的求和运算。两个复数的和是指这样一个复数:其实部等于两个复数的实部之和,其虚部等于两个复数的虚部之和。例如,(23+34i)+(56+35i)等于(79+69i)。 要求: 补充编制的内容写在“//**********333**********”与“//**********666**********”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。//Minicomplex.h#includeiostreamusing namespace std;class MiniComplex//复数类{public: //重载流插入和提取运算符 friend ostreamoperator(ostream osObject, const MiniComplexcomplex) { osObject"("complex.realPart"+"complex.imagPart"i"")"; return osObject; } friend istreamoperator(istreamisObject,MiniComplexcomplex) { char ch; isObjectcomplex.realPartchcomplex.imagPartch; return isObject; } MiniComplex(double real=0,double imag=0);//构造函数 MiniComplex operator+(const MiniComplexotherComplex)const;//重载运算符+private:double realPart;//存储实部变量double imagPart;//存储虚部变量};void writeToFile(char*);//main.cpp#include"MiniComplex.h"MiniComplex::MiniComplex(double real,double imag){realPart=real;imagPart=imag;}MiniComplex MiniComplex::operator+(const MiniComplexother-Complex)const{//**********333**********//**********666**********}int main(){ void writeToFile(char*); MiniComplex num1(23,34),num2(56,35); cout"Initial Value of Num1="num1"\nInitial Value of Num2="num2endl; coutnum1"+"num2"="num1+num2endl;//使用重载的加号运算符 writeToFile(""); return 0; }
请打开考生文件夹下的解决方案文件proj1,该工程含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR ****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: The value is 10 注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。 1 //proj1.cpp 2 #includeiostream 3 using namespace std; 4 class MyClass{ 5 int value; 6 public: 7 //ERROR ****found**** 8 void MyClass(int val):value (val){} 9 int GetValue()const{return value;} 10 void SetValue(int val); 11 }; 12 //ERROR ******found****** 13 inline void SetValue(int val) 14 {value=val;} 15 int main() 16 { 17 MyClass obj(0); 18 obj.SetValue(1 0); 19 //ERROR ******found****** 下列语句功能是输出obj的成员value的值 20 cout"The value is" obj.valueendl; 21 return 0; 22 }
请打开考生文件夹下的解决方案文件proj3,此工程中包含一个源程序文件proj3.cpp,补充编制C++程序proj3.cpp,其功能是读取文本文件in.dat中的全部内容,将文本存放到doc类的对象myDoc中。然后将myDoc中的字符序列反转,并输出到文件out.dat中。文件in.dat的长度不大于1000字节。 要求: 补充编制的内容写在“//********333********”与“//********66666********”两行之间。实现将myDoc中的字符序列反转,并将反转后的序列在屏幕上输出。不得修改程序的其他部分。 注意:程序最后已将结果输出到文件out.dat中,输出函数writeToFile已经给出并且调用。 1 //proj3.cpp 2 #includeiostream 3 #includefstream 4 #includecstring 5 using namespace std; 6 7 class doc 8 { 9 private: 10 char*str;//文本字符串首地址 11 int length;//文本字符个数 12 public: 13 //构造函数,读取文件内容,用于初始化新对象,filename是文件名字符串首地址 14 doc(char*filename); 15 void reverse();//将字符序列反转 16 ~doc(); 17 void writeToFile(char*filename); 18 }; 19 doc::doc(char*filename) 20 { 21 ifstream myFile(filename); 22 int len=1001,tmp; 23 str=new char[len]; 24 length=0 ; 25 while((tmp=myFile.get())!=EOF) 26 { 27 str[length++]=tmp; 28 } 29 str[length]='\0'; 30 myFile.close(); 31 } 32 void doc::reverse(){ 33 //将数组str中的length个字符中的第一个字符与最后一个字符交换,第二个字符与倒数第二个 34 //字符交换…… 35 //***************333*************** 36 37 38 //***************666*************** 39 } 40 41 doc::~doc() 42 { 43 delete[]str; 44 } 45 void doc::writeToFile(char*filename) 46 { 47 ofstream outFile(filename); 48 outFilestr; 49 outFile.ciose(); 50 } 51 void msin() 52 { 53 doc myDoc("in.dat"); 54 myDoc.reverse(); 55 myDoc.writeToFile("out.dat"); 56 }
使用VC6打开考生文件夹下的源程序文件modi3.cpp。此程序的运行结果为: In CDerive's display().b=1 In CDerive2’s display().b=2 其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。 (1)定义函数display()为无值型纯虚函数。请在注释∥********1********之后添加适当的语句。 (2)建立类CDerive的构造函数,请在注释∥********2********之后添加适当的语句。 (3)完成类CDerive2成员函数diaplay0的定义。请在注释∥********3********之后添加适当的语句。 (4)定义类Derivel的对象指针d1,类CDerive2的对象指针d2。其初始化值分别为1和2。请在注释∥********4********之后添加适当的语句。 注意:增加代码,或者修改代码的位置已经用符号表示出来。请不要修改其他的程序代码。#includeiOStreamusing namespace std;Class CBase{public: CBase(int i){b=i;)∥********1********protected: int b; }; class CDerive:public CBase { public: ∥********2******** void di splay() { cout“In CDerive’s display().“”b=”bendl; } }; class CDerive2:public CBase { public: CDerive2(int i):CBaSe(i){} ∥********3********};void func(CBase*obj){ obj一di splay();}void main(){ ∥********4******** func(d1); func(d2);}
请打开考生文件夹下的解决方案文件proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR*********found**********”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为:NUM=0Value=1注意:只修改注释“//ERROR****found****”的下一行语句,不要改动程序中的其他内容。//proj1.cpp#includeusing namespace std;class MyClass{int_i;friend VOid Increment;(MyClassf);public:const int NUN;//ERROR*******found*******NyClass(int i=0){NUM=0;_i=i;}int GetValue( )const{return_i;}};//ERROR*******found*******void Increment( ){f._i++;)int main( ){HyClass obj;//ERROR*******found*******NyClass::TncEement(ohj);coutretuEn0;}