函数不能直接引用类中说明的非静态成员,这里指的成员是【 】。
请打开考生文件夹下的解决方案文件proj3,其中声明了ValArray类,该类在内部维护一个动态分配的整型数组。ValArray类的复制构造函数应实现对象的深层复制。请编写ValArray类的复制构造函数。在main函数中给出了一组测试数据,此种情况下程序的输出应该是: ValArray v1={1,2,3,4,5} ValArray v2={2,2,2,2,2} 要求: 补充编制的内容写在“//*******333*******”与“//*******666*******”之间。不要修改程序的其他部分。 注意: 相关文件包括:main.cpp、ValArray.h。 程序最后调用writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件。//ValArray.h#includeiostreamusing namespace std;Class ValArray{ int * v; int size;public: ValArray(const int*p,int n):size(n) { v=new int[size]; for(int i=0;isize;i++) v[i]=p[i]; } ValArray(const ValArrayother); ~ValArray(){delete[]v;} void setElement(int i,int val) { v[i]=val ; } void print(ostreamout)const { out'{'; for(int i=0 ; isize-1;i++) out v[i] ”,”j out v[size-1] '}'; }};void writeToFile(const char *);//main.cpp#include"ValArray.h"ValArray::ValArray (const ValArrayother){//*********333*********//*********666*********}int main(){ const int a[]={1,2,3,4,5); ValArray v1(a,5); ValArray v2(v1); for(int i=0 ; i5;i++) v2.setElement(i,2); cout"ValArray v1="; v1.print(cout); coutend1: cout"ValArray v2="; v2.print(cout); coutendl: writeToFile(" "); return 0;}
请打开考生文件夹下的解决方案文件proj1,其中定义了一个CD类。程序中位于每个//ERROR**********found**********下的语句行有错误,请加以更正,不得修改程序的其他部分。更正后程序的输出应该是: 歌唱祖国30 义勇军进行曲95 注意:只能修改每个//ERROR**********found**********下的那一行,不要改动程序中的其他内容。#includeiostream#includecstringusing namespace std;class CD{ char name[20]; int number;public: void init(char*aa,intbb) { //ERROR**********found********** name=aa; number=bb; } char * getName(){ //ERROR *****found***** return*name; } int getNumber()(returnnumber;} void output(){ //ERROR *****found***** coutname[20]''numberendl; }};void main(){ CD dx,dy; dx.init("歌唱祖国",30); dy.init("义勇军进行曲",3*dx.getNumber()+5); dx.output(); dy.output(); }
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中定义了MyString类,一个用于表示字符串的类。成员函数reverse的功能是将字符串进行“反转”。例如,将字符串ABCDEF“反转”后,得到字符串FEDCBA;将字符串ABCDEFG“反转”后,得到字符串GFEDCBA。请编写成员函数reverse。在main函数中给出了一组测试数据,此时程序运行中应显示: 读取输入文件… ---反转前--- STR1=ABCDEF STR2=ABCDEFG ---反转后--- STR1=FEDCBA STR2=GFEDCBA 要求: 补充编制的内容写在“//***********333***********”与“//***********666***********”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中,输出函数WriteToFile已经编译为obj文件,并且在本程序中调用。//mgsering.h#includeiostream#includecstringusing namespace std;class MyString{public: MyString(const char*s) { str=new char[strlen(S)+1]; strcpy(str,s); } ~MyString(){delete[]str;) void reverse(); friend ostreamoperator(ostreamos,const MyStringmystr) { osmystr.str; return os; }private: char*str;};void writeToFile(char *, constMyString);//main.cpp#include"mystring.h"#includefstreamvoid MyString::reverse(){//***********333***********//***********666***********}int main(){ char inname[128],pathname[80] ; strcpy(pathname,""); sprintf(inname,"in.dat",pathname); cout"读取输入文件…\n\n"; ifstream infile(inname); if(infile.fail()){ cerr"打开输入文件失败!"; exit(1); } char buf[4096]; infile.getline(buf,4096); MyString strl("ABCDEF"),str2("ABCDEFG"),str3(buf); cout"---反转前---"\n"; cout"STR1="str1endl; cout"STR2="str2endlendl; str1.reverse(); str2.reverse(); str3.reverse(); cout"---反转后---\n"; cout"STR1="str1endl; cout"STR2="str2endlendl; writeToFile(pathname,str3); return 0;}