请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件main.Cpp,其中有坐标点类point、线段类Line和三角形类Triangle的定义.还有main函数的定义。程序中两
Side l:9.43398 Side 2:5
Side 3:8 area:20 注意:只在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。
#inClude #nClude 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()<
Cout<<”Side 2:”<<R.1ENGTH2()<<ENDL;&NBSP;&NBSP;&NBSP;
retum 0;
发布于 2022-05-13 21:36:48
登录后免费查看答案
关注者
0
被浏览
10
1 个回答
推荐阅读
-
有如下程序:#jnCludeusing namespaCe std; Class Part{publiC:Part(int x=0):val(X){Cout<<VAL;}&NBSP; ~Part(){Cout<<val;}private:int val; t };Class Whole{ publiC:Whole(int x,int Y,int z=0):p2(x),pl(y),val(z){Cout<<VAL;}&NBSP;&NBSP;&NBSP; ~Whole(){eout<<val;}private:Part pl,p2; int val;};int main() {Whole obj(1,2,3); return 0;}执行这个程序的输出结果是( )。
2022-05-13 关注 0 浏览25 1答案
-
下列程序输出的 * 个数是() <pre class="prettyprint lang-cpp">class Point { public: Point(int xx=0, int yy=0) { X=xx; Y=yy; } Point(Point &p) { X=p.X; Y=p.Y; cout<<"*"; } private: int X,Y; }; class Line { public: Line (Point xp1, Point xp2):p1(xp1),p2(xp2) {} private: Point p1,p2; }; int main() { Point myp1(1,1),myp2(4,5); Line line(myp1,myp2); return 0; }
2020-12-30 关注 0 浏览54 1答案
-
有如下程序:#includeusing namespace std;class MyClass{public:MyClass(){cout<<’A’;}MyClass(char C.{cout<<C;}~MyClass(){cout<<’B’;}};int main(){MyClass pl,+p2;p2=new MyClass(’X’);delete p2;return 0;}执行这个程序的输出结果是( )。
2022-05-13 关注 0 浏览37 1答案
-
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2。此工程中包含一个源程序文件main.cpp,其中有“房间”类Room及其派生出的“办公室”类0ffice的定义,还有主函数main的定义。请在程序中“//****found****”下的横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:办公室房间号:308办公室长度:5.6办公室宽度:4.8办公室面积:26.88办公室所属部门:会计科注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“///料料found??料”。#includeusing namespaee std;class Room{ //“房间”类int room_n0;//房间号double length;//房间长度(m)double width;//房间宽度(n1)public:Room(int the—room—n0,double the~length,double the—width):loom—no(the—room—no),length(the—length),width(the—width){}int theRoomNo()eonst{return iDonl—n0;}//返回房间号double theLength()const{return length;}//返回房间长度double theWidth()const{return width;}//返回房间宽度//**********found**********double theArea()const{_______________}//返回房间面积(矩形面积)};class Office:public Room{//“办公室”类char*depart;//所属部门public:Office(int the_room_n0,double the_length,double the_width,eonst char木the_depart)//**********found**********:_______________{depart=new char[strlen(the depart)+1];//**********found**********strcpy(_______________);}~Office(){delete[]depart;}const char*theDepartment()const{return depart;}//返回所属部门};int main(){//**********found**********Office_______________;cout<<”办公室房间号:”<<AU_OFFICE.THEROOMNO()<<ENDL<<”办公室长度:”<<<endl<<”办公室宽度:”<<<endl<<”办公室面积:”<<<endl<<”办公室所属部门:”<<ALL—OFFICE.THEDEPARTMENT()<return 0;}
2022-05-13 关注 0 浏览11 1答案
-
有如下程序:#includeusing namespace std;class MyClass{public:MyClass(int i=0){cout<<1;}MyClass(const MyClass&x){cout<<2;}MyClass&operator=(const MyClass&x){cout<<3;retum$this;}~MyClass()}cout<<4;}};int main(){MyClass objl(1),obj2(2),obj3(objl);retum 0;{执行这个程序的输出结果是( )。
2022-05-13 关注 0 浏览26 1答案
-
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,该工程中包含一个程序文件 main.cpp,其中有类CPolygon(“多边形”)、CRectangle(“矩形”)、CTriangle(“三角形”)的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。该程序的正确输出结果应为: 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//****found****”。 #include{tout<<——<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;
2022-05-13 关注 0 浏览8 1答案
-
试题六(15分,每空3分) 阅读以下说明和C++程序,将应填入 __(n)__处的字句写在答题纸的对应栏内 【说明】 以下程序的功能是计算三角形、矩形和正方形的面积并输出。 程序由4个类组成:类Triangle,Rectangle和Square分别表示三角形、矩形和正方形;抽象类Finure提供了一个纯虚拟函数getArea(),作为计算上述三种图形面积的通用接口。 【C++程序】 #include<iostream.h> #include<math.h> class Figure{ public: virtual double getArea()=0; //纯虚拟函数 }; class Rectangle:__(1)__ { protected: double height; double width; public: Rectangle(){}; Rectangle(double height,double width){ This->height=height; This->width=width; } double getarea(){ return __(2)__ ; } }; class Square:__(3)__ { public: square(double width){ __(4)__ ; } }; class triangle:__(5)__ { double la; double lb; double lc; public: triangle(double la ,double lb,double lc){ this ->la=la; this->lb; this->lc; } double getArea(){ double s=(la +lb+lc)/2.0; return sqrt(s*(s-la)**(s-lb) *(s-lc)); } };viod main(){ figure* figures[3]={ new triangle(2,3,3),new Rectangle(5,8),new Square(5)}; for (int i=0;i<3;i++){ cout<<”figures[“<<i<<”]area= “<<(figures)->getarea()<<endl; } } };
2022-05-10 关注 0 浏览20 1答案
-
下列程序的执行结果是( )。#includeclassSample{intx,y;public:Sample(){x=y=0;}Sample(inta,intb){x=a;y=b;}~Sample(){if(x==y)cout<<"x=y"<elsecout<<"x!=y"<}voiddisp(){cout<<"x="<<x<<",y="<<y<<endl;}};voidmain(){Samples1(2,3);s1.disp();}
2022-05-13 关注 0 浏览22 1答案
-
请使用VC6或使用【答题】菜单打开考生文件夹proj2下的工程proj2,其中有矩阵基类MatrixBase、矩阵类Matrix和单位阵UnitMatrix的定义,还有main函数的定义。请在横线处填写适当的代码并删除横线,以实现上述类定义。此程序的正确输出结果应为:1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 1 注意:只能在横线处填写适当的代码,不要改动程序中的其他内容,也不要删除或移动“//t+++found母***”。#nClude using namespaCe std; //矩阵基础类,一个抽象类Class MatrixBase{ int rows,Cols; publiC:MatrixBase(int rows,int Cols):roWS(rows),Cow(Cols){} int getRows()Const{retum rows;}//矩阵行数int getCols()Const{return Cols;}//矩阵列数virtual double getElement(int r,int C)Const=0;//取第i个元素的值 void show()Const{//分行显示矩阵中所有元素for(int i=0;i<ROWS;I++){&NBSP;&NBSP;&NBSP;for(int j=0;j<COLS;J++)&NBSP;&NBSP;&NBSP; }<<””; Cout<< **********found********** /> } }; //矩阵类Class Matrix:publiC MatfixBase{ double*val;publiC: //**********found**********Matrix(int rows,int Cols,double in[]=NULL):——{ //**********found**********val=;for(int i=0:i<ROWS*COLS;I++)val[i]=(m==NULL?0.0:Ill[i]);}一Matrix(){delete[]val;} double getElement(int r,int C)Const{retum val[r*getCols()+C];}};//单位阵(主对角线元素都是l,其余元素都是0的方阵)类 Class UnitMatrix:publiC MatrixBase{publiC:UnitMatrix(int rOWS):MatrixBase(rows,rows){} //单位阵行数列数相同double getElement(int r,int C)Const{ //**********found**********if(_____)retum l.0; retum 0.0;} }; int main(){MatrixBase*m;double d[][5]={{1,2,3,4,5},{2,3,4,5,6},{3,4,5,6,7}}; ITI=new Matrix(3,5,(double*)d);m→show(); delete m;Cout<m=new UnitMatrix(6); Ill→show();delete m; retum0; }
2022-05-13 关注 0 浏览15 1答案
-
有如下程序: #include #include using namespace std; class Point { public: friend double distance(const Point& p); //p距原点的距离 Point(int xx = 0, int yy = 0) :x(xx), Y(yy){} //① private: int x, Y; }; double distance(const Point &p) { return sqrt(p.x*p.x + p.Y*p.Y); //② } int main() { Point p1(3, 4); cout << distance(p1) << endl; //③ return 0; } 下列叙述中正确的是( )
2021-11-03 关注 0 浏览109 1答案