请打开考生文件夹下的解决方案文件proj3,此工程中包含一个源程序文件proj3.cpp,其中定义了用于表示平面坐标系中的点的类MyPoint和表示矩形的类MyRectangle;程序应当显示: (0,2)(2,2)(2,0)(0,0)4 但程序中有缺失部分,请按照以下提示,把缺失部分补充完整: (1)在“//**1** ****found****”的下方是构造函数的定义,它用参数提供的左上角和右下角的坐标对up_left和down_right进行初始化。 (2)在“//**2** ****found****”的下方是成员函数getDownLeft的定义中的一条语句。函数getDownLeft返回用MyPoint对象表示的矩形的左下角。 (3)在“//**3** ****found****”的下方是成员函数area的定义,它返回矩形的面积。 注意:只在指定位置编写适当代码,不要改动程序中的其他内容,也不要删除或移动“****found****”。 1 //proj3.cpp 2 #includeiostream 3 using namespace std; 4 class MyPoint{//表示平面坐标系中的点的类 5 double x; 6 double y; 7 public: 8 MyPoint(double x,double y){this-x=x;this-y=y;} 9 double getX()const{return x;} 10 double getY()const{return y;} 11 void show()const(cout'('x','y:')';} 12 }; 13 class MyRectangle{ //表示矩形的类 14 MyPoint up left; //矩形的左上角顶点 15 MyPoint down right; //矩形的右下角顶点 16 public: 17 MyRectangle(MyPoint upleft,MyPoint downright); 18 MyPoint getUpLeft()const{return up left;}//返回左上角坐标 19 MyPoint getDownRight()const {return down right;} //返回右下角坐标 20 MyPoint getUpRight()const; //返回右上角坐标 21 MyPoint getD0wnLeft()const; //返回左下角坐标 22 double area()const; //返回矩形的面积 23 }; 24 //**1** **********found********** 25 MyRectangle:: MyRectangle (____________): up left(p1),down_right(p2){} 26 MyPoint MyRectangle::getUpRight ()const 27 { 28 return MyPoint(down_right.getX(),up_left.getY()); 29 } 30 MyPoint MyRectangle::getDown-Left()const 31 { 32 //**2** **********found********** 33 return MyPoint(___________); 34 } 35 //**3** **********found********** 36 ___________area()const 37 { 38 return(getUpLeft().getX()-getDownRight().getX()) *(getDownRight().getY()-getU-pLeft().getY()); 39 } 40 int main() 41 { 42 MyRectangle r(MyPoint(0,2), MyPoint(2,0)); 43 r.getUpLeft().show(); 44 r.getUpRight().show(); 45 r.getDownRight().show(); 46 r.getDownLeft().show(); 47 coutr.area()endl; 48 return 0; 49 }
请使用VC6或使用【答题】菜单打开考生文件夹proj3下的工程proj3,其中声明了一个单向链表类sList。sList的成员函数Prepend的功能是在链表头部加入一个新的元素。请编写成员函数Prepend。在main函数中给出了一组测试数据,此时程序的输出应为: B-A- ### A- ### A- ### exiting inner block exiting outer block 注意:只在函数Prepend的“//**********333**********”和“//**********666**********”之间填入若干语句,不要改动程序中的其他内容。//sList.hStruer sListItem{ char data; sListItem*next;};class sList{public: sList():h(0){)//0表示空链表 ~sList(); void Prepend(char c);//在链表前端加入元素 void Del();//删除链表首元素 sListItem*First()const(return h;}//返回链表首元素 void Print()const;//打印链表内容 void Release();//销毁链表private: sListItem*h;//链表头};void writeToFile(const char* );//main.cpp#includeiostream#include"sList.h"using namespace std;sList::~sList(){ Release();}void sList::Prepend(char c){ //**********333********** //**********666**********}void sList::Del(){ sLisstItem*temp=h; h=h-next; delete temp;}void sList::Print()const{ sListItem*temp=h; while(temp!=0)//判断是否到达链表尾部 { couttemp-data"-"; temp=temp-next; } cout"\n###"endl;}void sList::Release(){ while(h!=0) Del();}int main(){ sList*ptr; { sTst obj; obj.Prepend('A'); obj.Prepend('B'); obj.Print(); obj.Del(); obj.Print(); ptr=obj; ptr-Print(); cout"exiting inner block"endl; } cout"exiting outer block"endl; writeToFile(""); return 0;}
请打开考生文件夹下的解决方案文件proj2,其中定义了vehicle类,并派生出motorcar类和bicycle类。然后以motorcar和bicycle作为基类,再派生出motorcycle类。要求将vehicle作为虚基类,避免二义性问题。清在程序中的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为: 80 150 100 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。#includeiostream.hClass vehiCle{private: int MaxSpeed; int Weight;public://********found******** vehicle(int maxspeed,intweight):______________ ~vehicle()(); int getMaxSpeed(){return MaxSpeed;) int getWeight() {returnWeight;}};//********found********class bicycle:___________publicvehicle{private: int Height;public: bicycle(int maxspeed,intweight,int height):vehicle(maxspeed,weight),Height(height){} int getHeight(){ returnHeight ;};};//********found********class motorcar:___________public vehicle{private: int SeatNum;public: motorcar(int maxspeed,intweight,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,1 00); couta.getMaxSpeed()endl; couta.getWeight()endl; couta.getHeight()endl; couta.getSeatNum()endl;}
请打开考生文件夹下的解决方案义件proj1,其中有点类Point和线段类Line和主函数main的定义,程序中位于每个“//ERROR ****found****”之后的一行语句有错误,请加以改正。改正后程序的输出应为: p1=(8,4)p2=(3,5) 注意:只修改两个“//ERROR ****found****”下的那一行,不要改动程序中的其他内容。#includeiostream#includecmathusing namespace std;class Point{ double x,y;public: Point(double x=0.0,double y=0.0)//ERROR ********found******** {x=x;y=y;} double getX()const{return x;) double getY()const{return y;}//ERROR ********found******** void show()const{cout'('x','y')')};clas s Line{ Point p1,p2;public: Line(point pt1,Point pt2)//ERROR ********found******** { pt1=p1;pt2=p2;} Point getP1()const{return p1 ;} Point getP2()const{return p2 ;}};int main(){ Line line(Point(8,4),Point(3,5)); cout"p1="; line.get P1().show(); cout"p2="; line.get P2().show(); coutend1; return 0;}
请打开考生文件夹下的解决方案文件proj3,其中包含了类Polynomial(“多项式”)的定义。 形如5x4+3.4x2一7x+2的代数式称为多项式,其中的5为4次项系数,3.4为2次项系数,一7为1次项系数,2为0次项(常数项)系数。此例缺3次项,意味着3次项系数为0,即省略了0x3。在Poly.nomial中,多项式的各个系数存储在一个名为coef的数组中。例如,对于上面的多项式,保存在coef[0]、coef[1]…coef[4]中的系数依次为:2.0、一7.0、3.4、0.0、5.0,也即对于i次项,其系数就保存在coef[i]中。成员函数getValue计算多项式的值,多项式中x的值是由参数指定的。 请补充完成文件Polynomial.cpp中成员函数getValue的定义。此程序的正确输出结果应为: Value of p1 when x=2.0:59.8 Value of p2 when x=3.0:226.8 注意:只在函数getValue的“//*******333*******”和“//*******666*******”之间填入若干语句,不要改动程序中的其他内容。//Polynomiac.h{}includeusing namespace std;class Polynomial{//“多项式”类public: Polynomial(double coef[],int num):coef (new double[num]),num_Of_terms(num){ for(int i=0;icoef[i]=coef[i]; } ~Polynomial(){delete[] coef;} //返回指定次数项的系数 double getCoefficient(intpower)const{return coef[power];} //返回在x等于指定值时多项式的值 double getValue(double x)conSt;private://系数数组,coef[0]为0次项(常数项)系数,coef[1]为1次项系数,coef[2]为2次项(平方项)系数,余类推。 double*coef; int num_of_terms; }; void writeToFile f const char* path); //Polymomial.cpp #include"Polynomial.h" double Polynomial:: getValue (double x)conSt{ //多项式的值value为各次项的累加和 double value=coef[0]; //*******333******* //*******666******* return value;}//main.cpp#include"Polynomial.h"int main(){ double p1[]={5.0,3.4,一4.0,8.0},p2[]={0.0,一5.4,0.0,3.0,2.0}; Polynomial polyl(p1,sizeof(p1)/sizeof(double)),poly2(p2,sizeof(p2)/sizeof(double)); cout"Value of p1 when x=2.0:"
