题目内容:
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件 main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTriangle(“三角形”)的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序的正确输出结果应为: 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 #include<lostream> {tout<<——<<endl;} class CRectangle:public CPolygon{ CRe&angle(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 l,int h):length(1),height(h){}
//*********found*********
int area(void){return(——)/2;}
};
int main(){
CRectangle rect(4,5); CTriangle trgl(4,5);
//*********found********* ______ *ppolyl,* ppoly2; ppolyl=&rect;
ppoly2=&trgl;
ppolyl->printarea(); ppoly2->printarea(); retun 0;
参考答案:
答案解析: