第1题
第2题
第3题
第4题
第5题
第6题
第7题
清使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,此工程中包含了类Pets(“宠物”) 和主函数main的定义。程序中位于每个“//ERROR****found ****”之后的一行语句有错误,请加以改 正。改正后程序的输出结果应为: Name:sonny Type:dog Name:John Type:dog Name:Danny Typc:cat Name:John Type:dog 注意:只修改每个“//ERROR ****found ****”下的那一行,不要改动程序中的其他内容。 include<iostream> using namespace sm; enum Pets_type{d09,cat,bird,fish}; class Pets{ private: char *name; Pets_type type; public: Pets(const char *name=”sonny”,Pets_type type=dog); Pets&operator=(const Pets&s); ~Pets; void showeonst;}; Pets::Pets(eonst char$naIne,Pets_type type) //构造函数 { This ->name=new char[strlen(name)+1]; strcpy(this一>name,name); //ERROR *********found********* type=type; }{ Pets::~Pets//析构函数,释放name所指向的字符串 { //ERROR *********found********* name=’/0‘; } Pets&Pets::0perator=(const Pets&s){ if(&s==this)//确保不要向自身赋值 return *this; delete[]name; name=new char[strlen(S.name)+1];//ERROR *********found********* strcpy(this一>nmne,name); type=S.type: return *this;} void Pets::showconst cout<<“Name:”<<name<<”Type:”: Pets mypetl,mypet2(’’John”,dog);
第8题
第9题
请使用VC6或使用【答题】菜单打开考生文件夹prosS下的工程pr093,其中包含了类TaxCaleulator(“个税计算器”)和主函数main的定义。创建“个税计算器”需要接收税率表信息和起征额信息。在main函数中,通过两个数组创建了如下的税率表:利用这个税率表创建“个税计算器”时,假定起征额为2 000元(即不超过2 000元的所得不征收个人所得税)。请补充完成计算应纳个人所得税额的成员函数getTaxPayable,其中的参数income为月收入。此程序的正确输出结果应为: 月收入为800元时应缴纳个人所得税0元 月收入为l 800元时应缴纳个人所得税0元月收入为2 800元时应缴纳个人所得税 55元 月收入为3 800元时应缴纳个人所得税l55元 月收入为4 800元时应缴纳个人所得税295元月收入为5 800元时应缴纳个人所得税455元 注意:只能在函数9etTaxPayable中的“//**********333**********”和“//**********666**********”之间 填人若干语句,不要改动程序中的其他内容。 //Tax Calculator.h include<iostream> include<iomanip> using flamespace 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;i<list—len;i++){ lower_limits[i]=the_limits[i]; rates[i]=the_rates[i]; } f —TaxCalculator{delete[]lower_limits;delete[]rates;} double getTaxPayable(double income)eonst;//返回指定月收入的应纳个人所得税额 void showTaxPayable(double income)const;//显示指定月收入的应纳个人所得税额 private: double$lower—limits;//适用收入段下限 double *rates; //适用税率 int list—len;//税率表项数 double threshold; //起征额 }; void writeToFile(consl char * path); //TaxCalcnlator.cpp ‘include”TaxCalculator.h” double TaxCalculator::getTaxPayable(double income)const{ double taxable=income—threshold; //应纳税工资额 double tax_payable=0.0; //应纳个人所得税额 int i=list_len-1; //从税率表的最高适用段开始计算 while(i>=0){ //**********333********** //**********666********** --i; } return tax_payable; } void TaxCalculator::showTaxPayable(double income)const{ cout<<”月收入为”<<setw(6)<<income<<”元时应缴纳个人所得税” <<setw(4)<<getTaxPayable(income)<<”元”<<endl; } //main.cpp include”TaxCalculator.h” int main{ double limits[]={0.0,500.0,2000.0,5000.0,20000.0,40000.0,60000.0,80000。0,100000.0}; double rates[]={0.05,0.1,0.15,0.2,0.25,0.3,O.35,0.4,0.45}; TaxCaleulator calc(1imits,rates,9,2000.0); calc.showTaxPayable(800.0); calc.showTaLPayable(1800.0); cale.showTaxPayable(2800.0); calc.showTaxPayable(3800.0); calc.showTaxPayable(4800.0); eaie.showTaxPayable(5800.0); writeToFile(””); return 0; }
第10题
80
150
100
1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
include<iostream.h>
class vehicle
{
private:
int MaxSpeed;
int Weight;
public:
//*************found************
vehicle(int maxspeed,int weight):——
~vehicle{};
int getMaxSpeed{return MaxSpeed;}
int getWeight{retum Weight;}
};
//****************found************
class bicycle:——public vehicle
{
private:
int Height;
public:
bicycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),Height(height){}
int getHeight{retum Height;};
};
//*******************found**************
class motorcar:——public vehicle
{
private:
int SeatNum;
public:
motorcar(int maxspeed。int weight,int seatnum):vehicle(maxspeed,weight),SeatNum(seatnum){}
int getSeatNum{return SeatNum;};
};
//*****************found***************
class motorcycle:——
{
public:
motorcycle(int maxspeed,int weight,int height):vehicle(maxspeed,weight),bicycle(maxspeed,weight,
height),motorcar(maxspeed,weight,1){}
};
void main
{
motorcycle a(80,150,100);
cout<<a.getMaxSpeed<<endl;
cout<<a.getWeight<<endl;
cout<<a.getHeight<<endl;
cout<<a.getSeatNum<<endl;
}
第11题
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!