问答题综合应用题
使用VC6打开考生文件夹下的工程kt13_3。此工程包含一个kt13_3.cpp,其中定义了类Person,但该类的定义并不完整。请按要求完成下列操作,将程序补充完整。
(1)定义类Person的私有数据成员forename、surname和money,forename和surname都是char型的指针数据,money是double型的数据。请在注释“//**1**”之后添加适当的语句。
(2)完成类Person的带三个参数的构造函数Person(char*f,char*s,doublem),分别为forename和surname申请新的空间来存储参数f和s指针指向的内容,注意空间的大小,最后把参数m的值赋给money,请在注释“//**2**”之后添加适当的语句。
(3)完成类Person的析构函数的定义,把forename和surname指向的空间释放,请在注释“//**3**”之后添加适当的语句。
(4)完成类Person的成员函数display的定义,使其以格式"fornamesurnamehasmoney"的形式输出内容,请在注释“//**4**”之后添加适当的语句。
注意:除在指定位置添加语句之外,请不要改动程序中的其他内容。
输出结果如下:
RichardBerkhas1000.56
Pressanykeytocontinue
源程序文件kt13_3.cpp清单如下:
#include
#include
classPerson
{ private:
//**1**
doublemoney;
public:
Person(char*f,char*s,doublem);
~Person();
voiddisplay(); };
Person::Person(char*f,char*s,doublem)
{ //**2**
strcpy(forename,f);
surname=newchar[strlen(s)+1];
strcpy(surname,s);
money=m; }
Person::~Person()
{ //**3** }
voidPerson::display()
{ //**4** }
voidmain()
{ Personp("Richard","Berk",1000.56);
p.display(); }
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错,请改正错误,使得程序正确执行,并且输出以下语句: TestClass1:0 TestClass2 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//******error******的下面。#include<iostream.h>struct TestClass1{ TestClass1(int i=0) { m_i=i; } void print() { cout<<"TestClass1:"<<m_i<<end1; }; int m_i;};Class TestClass2{public: TestClasS2() { } void print() { cout<<”TestClass2”<<end1; }; //********error********private: ~TestClass2() { }};int main(){ //********error******** TestClass1 obj1(); //********error******** TestClass2 obj 2(); obj1.print(); obj2.print(); return 0;}
问答题使用VC6打开考生文件夹下的源程序文件modi 1.cpp,该程序运行时有错误,请补充程序中的丢失部分,使得程序运行。可以在修改处增加或者删除一条语句。本程序完成以下功能: (1)获得输入的两个数字x1,x2(例如x1=4,x2=2); (2)输出两个中较小的一个(例如输出2); (3)计算x1/x2如果X2等于0,返回-1(输出结果2); (4)输出x1+x2的结果(输出结果6): (5)输出x1+1的结果(输出结果5); (6)输出x2-1的结果(输出结果1)。注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在∥*******error*******的下面。#inClude<i0Stream.h>Void main(){ int x1; int x2; int X3; cout<<“please input two number:”<<end1; Cin>>x1>>x2; ∥*******error******* x3=(x1>x2)?x1:x2; cout<<“Min number is :”<<x3<<end1;∥计算x1/x2如果x2等于0,返回一1 ∥*******error******* x3=(x2)?x1\x2:一1; cout<<“x1/x2=”<<x3<<end1; ∥*******error******* x3=(一一x1)+(x2++); cout<<“x1+x2= “<<x3<<end1; cout<<“x1+1= “<<x1<<end1; cout<<“x2—1= “<<x2<<end1; return;}
问答题请使用VC6或使用[答题]菜单打开
proj1下的工程proj1,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
There is a white dog named Hoho.
There is a black dog named Haha.
There is a motley dog named Hihi.
注意:只修改每个//ERROR ****found****下的那一行,不要改动程序中的其他内容。
#include<iostream>
using namespace std;
//狗的颜色:黑、白、黄、褐、花、其他
enum DOGCOLOR {BLACK, WHITE, YELLOW, BROWN, PIEBALD, OTHER};
class Dog {//狗类
DOGCOLOR color;
char name[20];
static int count;
public:
Dog(char name[], DOGCOLOR color) {
strcpy(this->name, name);
//ERROR **********found**********
strcpy(this->color, color);
}
DOGCOLOR getColor()const {return color;}
//ERROR **********found**********
const char*getName()const {return*name;}
const char*getColorString()const {
switch(color) {
case BLACK: return "black":
case WHITE: return "white":
case YELLOW: return "yellow":
case BROWN: return "brown":
case PIEBALD: return "piebald":
}
return "motley";
}
void show()const {
cout<<"There is a"<<getColorString()<<"dog named"<<name<<"."<<endl:
}
};
int main() {
//ERROR **********found**********
Dog dog1("Hoho", WHITE), dog2("Haha", BLACK); dog3("Hihi", OTHER);
dog1. show();
dog2. show();
dog3. show();
return 0;
}
问答题使用VC6打开考生文件夹下的源程序文件modi3.cpp,阅读下列程序说明和代码,功能如下:
从屏幕输入数字,然后由大到小插入指定的链中。当输入0时,表示输出的数据已经输入完成,然后把数据打印到屏幕,然后释放内存。
其中定义的类并不完整,按要求完成下列操作,将类的定义补充完整。
(1)在父节点的Next中保存新插入的节点的指针,请在注释∥*******1********后添加适当的语句。
(2)把pNext的子节点赋给pNext本身,请在注释∥********2********后添加适当的语句。
(3)判定P的子节点不为空,如果不为空,则打stp其中的数据到屏幕, 请在注释
∥********3********后添加适当的语句。
(4)用temp1保存动态申请内存节点的链表头,请在注释∥********4********后添加适当的语句。
注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。
#i12Clude
Class TeStClass
{
public:
TestClass(int data=0)
{
this->data=data;
this一>next=NULL;
},
int data;
TestClass* mext;
},
void Insert(TestClass*P,int data)
{
TestClass*temp=new TestClass(data);
TeStClass*pparent=p;
TeStClass*pNext=p一>next;
while(pNext)
{
if(data>pNext一>data)
{
∥********1********
temp一>next=pNext;
return;
}
E1se
f
pParent=pNext;
∥********2********
}
}
if(pNext=NULL)
{
pParent一>next=temp;
retuen;
}
}
void printf(TestClass*P)
{
∥********3********
while()
{
coutnext一>datanext;
}
coutnext;
delete temp1;
temp1=temp2;
}
}
Void main()
{
int i=0;
TestClass head;
dp
{
int data;
cout>data;
if(data=0)break;
Insert(&head,data);
}while(1);
printf(&head);
Delete(&head);
return;
}
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程文件pmj3。本题创建一个小型字符串类,字符串长度不超过100。程序文件包括proj3.h、proj3.cpp、writeToFile.obj。补充完成重载赋值运算符函数,完成深复制功能。 屏幕上输出的正确结果应该是: Hello! Happy new year! 要求: 补充编制的内容写在“//**********333**********”与“//**********666**********”两行之间。不得修改程序的其他部分。 注意: 程序最后调用writeToFile函数,使用另一组不同的测试数据,将不同的运行结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件。 //proj3.h #include<iostream> #include<iomanip> using namespace std; class MiniString { public: friend ostream&operator<<(ostream&output,const MiniString&s)//重载流插入运算符 { output<<s.sPtr;return output; } friend istream&operator>>(istream&input,MiniString&s)//重载流提取运算符 { char temp[100];//用于输入的临时数组 temp[0]='\0';//初始为空字符串 input>>setw(100)>>temp; int inLen=strlen(temp);//输入字符串长度 if(inLen!=0) { s.1ength=inLen;//赋长度 if(s.sptr!=0)delete[]s.sPtr;//避免内存泄漏 s.sPtr=new char[s.length+1]; strcpy(s.sPtr,temp);//如果s不是空指针,则复制内容 } else s.sPtr[0]='\0';//如果s是空指针,则为空字符串 return input; } void modString(const char*string2)//更改字符串内容 { if(string2 !=0)//如果string2不是空指针,则复制内容 { if(strlen(string2)!=length) { length=strlen(string2); delete[]sPtr; sPtr=new char[length+1]; //分配内存 } strcpy(sPtr,string2); } else sPtr[0]='\0';//如果string2是空指针,则为空字符串 } MiniString&operator=(const MiniString&otherString); MiniString(const char*s=||):length((s!=0)?strlen(s):0)//构造函数 { sPtr=0; if(1ength!=0) setString(s); } ~MiniString()//析构函数 {delete[]sPtr;} private: int length;//字符串长度 char*sPtr;//指向字符串起始位置 void setString(const char*string2)//辅助函数 { sPtr=new char[strlen(string2)+1]; //分配内存 if(string2!=0)strepy(sPtr,string2);//如果string2不是空指针,则复制内容 else sPtr[0]='\0';//如果string2是空指针,则为空字符申 }};//proj3.cpp#include<iostream>#include<iomanip>using namespace std;#include"proj3.h"MiniString&MiniString::operator=(const MiniString&otherString){//重载赋值运算符函数。提示:可以调用辅助函数setString//**********333**********//**********666**********}int main(){ MiniString strl("Hello!"),str2; void writeToFile(const char*); str2=strl;//使用重载的赋值运算符 str2.modString("Happy new year!"); cout<<strl<<'\n': cout<<str2<<'\n'; writeToFile(""); return 0;}
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,补充空出的代码。sum(intn)计算所有n的因子之和(不包括1和自身)。
注意:不能修改程序的其他部分,只能补充sum()函数。
#inClude
int sum(int n)
{
}
Void main()
{
cout<
问答题使用VC6打开考生文件夹proj2下的工程proj2,其中有两个类:一是销售类(sale),用于表示按照一件商品的基本价格进行销售;另一个是打折销售类(DiscountSale),用于表示在基本价格基础上按一个折扣比例进行销售。DiscountSale类继承了sale类。类的主要数据成员的含义和成员函数的功能要求在程序注释中有说明。请在程序中的横线处填写适当的代码,然后删除横线,完成程序的功能。此程序的正确输出结果应为: Discount item is cheaper. Saving is 0.1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。#include<iostream> using namespace std;class Sale{public: Sale();//默认构造函数,将price初始化为0 Sale(double the_price);//构造函数,用the_price初始化price virtual double bill()const;//返回当前商品的价格(基本价) double savings(const Sale&other)const;//返回参数other所引用的对象比当前对象便宜的差价protected: double price;//商品的基本价格(不打折的价格)};Sale::Sale():price(0){}Sale::Sale(double the_price):price(the_price){}double Sale::bill()const{ return price;}double Sale::savings(const Sale&other)const{ //**********found********** ________;//返回当前对象价格比other贵多少的差价}class DiscountSale:public Sale//打折销售类继承销售类{public: DiscountSale();//默认构造函数,将discount初始化为0 DiscountSale(double the_price,double the_discount);//构造函数,the_price是基本价格;the_discount是折扣百分比 virtual doublle bill()const;//返回本商品销售价格(即打折以后的实际售价,覆盖了基类的bill函数)protected: double discount;//折扣百分比。例如降价至原价的70%,此成员值应为70}:DiscountSale::DiscountSale():discount(0){}DiscountSale::DiscountSale(double the_price,double the_discount) :Sale(the_price),discount(the_discount){}double DiscountSale::bill()const{ double fraction=discount/100; //**********found********** ________;//返回本对象打折以后的实际售价}bool operator<(const Sale&first,const Sale&second){ //**********found********** ________;//判断是否first价格低于second价格}int main(){ Sale simple(10.00); DiscountSale discount(11.00,90); if(discount<simple) { cout<<"Discount item is cheaper.\n": //**********found********** //这里输出购买discount比购买simple节省多少钱 cout<<"Saving is"<<________<<endl; } else cout<<"Discount item is not cheaper.\n"; return 0;}
问答题使用VC6打开下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序。该程序从键盘读入整数,并按从大到小的顺序输出输入整数中互不相等的那些整数。程序一边读入整数,一边构造一个以大到小顺序链接的链表,直至输入0时结束。然后顺序输出链表上各表元的整数值。主函数每读入一个整数,就调用函数fun(),函数fun()将还未出现在链表上的整数按从大到小的顺序插入到链表中。为了插入方便,链表在表首有一个辅助表元。注意:不能修改程序的其他部分,只能修改fun()函数。#include<iostream>classNODE{public:intdata;NODE*next;};voidfun(NODE*list,intx){}voidmain(){intx;NODE*head,*p;/*首先建立只有辅助表元的空链表*/head=newNODE;head->next=NULL;std::cout"Enterintegers,endwith0"std::endl;while(1){std::cinx;if(x==0)break;fun(head,x);}for(p=head->next;p!=NULL;p=p->next)std::cout"";std::coutstd::endl;do{p=head->next;deletehead;head=p;}while(p);}
问答题请使用VC6或使用【答题】菜单打开考生目录proj3下的工程文件proj3,其中定义了用于表示特定数制的数的模板类Number和表示一天中的时间的类TimeOfDay;程序应当显示: 01:02:03.004 06:04:06.021 但程序中有缺失部分,请按照以下的提示,把缺失部分补充完整: (1)在“//**1** ****found****”的下方是一个定义数据成员Seconds的语句,seconds用来表示“秒”。 (2)在“//**2** ****found****”的下方是函数advanceSeconds中的一个语句,它使时间前进k秒。 (3)在“//**3** ****found****”的下方是函数advance中的一个语句,它确定增加k后n的当前值和进位,并返回进位。例如,若n的当前值是表示时间的55分,增加10分钟后当前值即变为5分,进位为1(即1小时)。 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“****found****”。填写的内容必须在一行中完成,否则评分将产生错误。//proj3.cpp#include<iostream>#include<iomanip>using namespace std;template<int base> //数制为base的数class Number{ int n; //存放数的当前值public: Number(int i):n(i){) //i必须小于base int advance(int k);//当前值增加k个单位 int value()const{return n;)//返回数的当前值},class TimeOfDay{public: Number<24>hours; //小时(0—23) Number<60>minutes; //分(0—59)//**1** **********found**********_______;//秒(0—59)Number<1000>milliseconds;//毫秒(0—999) TimeOfDay(int h=0,int m=0,int S=0,int milli=0) :hours(h),minutes(m),seconds(S),milliseconds(milli){) void advanceMilliS(int k){ad-vanceSeconds { milliseconds.advance(k));) //前进k毫秒void advanceSeconds(int k) //前进k秒{//**2** ********** found********** ________; } Void advanceMinuteS(int k){advanceHour(minutes.advance(k));}//前进k分钟 void advanceH0ur(int k)f hours.advance(k);) //前进k小时 void show()const{//按“小时:分:秒.毫秒”的格式显示时间 int C=cout.fill(’0’);//将填充字符设置为'0 cout<<setw(2)<<hours.value()<<’:’//显示小时 <<setw(2)<<minutes.value()<<’:’ //显示分 <<setw(2)<<seconds.value()<<’.'//显示秒 <<setw(3)<<milliseconds.value(); //显示毫秒 tout.fill(c); //恢复原来的填充字符 }};template<int base>int Number<base>::advance(int k){ n+=k; //增加k个单位 int S=0; //s用来累计进位 //**3** **********found**********while(n>=base)__________//n到达或超过base即进位 return s;//返回进位 } int main() { TimeOfDay time(1,2,3,4);//初始时间:1小时2分3秒4毫秒 time.show(); //显示时间 time.advanceHour(5); //前进5小时 time.advanceSeconds(122);//前进122秒(2分零2秒) time.advanceMillis(1017);//前进1017毫秒(1秒零17毫秒) cout<<endl; time.show(); //显示时间 cout<<endl; return 0; }
问答题使用VC6打开考生文件夹下的源程序文件modi2.cpp。阅读下列函数说明和代码,完成空出部分程序。函数fun(int n)的功能是在n行n列的矩阵中,每行都有最大的数,本程序求这n个最大数中的最小一个,并作为参数返回。
注意:不能修改程序的其他部分,只能修改fun()函数。
#include
#define N 100
int a[N][N];
int fun(int n)
{
}
void main()
{
int n ;
cout>n;
for(int i=0;i>a[i][j];
}
cout<<“The min of max numbers is”<
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错,请改正其中的错误,使得程序正常运行,并使程序输出的结果为:
1
1
2
1
注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在∥********error********的下面。
#include
C1ass TestClasS
{
∥********error********
∥********error********
const int j;
public:
TestClasS()
{
∥********error********
statiC int i=0 ;
cout<<++i<
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。DataList的重载运算符函数operator+,其功能是求当前数据表与另一个相同长度的数据表之和;即它返回一个数据表,其每个元素等于相应两个数据表对应元素之和。请编写这个operator+函数。程序的正确输出应该是:两个数据表:1,2,3,4,5,63,4,5,6,7,8两个数据表之和:4,6,8,20,12,14要求:补充编制的内容写在“//**********333**********”与“//**********666**********”之间,不得修改程序的其他部分。注意:程序最后将结果输出到文件out.dat中。输出函数writeToFile已经编译为obj文件,并且在本程序中调用。//DataList.h#include<iostream>using namespace std;class DataList{//数据表类int len;double*d;public:DataList(int len,double data[]=NULL);DataList(DataList &data);int length()const{return len;}double getElement(int i)const{return d[i];}DataList operator+(const DataList& list)const;//两个数据表求和void show()const;//显示数据表};void writeToFile(char*,const DataList&);//main.cpp#include"DataList.h"DataList::DataList(int len,double data[]):len(len){d=new double[len];for(int i=0;i<len;i++)d[i]=(data==NULL?0.0:data[i]);}DataList::DataList(DataList&data):len(data.len){d=new double[len];for(int i=0;i<len;i++)d[i]=data.d[i];}DataList DataList::operator+(const DataList&list)const{//两个数据表求和double*dd=new double[list.length()];//**********333**********//**********666**********return DataList(list.length(),dd);}void DataList::show()const{//显示数据表for(int i=0;i<len-1;i++)cout<<d[i]<<",";cout<<d[len-1]<<endl;}int main(){double s1[]={1,2,3,4,5,6};double s2[]={3,4,5,6,7,8};DataList list1(6,s1),list2(6,s2);//定义两个数据表对象cout<<"两个数据表:"<<endl:list1.show();list2.show();cout<<endl<<"两个数据表之和."<<end!;(list1+list2).show();writeToFile(" ",list1+list2);return0;}
问答题使用VC6打开考生文件夹下的源程序文件modi1.cpp,该程序运行时有错误,请改正程序中的错误。本程序要求实现的功能为:从键盘输入一个字符串,并将结果保存到文件modi1.txt中。 注意:不要改动main函数,不能增行或删行,也不能更改程序的结构,错误的语句在//********error********的下面。#include<iostream>#include<fstream>//********error********using std;void WriteFile(char*s){ ofstream out1; //********error******** out1.open("modi1.txt",binary | app); for(int i=0;s[i]!=0;i++) { //********error******** out1.puts(s[i]); } out1.Close();}Void ClearFile(){ ofstream out1; out1.open("modi1.txt"); out1.Close();}int main(){ char s[1024]; ClearFile(); cout<<"please input a string:"<<endl; cin.getline(s,1024); WriteFile(s); return 0;}
问答题使用VC6打开下的源程序文件modi3.cpp,其中定义了用于表示坐标的类TestClass1,但类TestClass1的定义并不完整,按要求完成下列操作,将类的定义补充完整。(1)声明TestClass2类为TestClass1类的友元类,请在注释//********1********后添加适当的语句。(2)完成类的构造函数,分别对成员变量赋值,请在注释//********2********后添加适当的语句。(3)完成类的构造函数,分别对成员变量赋值,请在注释//********3********后添加适当的语句。(4)完成计算平面上两点之间的距离函数Distance,计算的方法如下:X坐标之差的平方与Y坐标之差的平方之和的开方。请在注释//********4********后添加适当的语句。注意:仅在函数指定位置添加语句,请勿改动主函数main与其他函数中的任何内容。#include<iostream>#include<cmath>usingnamespacestd;classTestClass1{//********1********public://********2********{X=a;Y=b;}//********3********{X=a;Y=0;}voidprint(){}private:floatX,Y;};classTestClass2{public:floatDistance(TestClass1};floatTestClass2::Distance(TestClass1//********4********returnresult;}intmain(){TestClass1p(10,10),q(20);TestClass2d;d.Distance(p,q);return0;}
问答题请使用VC6或使用【答题】菜单打开考生文件夹proj1下的工程pwj1,此工程中含有—个源程序文件projl.cpp。其中位于每个注释“//ERROR**********found**********”之后的一行语句存在错误。请改正这些错误,使程序的输出结果为: NUM=0 Value=1 注意:只修改注释“//ERROR ****found****”的下一行语句,不要改动程序中的其他内容。//proj1.cpp#include<iostream>using namespace std;class MyClass{ int i; friend void Increment(MyClas S&f);public: const int NUM;//ERROR********found******** MyClass(int i=0){NUM=0; i=i; } int GetValue()const{return i;)};//ERROR********found********VOid Increment(){f.i++;)int main(){ MyClass obj;//ERROR********found******** MyClass::Increment(obj); cout<<”NUM=”<<obj.NUM<<endl <<”Value:”<<obj.GetValue()<<end1 return 0;}
问答题请使用VC6或使用[答题]菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.cpp,其中有类AutoMobile(“汽车”)及其派生类Car(“小轿车”)、Truck(“卡车”)的定义,还有主函数main的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:
车牌号:冀ABCl234 品牌:ForLand 类别:卡车 当前档位:0 最大载重量:12
车牌号:冀ABC1234 品牌:ForLand 类别:卡车 当前档位:2 最大载重量:12
车牌号:沪XYZ5678 品牌:QQ 类别:小轿车 当前档位:0 座位数:5
车牌号:沪XYZ5678 品牌:QQ 类别:小轿车 当前档位:-1 座位数:5
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
class AutoMobile{ //"汽车"类
char * brand; //汽车品牌
char * number; //车牌号
int speed; //档位: 1、2、3、4、5, 空档: 0,倒档: -1
public:
AutoMobile (const char * the_brand, const char * the_number): speed(0) {
brand = new char [strlen (the_brand) +1];
//********** found**********
______;
//********** found**********
______;
strcpy (number, the_number);
}
~AutoMobile ( ) {delete[ ] brand;delete[] number; }
const char * theBrand {{U}} {{/U}}const { reurn brand; } //返回品牌名称
const char * theNumber{{U}} {{/U}}const{ return number; } //返回车牌号
int currentSpeed {{U}} {{/U}}const { returnspeed; } //返回当前档位
void changeGearTo (int the speed)
if(speed>= -1
}
virtual const char * category {{U}} {{/U}}
const =0; //类别: 卡车、小轿车等
virtual void show {{U}} {{/U}}const {
cout << "车牌号" << theNumber {{U}} {{/U}}
//**********found**********
<< "品牌:" <<
<< "类别:" << category {{U}} {{/U}}
<<"当前档位" << currentSpeed {{U}} {{/U}};
}
};
class Car: public AutoMobile {
int seats; //座位数
public:
Car (const char * the_brand, constchar * the_number, int the seats):AutoMobile (the_brand, the _number),seats (the seats) {}
int numberOfSeat {{U}} {{/U}}const { returnseats; }
const char * category{{U}} {{/U}}const{ return "小轿车"; } //返回汽车类别
void show{{U}} {{/U}}const{
AutoMobile::show{{U}} {{/U}};
cout <<"座位数" <<numberOfSeat{{U}} {{/U}}<<endl;
}
};
class Truck: public AutoMobile { //int max_load; //最大载重量
public:
Truck (const char * the _brand,const char * the number, int the_max_load): AutoMobile (the_brand, the_number), max_load (the_max_load) { }
int maxLoad {{U}} {{/U}}const { return max_load; } //返回最大载重量
//********** found**********
const char * category{{U}} {{/U}}______//返回汽车类别
void show{{U}} {{/U}}const{
AutoMobile::show{{U}} {{/U}};
cout <<"最大载重量:" <<maxmoad {{U}} {{/U}}<<endl;
}
};
int main{{U}} {{/U}}{
Truck truck ( "ForLand", "ABC1234", 12);
truck.show{{U}} {{/U}};
truck.changeGearTo(2);
truck.show{{U}} {{/U}};
Car car("QQ", "沪XYZ5678", 5);
car.show{{U}} {{/U}};
car.changeGearTo(-1);
car.show{{U}} {{/U}};
cout<<endl;
return 0;
}
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,但该程序运行时有错,请改正程序中的错误,使程序输出的结果为:
This is a greart!
Hello
Hello
注意:错误的语句在∥********error********的下面,修改该语句即可。
#include
class CMyClass
{
public:
void displayl()
(
cout<<“ThiS iS great!”
<
问答题使用VC6打开考生文件夹下的源程序文件modil.cpp,该程序运行时有错,请改正其中的错误,使程序正常运行,并使程序输出的结果为:
Max is 7
提示:max()函数实现找出两个数中的最大值,并作为函数值返回。
注意:错误的语句在∥********error********的下面,修改该语句即可。
#include
using namespace std;
∥********error********
int max(int a,int b)
{
if(a
问答题使用VC6打开
proj2下的工程proj2,其中有两个类:一是销售类(sale),用于表示按照一件商品的基本价格进行销售;另一个是打折销售类(DiscountSale),用于表示在基本价格基础上按一个折扣比例进行销售。DiscountSale类继承了sale类。类的主要数据成员的含义和成员函数的功能要求在程序注释中有说明。请在程序中的横线处填写适当的代码,然后删除横线,完成程序的功能。此程序的正确输出结果应为:
Discount item is cheaper.
Saving is 0.1
注意:只能在横线处填写适当的代码,不要改动程序中的其他内容。
#include<iostream>
using namespace std;
class Sale
{
public:
Sale();//默认构造函数,将price初始化为0
Sale(double the_price);//构造函数,用the price初始化price
virtual double bill()const;//返回当前商品的价格(基本价)
double savings(const Sale//返回参数other所引用的对象比当前对象便宜的差价protected:
double price;//商品的基本价格(不打折的价格)
};
Sale::Sale():price(0){}
Sale::Sale(double the_price): price(the_price){}
double Sale::bill()const
{
return price;
}
double Sale::savings(const Sale//返回当前对象价格比other贵多少的差价
}
class DiscountSale: public Sale//打折销售类继承销售类
{
public:
DiscountSale();//默认构造函数,将discount初始化为0
DiscountSale(double the_price,double the_discount);//构造函数,the_price是基本价格;the_discount是折扣百分比
virtual double bill()const;//返回本商品销售价格(即打折以后的实际售价,覆盖了基类的bill函数)
protected:
double discount;//折扣百分比。例如降价至原价的70%,此成员值应为70
};
DiscountSale::DiscountSale(): discount(0){}
DiscountSale::DiscountSale(double the_price,double the_discount)
:Sale(the_price),discount(the_discount){}
double DiscountSale::bill()const
{
double fraction=discount/100;
//******found******
______;//返回本对象打折以后的实际售价
}
bool operator<(const Sale//判断是否first价格低于second价格
}
int main()
{
Sale simple(10.00);
DiscountSale discount(11.00,90);
if(discount<simple)
{
cout<<"Discount item is cheaper./n";
//******found******
//这里输出购买discount比购买simple节省多少钱
cout<<"Saving is"<<______<<endl;
}
else
cout<<"Discount item is not cheaper./n";
return 0;
}
