请打开考生文件夹下的解决方案文件proj1,此工程中包含一个源程序文件main.cpp,其中有类Book(“书”)和主函数main的定义。程序中位于每个“//ERROR****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:书名:C++语句程序设计总页数:299已把“C++语言程序设计”翻到第50页已把“C++语言程序设计”翻到第51页已把“C++语言程序设计”翻到第52页已把“C++语言程序设计”翻到第51页已把书合上。当前页:0注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。#includeusing namespace std;class Book{char*title;int num_pages;//页数int cur_page;//当前打开页面的页码,0表示书未打开public://ERROR*******found*******Book(const char*theTitle,int pages)num_pages(pages){title=new char[strlen(theTitle)+1];strcpy(title,theTitle);cout}~Book( ){delete[ ]title;}bool isClosed( )const{returncur_page==0;}//书合上时返回true,否则返回falsebool isOpen( )const{return!isClosed( );}//书打开时返回true,否则返回falseint numOfPages( )const{return num_pages;}//返回书的页数int currentpage( )const{return cur_page;//返回打开页面的页码//ERROR*******found*******void openAtPage(int page_no)const{//把书翻到指定页coutif(page_nonum_pages){coutclose( );}else{cur_page=page_no;cout翻到第"}}void openAtpreVPage( ){openAtPage(cur_page-1);}//把书翻到上一页void openAtNextPage( ){openAtPage(cur_page+1);}//把书翻到下一页void close( ){//把书合上coutif(isCloSed( ))coutelse{//ERROR*******found*******num_pageS=0;cout}cout}};int main( ){Book book("C++语言程序设计",299);book.openAtPage(50);book.openAtNextPage( );book.openAtNextPage( );book.openAtPreVpage( );book.close( );coutreturn0;}
请使用VC6或使用【答题】菜单打开考生文件夹progl下的工程progl,该工程中包含程序文件main.cpp,其中有Salary(“工资”)类和主函数main的定义。程序中位于每个“//ERROR****found****”之后的一行语句行有错误,请加以改正。改正后程序的输出结果应为: 应发合计:3500应扣合计:67.5 实发工资:3432.5 注意:只修改每个“//ERROR****found****”下的那一行,不要改动程序中的其他内容。#includeiostreamusing namespace std;class Salary{public: Salary(const char * id,double the_base,double the_bonus,double the_tax)//ERROR ********found******** :the base(base),the bonus(bonus),the tax(tax) { staff id=new char[strlen(id)+1]; strcpy(staff id,id); }//ERROR********found******** ~Salary(){delete*staff_id;} double getGrosSPay()const {return base+bonus;} //返回应发项合计 double getNetPay()const{return getGrossPay()-tax;)//返回实发工资额private: char*staff id; //职工号 double base; //基本工资 double bonus; //奖金double tax; //代扣个人所得税};int main(){ Salary pay("888888",3000.0,500.0,67.50); tout"应发合计:"pay.get-GrossPay()""; cout"应扣合计:"pay.get-GrossPay()-pay.getNetPay()"";//ERROR**********found********** cout"实发工资:"pay::getNetPay()endl; return 0;}
在关系代数运算中,__________操作会消去关系中的某些列并删去重复的元组。
请打开考生文件夹下的解决方案文件proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR ****found****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: Constructor called. The value is 10 Copy constructor called. The value is lO Destructor called. Destructor called. 注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。//proj1.cpp#includeiostreamusing namespace std;class MyClass{public://ERROR *******found******* Myclass(int i) {value=i;cout"Constructor called."endl;}//ERROR *******found******* Myclass(const Myclass p) { Value=p.value; cout"Copy constructor called."endl: } void Print() {cout"The value is"valueendl ;)//ERROR *******found******* void ~MyClas s() { cout "Destructor called."endl;}private: int value;};int main(){ MyClass obj1 ; obj1.Print(); MyClass obj2(objl); obj2.Print(); return 0 ;}
请打开考生文件夹下的解决方案文件proj3,其中定义了Mystring类,一个用于表示字符串的类。成员函数reverse的功能是将字符串进行“反转”。例如,将字符串ABCDEF“反转”后,得到字符串FEDCBA;将字符串ABCDEFG“反转”后,得到字符串GFEDCBA。请编写成员函数reverse。在main函数中给出了一组测试数据,此时程序运行中应显示: 读取输入文件… ---反转前--- STR1=ABCDEF STR2=ABCDEFG ---反转后--- STR1=FEDCBA STR2=GFEDCBA 要求: 补充编制的内容写在“//*********33*********”与“//*********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; returnR 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"; iEstream infile(inname); if(infile.fail()){ cerr"打开输入文件失败!"; exit(1); } char bur[4096]; infile.getline(bur,4096); Nystring strl("ABCDEF"),str2("ABCDEFG"),str3(buf); cout"---反转前---\n"; cout "STR1 =" str1 endl; cout"STR2="str2endlendl: str1.reverse(); str2.reVerse(); str3.reverse(); cout"---反转后---\n"; cout"STR1 =" str1 endl; cout"STR2 ="str2 endlendl; writeToFile(pathname,str3); return 0 ; }
