请打开考生文件夹下的解决方案文件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 ; }
请使用VC6或使用【答题】菜单打开考生文件夹prog3下的工程prog3,其中包含了类TaxCalculator(“个税计算器”)和主函数main的定义。创建“个税计算器”需要接收税率表信息和起征额信息。在main函数中,通过两个数组创建了如下的税率表: 利用这个税率表创建“个税计算器”时,假定起征额为2 000元(即不超过2 000元的所得不征收个人所得税)。请补充完成计算应纳个人所得税额的成员函数getTaxPayable,其中的参数income为月收入。此程序的正确输出结果应为: 月收入为800元时应缴纳个人所得税0元 月收入为1 800元时应缴纳个人所得税0元 月收入为2 800元时应缴纳个人所得税55元 月收入为3 800元时应缴纳个人所得税155元 月收入为4 800元时应缴纳个人所得税295元 月收入为5 800元时应缴纳个人所得税455元 注意:只能在函数getTaxPayable中的“//***********333***********’’和“//***********666***********”之间填入若干语句,不要改动程序中的其他内容。//TaxCalculator.h#include#includeusing namespace std;Class TaxCalculator{public: TaxCalculator(double the_limits[],double the rates[],int the_length,double the_threshold) :lower_limits(new double[the_length]),rates(new double[the_length]), list_len(the length),threshold(the_threshold){ for(int i=0;i1ist_len;i++){ lower_limits[i]=the_limits[i]; rates[i]=the_rates[i]; } } ~TaxCalculator(){delete[]lower _limits;delete []rates ;} double getTaxPayable(double income)const; //返回指定月收入的应纳个人所得税额 void showTaxPayable(double income)const;//显示指定月收入的应纳个人所得税额private:double*lower_limits; //适用收入段下限 double*rates; //适用税率 int list_len;//税率表项数 double threshold; //起征额};void writeToFile,const char*path);//TaxCalcnlator.cpp#include"TaxCalculator.h"double TaxCalculator::getTax-Payable(double income)const{ double taxable=income-thresh-old;//应纳税工资额 double tax_payable=0.0;//应纳个人所得税额 int i=1ist_len-1;//从税率表的最高适用段开始计算 while(i=0){ //***********333*********** //***********666*********** --i; } return tax_payable;}void TaxCalculator::showTax-Payable(double income)const{ cout"月收入为"
请打开考生文件夹下的解决方案文件proj3,其中声明IntSet是一个用于表示正整数集合的类,IntSet的成员函数Intersection的功能是求当前集合与另一个集合的交集。请完成成员函数Intersection。在main函数中给出了一组测试数据,此时程序的输出应该是: 求交集前: 1 2 3 5 8 10 2 8 9 11 30 56 67 求交集后: 1 2 3 5 8 10 2 8 9 11 30 56 67 2 8 要求: 补充编制的内容写在“//********333********”与“//********666********”之间,不得修改程序的其他部分。 注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。//Intset.h#includeiostreamusing namespace std;const int Max=100 ;C1as s IntSet{public: IntSet()//构造一个空集合 { end=-1; } IntSet(int a[],int size)//构造一个包含数组a中size个元素的集合 { if(Size=Max) end=Max-1; e1Se end=size-1; for(int i=0;i=end;i++) element[i]=a[i]; } bool IsMemberOf(int a)//判断a是否为集合中的一个元素 { for(int i=0;i=end;i++) if(element[i]:=a) return true; return falSe; } int GetEnd(){return end;}//返回最后一个元素的下标 int GetElement(int i){return element[i];}//返回下标为i的元素 IntSet Intersection(IntSetset);//求当前集合与集合set的交 void Print()//输出集合中的所有元素 { for(int i=0;i=end;i++) if((i+1)%20==0) coutelement[i]endl; else coutelement[i]''; coutendl; }private: int element[Max]; int end;};void writeToFile(const char*);//main.cpp#include "IntSet.h"IntSet IntSet::Intersection(IntSetSet){ int a[Max],size=0;//********333********//********666******** return IntSet(a,size);}int main(){ int a[]={1,2,3,5,8,10); int b[]={2,8,9,11,30,56,67}; IntSet Set1(a,6),Set2(b,7),Set3; cout"求交集前:"endl; set1.Print(); set2.Print(); set3.Print(); set3=setl.Intersection(set2); coutendl"求交集后:"endl; Set1.Print(); set2.Print(); set3.Print(); writeToFile(" "); return 0 ;}
请打开考生文件夹下的解决方案文件proj1,该工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR****found****”之后的一行语句有错误。请改正这些错误,使程序的输出结果为: 注意:只能修改注释“//ERROR****found****”的下一行语句,不要改动程序中的其他内容。 1 //proj1.cpp 2 #includeiostream 3 using namespace std; 4 5 class Myclass{ 6 public: 7 Myclass(int len) 8 { 9 array=new int[len]; 10 arraySize=len; 11 for(int i=0;iarraySize;i++) 12 array[i]=i+1; 13 } 14 15 ~Myclass() 16 { 17 //ERROR ********found******** 18 delete array[i]; 19 } 20 21 void Print()const 22 { 23 for(int i=0 ; iarraySize ; i++) 24 //ERROR ********found******** 25 cinarray[i]"; 26 27 coutendl ; 28 } 29 private: 30 int*array: 3l int arraySize; 32 }; 33 int main() 34 { 35 //ERROR ********found******** 36 MyClass obj; 37 obj.Print(); 38 return 0 ; 39 }
请打开考生文件夹下的解决方案文件proj2,此工程包含一个源程序文件proj2.cpp。其中定义了Score类。 Score是一个用于管理考试成绩的类。其中,数据成员_s指向存储成绩的数组,_n表示成绩的个数;成员函数Sort使用冒泡排序法将全部成绩按升序进行排列。 请在程序中的横线处填写适当的代码,然后删除横线,以实现Score类的成员函数Sort。 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 1 //proj2.cpp 2 #includeiosttream 3 #includecstdlib 4 #includectime 5 using namespace std; 6 class Score { 7 public: 8 Score(double * s, int n) : s(s), n(n) {} 9 double GetScore(int i)const 10 {return s[i];} 11 void Sort(); 12 private: 13 double*s; 14 int;n ; 15 }; 16 void Score::Sort() 17 { 18 //********found******** 19 for(int i=0 ; i_n-1;____________) 20 //********found******** 21 for(int j=___________;ji;j--) 22 if ( s[j] s[j-1] ) 23 { //交换 s[j]和 s[j-1] 24 double t=s[j]; 25 //********found******** 26 __________; 27 //********found******** 28 ____________; 29 } 30 } 31 32 int main() 33 { 34 const int NUH=10; 35 double s[NUM]; 36 srand(time(0)); 37 for(int i=0 ; iNUN; i++) 38 s[i]=double(rand())/RAND_MAX * 100 ; 39 score ss(s,NUM); 40 ss.Sort(); 41 for(int j=0;jNUM;j++) 42 coutss.GetScore(j) endl; 43 return 0; 44 }
请打开考生文件夹下的解决方案文件proj1,此工程中含有一个源程序文件proj1.cpp。其中位于每个注释“//ERROR ****bund****”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: This object is no.1 注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。//proj1.cpp#include iostreamusing namespace std;class MyClass{public: HyClass():count(0){cout"This object is";)//ERROR ****found**** Void Inc()const {cout"no. "++countendl ;}private://ERROR *******found******* int count=0;};int main(){ Myclass*obj=new Myclass;//ERROR *******found******* *obj.Inc(); return 0 ;}
在10S中提供格式控制标志位中,转换为十六进制形式的标志位是( )。
请打开考生文件夹下的解决方案文件proj2,该工程中含有一个源程序文件proj2.cpp,请将堆栈类的定义补充完整。使程序的输出结果为: The element of stack are:4 3 2 1 注意:请勿修改主函数main和其他函数中的任何内容,只在横线处编写适当代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 t //proj2.cpp 2 #includeiostream 3 using namespace std; 4 const int size=5 ; 5 class Stack; 6 class Item 7 { 8 public: 9 //********found******** 10 Item(const int val):___________ {}//构造函数对item进行初始化 11 private: 12 int item; 13 Item*next; 14 friend class Stack; 15 }; 16 class Stack 17 { 18 public: 19 Stack():top(NULL){} 20 ~Stack(); 21 int Pop(); 22 void Push(const int ); 23i private: 24 Item*top; 25 }; 26 Stack::~Stack() 27 { 28 Item*p=top,*q; 29 while(p!=NULL) 30 { 31 q=p一next ; 32 //********found******** 33 _____________; //释放p所指向的节点 34 p=q; 35 } 36 } 37 int Stack::Pop() 38 { 39 Item*temp ; 40 int ret; 41 //**********found********** 42 ___________; //使temp指向栈顶节点 43 ret=top-item; 44 top=top-next; 45 delete temp; 46 return ret; 47 } 48 void Stack::Push(const intval) 49 { 50 Item*temp=new Item(val); 51 //**********found********** 52 } //使新节点的next指针指向栈顶数据 53 top=temp; 54 ) 55 int main() 56 { 57 Stack s; 58 for(int i=1;iSize;i++) 59 s.Push(i); 60 cout"The element of stack are:"; 61 for(i=1;iSize;i++) 62 couts.Pop()'\t'; 63 return 0; 64 }
请打开考生文件夹下的解决方案文件proj2,该工程中包含一个程序文件main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTfiangle(“三角形”)的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序的正确输出结果应为: 20 10 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也小要删除或移动“//****found****”。#1ncludeiostreamusing namespace std;class CPolygon{public://*********found*********_____________//纯虚函数area声明 void printarea(void)//*********found*********{cout___________endl;}};class CRectangle:public CPolygon{ int width; //长方形宽 int height; //长方形高public: CRectangle(int w,int h):width(w),height(h){} int area (void){return(width*height);)};class CTriangle:public CPolygon{ int length; //三角形一边长 int height; //该边上的高public: CTriangle(int 1,int h):length(1),height(h){)//*********found********* int area(void){return( )/2;}};int main(){ CRectangle rect(4,5); CTriangle trgl(4,5);//*********found*********___________*ppoly1,*ppoly2 ;ppoly1=rect;ppoly2=trgl;ppoly1-printarea();ppoly2-printarea(); return 0;}