皮皮学,免费搜题
登录
搜题
【简答题】
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程文件proj3。本题创建一个小型字符串类,字符串长度不超过l00。程序文件包括pmj3.h、proj3.cpp、writeToFile.obj。补充完成重载赋值运算符函数,完成深复制功能。 屏幕上输出的正确结果应该是: Hello! Happy new year! 补充编制的内容写在“//**********333**********”与“//**********666**********”两行之间。 不得修改程序的其他部分。 注意: 程序最后调用writeToFil。函数,使用另一组不同的测试数据,将不同的运行结果输出到文件0ut?dat中。 输出函数writeToFile已经编译为obj文件。 //proj3.h include include using namespace std; class MiniString { pubhc: friend。8tream&operator$amp; amp;$gt;(istream&input,MiniString&8)//重载流提取运算符 { char temp[100];//用于输入的临时数组 temp[0]=’/0’://初始为空字符串 input$amp;>amp;$gt;setw(100)$amp;>amp;$gt;temp; int inLen=strlen(temp);//输入字符串长度 if(inLen!=0) } s.1ength=inLen;//赋长度 if(s.sPtr!=0)delete[]s.sPtr;//避免内存泄漏 s.sPtr=Hew char[s.1ength+1]; strcpy(s.sPtr,temp);//如果8不是空指针,则复制内容 } else s.sPtr[0]=’/0’;//如果s是空指针,则为空字符串 retum input; } void modString(const char}string2)//更改字符串内容 { if(strin92 1=0)//如果strin92不是空指针,则复制内容 { if(strlen(strin92)!=length) { length=strlen(strin92); delete[]sPtr; sPtr=new char[1ength+1];//分配内存 } strcpy(sPtr,strin92); } else sPtr[0]=’\0’;//如果string2是空指针,则为空字符串 } MiniString&operator=f const MiniString&otherString); MiniString(corot char*s=''):lengtll((s!=0)?strlen(s):0)//构造函数 { sPtT=0: if(1ength[=0) setString(S); } ~MiniString//析构函数 {delete[]sPtr;} private: int length;//字符串长度 char*sPtr;//指向字符串起始位置 void setString(const char*string2)//辅助函数 { sPtr=Dew char[str|en(string2)+1];//分配内存 if(stnIl92!=0)strcpy(sPtr,string2);//如果string2不是空指针,则复制内容 else slur[0]=/0;//如果string2是空指针,则为空字符串 } }; //pwj3.cpp include include using namespace std; include”proj3.h” MiniString&MiniStrin9::0perator=(const MiniString&otherString) {//重载赋值运算符函数。提示:可以调用辅助函数setString //*************333********** //*************666********** } int main { MiniSuing strl(”Heuo!”),str2; void writeToFile(const char*); sir2=strl;//使用重载的赋值运算符 str2.modString('Happy new year!'); cout$amp;
拍照语音搜题,微信中搜索"皮皮学"使用
参考答案:
参考解析:
知识点:
.
..
皮皮学刷刷变学霸
举一反三
【单选题】CLE齿轮油相当于( )车辆齿轮油。
A.
轻负荷
B.
中负荷
C.
较大负荷
D.
重负荷
【单选题】已知电路中Va=13V,Vb=7V,Vab=( )伏。
A.
A:6
B.
B:-20
C.
C:20
D.
D:-6
【单选题】Choose the correct definition for gravity.
A.
Business that produce a particular type of service
B.
The force that causes sth. to fall to the ground
C.
To start sth.
D.
Behaving in a calm, serious, and formal way, which makes people respect you
【简答题】Complete the following words according to their definitions. The first letter of each word is given for your reference. 1) s_______ v. to almost fall down while you are walking 2) h________ adj. ...
【简答题】vt. produce sth. for the first time 发明
【简答题】produce sth. for the first time
【单选题】下列哪项为区分有粒白细胞和无粒白细胞的主要依据 ( )
A.
细胞形状不同
B.
细胞大小不同
C.
细胞质内有无特殊颗粒
D.
细胞质内有无嗜天青颗粒
E.
细胞核有无分叶
【单选题】已知电路中Va=13V,Vb=7V,Vab=( )伏。
A.
6
B.
-20
C.
20
D.
-6
【简答题】【程序功能】 本程序实现如下功能:定义磁盘 Disk ,在类中定义字段、属性和虚拟方法;由基类 Disk 创建派生类 Floppy 和 Flash , 在派生类中实现方法重载;在程序中实例化类的对象并且调用类的方法。 【操作要求】 新建并保存项目:在 Visual Studio.NET 中,新建一个 Visual C# 控制台应用程序项目,名称设置为 Test2_3 , 位置设置为考生文件夹。 1...
【简答题】Choose the words according to their definitions. homemade、expose、stumble 、sacrifice、yield 1. ___________ v. to almost fall down while you are walking 2. ___________ adj. made at home rather tha...
相关题目: