简答题 C++
题号 #2607038

请使用VC6或使用【答题】菜单打开考生文件夹projl下的工程projl,其中有枚举DOGCOLOR、狗类Dog和主函数main的定义。程序中位于每个“//ERROR ****found****”下的语句行有错误,请加以改正。改正后程序的输出结果应该是:
There is a white dog named Hoh0.  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 nalTle[],DOGCOLOR Color){    strCpy(this一>name,name);
//ERROR**********found**********、
strCpy(this一>Color,Color);
}    1    DOGCOLOR getColor()Const{retum Color;}
//ERROR**********found**********
Const Char * 9etName()Const{return*finin9;}        Const Char * 9etColorString()Const{
switCh(Color){
Case BLACK:return”blaCk“;    Case WHITE:return”white”:
Case YELLOW:return’"yellow”:    Case BROWN:return”brown”;    ease PIEBALD:return”piebald”:
}
return”motley”;
}
void show()Const{    .    Cout<<”There is a”<<getColorString()<<”dog named’’<<name<<’.’<<endl;
}    };    int main(){
//ERROR**********found**********
Dog dogl(”Hoh0”,WHITE),dog2(”Haha”,BLACK);d0g3(”Hihi”,0THER);    d091.show();
dos2.show();    dos3.show();    return 0;
}

进入在线模考

参考答案

暂无

答案解析

(1)this->color=color:
(2)consL char getName()eonst{return*name;}
(3)Dog dogl(”Hoho”,WHITE)。dog2(”Haha”,
BLACK),dog3(”Hihi”,OTHER);

你可能感兴趣的试题

1 请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.Cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义.还有main函数的定义。程序中两

Side l:9.43398  Side 2:5
Side 3:8  area:20  注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#inClude<iostream>  #nClude<Cmath>  using namespaCe std;
Class Point{//坐标点类  publiC:
Const double x,y;
Point(double x=0.0,double Y=0.0):x(x),Y(Y){}    //**********found**********
double distanCeTo(_____)  Const{
//到指定点的距离
return sqrt((x-P.X)*(x-P.x)+(Y-P.Y)*(Y-P.Y));      }
};
Class Line{//线段类  publiC:
eonst Point pl,p2;//线段的两个端点
//**********found**********
Line(Point pl,Point p2):——{}
double length()eonst/retum pl.distanCeTo(p2);}//线段的长度  };
Ct彝SS Triangle{//三角形类  publiC:
Const Point pl,p2,p3;//三角形的三个顶点        //**********found**********
Triangle(_____):pl(p1),p2(p2),p3(p3){}  double lengthl()Const{//边pl,p2的长度
retum Line(pl,p2).1ength();    }
double length2()Const{//边p2,p3的长度    return Line(p2,p3).1ength();
}
double length3()Const{//边p3,pl的长度    returnLine(p3,pl).1ength();
}
double area()Const{//三角形面积
//**********found**********    double s=_____;
return sqrt(s{(S-lengthl())*(s-length2())*(s—length3()));    }
};
int main(){
Triangle r(Point(0.0,8.0),Point(5.0,0.0),Point(0.0,0.0));    Cout<<”Side l:”<<r.1engthl()<<endl;
Cout<<”Side 2:”<<r.1ength2()<<endl;    Cout<<”Side 3:”<<r.1ength3()<<endl;    Cout<<”area:”<<r.area()<<endl;
retum 0;
2 请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明的DataList类,是一个用于表示数据表的类。s0rt成员函数的功能是将当前数据表中的元素升序排列。请编写这个sort函数。程序的正确输出应为:    .
排序前:7,1,3,11,6,9,12,10,8,4,5,2  排序后:l,2,3,4,5,6,7,8,9,10,11,12
要求:
补充编制的内容写在“//********33********”与“//********666********”两行之问。不得修
改程序的其他部分。
注意:程序最后将结果输出到文件。ut.dat中。输出函数writeToFile已经编译为。obj文件,并且在本程序
调用。
//DataList.h
#inClude<iostream>    using namespaCe std;    Class DataList{//数据表类
int len;
double*d: publiC:
DataList(int len,double data[]=NULL);。DataList(){delete[]d;}
int length(Constt retum len;}//数据表长度(即数据元素的个数) double getElement(int i)Const{return d[i];}
void sort();//数据表排序
void show()Const;//显示数据表}.
void writeToFile(Char*,Const DataList&).//main.Cpp
#inClude”DataList.h”
DataList::DataList(int len,double data[]):len(1en){  d=new double[1en];
for(int i_0;i<len;i++)
d[i]=(data==NULL?0.0:data[i]);
}
void DataList::sort(){//数据表排序//********333********
//********666********}
void DataList::show()Const{//显示数据表
for(int i=0;i<len一1;i++)Cout<<d[i]<<”,”;    Cout<<d[1en一1]<<endl;
}
int main(){
double S[]={7,1,3,11,6,9,12,10,8,4,5,2};  DataList list(12,S);
Cout<<”排序前:”;  list.show();
list.sort();
Cout<<endl<<”排序后:”;  list.show();
writeToFile(””,list);  return 0;
}
A.栈顶元素最先能被删除
B.栈顶元素最后才能被删除
C.栈底元素永远不能被删除
D.栈底元素最先被删除
找试题 · 找答案 · 找资料 在线模考