建立如下类的层次结构:以Shape 为抽象基类,从Shape类派生出Point、Line、Circle、Cylinder、Cone、Triangle、Rectangle和Polygon等类。请为各个类设计比较实用的成员,并编写合适的应用程序来测试该类的层次结构。
#include<iostream>
#include<cmath>
#include<iomanip>
#ifndef CSHAPE_H
#define CSHAPE_h
usingnamespace std;
constfloat PI=31;
class CShape//CShape抽象类定义
{
public:
virtualfloat length()//图形长度
{
return 00;
}
virtualfloat area()//图形面积
{
return 00;
}
virtualfloat valum()//图形体积
{
return 00;
}
virtualfloat zc()//图形周长
{
return 00;
}
virtualvoid draw()=0;//描绘图形
};
class CPoint:virtualpublic CShape//CPoint类定义
{
protected:
float x,y;
public:
CPoint(float a,float b)
{
x=a;
y=b;
}
void setpoint(float a,float b)
{
x=a;
y=b;
}
void draw()
{
cout<<"点的坐标为:"<<"("<<x<<","<<y<<")"<<endl;
}
};
class CLine:virtualpublic CShape//线类定义
{
protected:
float x,y,z,k;
public:
CLine(float a,float b,float c,float d)
{
x=a;
y=b;
z=c;
k=d;
}
void setline(float a,float b,float c,float d)
{
x=a;
y=b;
z=c;
k=d;
}
float length()
{
return(sqrt((x-z)(z-z)+(y-k)(y-k)));
}
void draw()
{
cout<<"两坐标分别为:"<<"("<<x<<","<<y<<")"<<",("<<z<<","<<k<<")"<<endl;
}
};
class CRectangle:virtualpublic CShape//长方形类定义
{
protected:
float length,width;
public:
CRectangle(float l,float w)
{
length=l;
width=w;
}
void setrectangle(float l,float w)
{
length=l;
width=w;
}
float area()
{
return(lengthwidth);
}
float zc()
{
return(2(length+width));
}
void draw()
{
cout<<"长方形的长为:"<<length<<setw(10)<<"宽为:"<<width<<endl;
}
};
class CCircle:virtualpublic CShape//圆类定义
{
protected:
float radius;
public:
CCircle(float r)
{
radius=r;
}
void setcircle(float r)
{
radius=r;
}
float area()
{
return(PIradiusradius);
}
float zc()
{
return(2PIradius);
}
void draw()
{
cout<<"圆的半径为:"<<radius<<endl;
}
};
class CCylinder:virtualpublic CShape//圆柱类定义
{
protected:
float heigth,radius;
public:
CCylinder(float r,float h)
{
heigth=h;
radius=r;
}
void setcylinder(float r,float h)
{
heigth=h;
radius=r;
}
float area()
{
return(PIradiusradius+2PIradius);
}
float valum()
{
return(PIradiusradiusheigth);
}
void draw()
{
cout<<"圆柱高度为:"<<heigth<<setw(10)<<"半径为:"<<radius<<endl;
}
};
class CCone:virtualpublic CShape//定义一个圆锥类
{
protected:
float mx,radius;
public:
CCone(float a,float b)
{
mx=a;
radius=b;
}
void setcone(float a,float b)
{
mx=a;
radius=b;
}
float valum()
{
return(PIradiusradiussqrt(mxmx-radiusradius));
}
void draw()
{
cout<<"母线长为:"<<mx<<setw(10)<<"半径长为:"<<radius<<endl;
}
};
class CTriangle:virtualpublic CShape//三角形类定义
{
protected:
float x,y,z;
public:
CTriangle(float a,float b,float c)
{
x=a;y=b;z=c;
}
void settriangle(float a,float b,float c)
{
x=a;y=b;z=c;
}
float zc()
{
return(x+y+z);
}
float area()
{
float t=(x+y+z)/2;
return(sqrt((t-x)(t-y)(t-z)));
}
void draw()
{
cout<<"三角形三边长分别为:"<<x<<","<<y<<","<<z<<endl;
}
};
class CPolygon:virtualpublic CShape//多边形类定义
{
protected:
float x;
int y;
public:
CPolygon(float a,int b)
{
x=a;
y=b;
}
void setpolygon(float a,int b)
{
x=a;
y=b;
}
float area()
{
return(sqrt(30)xxy/4);
}
float zc()
{
return(xy);
}
void draw()
{
cout<<"多边形的一边长为:"<<x<<setw(10)<<"边数为:"<<y<<endl;
}
};
#endif
#include"CShapeh"
#include<iostream>
#include<iomanip>
usingnamespace std;
void main()
{
char d='y';
int i(0);
cout<<"欢迎进入本系统!";
cout<<"请选择服务:"<<endl;
cout<<" 1点的计算。"<<endl;
cout<<" 2线的计算。"<<endl;
cout<<" 3圆的计算。"<<endl;
cout<<" 4圆柱的计算。"<<endl;
cout<<" 5圆锥的计算。"<<endl;
cout<<" 6长方形的计算。"<<endl;
cout<<" 7多边形的计算。"<<endl;
cout<<" 8三角形的计算。"<<endl;
cout<<" 9退出。"<<endl;
while(d=='Y'||d=='y')
{
cin>>i;
if(i==1)
{
CShape pshape;
CPoint point(20,30);
float a,b;
cout<<"请输入点的坐标:";
cin>>a>>b;
pointsetpoint(a,b);
pshape=&point;
pshape->draw();
}
elseif(i==2)
{
CShape pshape;
CLine line(10,20,30,40);
float a,b,c,d;
cout<<"请依次输入两端点的坐标:";
cin>>a>>b>>c>>d;
linesetline(a,b,c,d);
pshape=&line;
pshape->draw();
cout<<"线的长度为:"<<pshape->length()<<endl;
}
elseif(i==3)
{
CShape pshape;
CCircle circle(20);
float a;
cout<<"请输入圆的半径:";
cin>>a;
circlesetcircle(a);
pshape=&circle;
pshape->draw();
cout<<"圆的面积为;"<<pshape->area()<<setw(10)<<"圆的周长为;"<<pshape->zc()<<endl;
}
elseif(i==4)
{
CShape pshape;
CCylinder yz(20,30);
float a,b;
cout<<"请输入圆柱的底面半径和高:";
cin>>a>>b;
yzsetcylinder(a,b);
pshape=&yz;
pshape->draw();
cout<<"圆柱的面积为:"<<pshape->area()<<setw(10)<<"圆柱的体积为:"<<pshape->valum()<<endl;
}
elseif(i==5)
{
CShape pshape;
CCone cone(50,40);
float a,b;
cout<<"请输入母线长和底面半径:";
cin>>a>>b;
conesetcone(a,b);
pshape=&cone;
pshape->draw();
cout<<"圆锥的体积为:"<<pshape->valum()<<endl;
}
elseif(i==6)
{
CShape pshape;
CRectangle rectangle(30,20);
float a,b;
cout<<"请输入长方形的长和宽:";
cin>>a>>b;
rectanglesetrectangle(a,b);
pshape=&rectangle;
pshape->draw();
cout<<"长方形的面积为:"<<pshape->area()<<setw(10)<<"长方形的周长为:"<<pshape->zc()<<endl;
}
elseif(i==7)
{
CShape pshape;
CPolygon polygon(20,4);
float a;
int b;
cout<<"请输入多边形的边长和边数:";
cin>>a>>b;
polygonsetpolygon(a,b);
pshape=&polygon;
pshape->draw();
cout<<"多边形的面积为:"<<pshape->area()<<setw(10)<<"周长为:"<<pshape->zc()<<endl;
}
elseif(i==8)
{
CShape pshape;
CTriangle triangle(30,40,50);
float a,b,c;
cout<<"请输入三角形三边长:";
cin>>a>>b>>c;
trianglesettriangle(a,b,c);
pshape=▵
pshape->draw();
cout<<"三角形的周长为:"<<pshape->zc()<<"面积为:"<<pshape->area()<<endl;
}
elseif(i==9)
{
return;
}
else
{
cout<<"输入错误,请重新输入!";
}
cout<<"是否继续其他操作(Y/N)"<<endl;
cin>>d;
}
}
欢迎进入本系统!请选择服务:
1点的计算。
2线的计算。
3圆的计算。
4圆柱的计算。
5圆锥的计算。
6长方形的计算。
7多边形的计算。
8三角形的计算。
9退出。
请输入你的选择:
1
请输入点的坐标:2
点的坐标为:(1,2)
是否继续其他操作(Y/N)
y
请输入你的选择:
2
请依次输入两端点的坐标:1 2 3 4
两坐标分别为:(1,2),(3,4)
线的长度为:2
是否继续其他操作(Y/N)
y
请输入你的选择:
3
请输入圆的半径:
圆的半径为:1
圆的面积为;31圆的周长为;62
是否继续其他操作(Y/N)
y
请输入你的选择:
4
请输入圆柱的底面半径和高:1
圆柱高度为:1半径为:1
圆柱的面积为:93圆柱的体积为:31
是否继续其他操作(Y/N)
y
请输入你的选择:
5
请输入母线长和底面半径:3
母线长为:5半径长为:3
圆锥的体积为1:1116
是否继续其他操作(Y/N)
y
请输入你的选择:
6
请输入长方形的长和宽:1 4
长方形的长为:1 宽为:4
长方形的面积为:4长方形的周长为:10
是否继续其他操作(Y/N)
y
请输入你的选择:
7
请输入多边形的边长和边数:1 7
多边形的一边长为:1 边数为:
多边形的面积为:303109 周长为:7
是否继续其他操作(Y/N)
y
请输入你的选择:
8
请输入三角形三边长:3 4 5
三角形三边长分别为:3,4,5
三角形的周长为:12面积为:244949
是否继续其他操作(Y/N)
y
请输入你的选择:
9
请按任意键继续
经过几十年专注的发展,目前,大唐融合已经拥有了一支在融合通信、CTI技术、电信业务、广电业务、产品开发和技术管理、系统集成、软件工程管理、项目管理等领域均具有丰富经验的专家队伍,其中技术人员占公司总人数的90%以上。基于多年来在各行业的业务技术积累,大唐融合能够根据用户需求,为用户量身定制完整的解决方案,包括前期咨询、硬件平台、系统软件、应用软件和运维服务。
大唐融合资质
ISO9001:2000国际质量保障体系
计算机信息系统集成一级资质
增值电信业务经营许可证(呼叫中心)
高新技术企业证书
海淀区创新企业
中关村高新技术企业
软件企业认定书
北京市安全技术防范工程准许证
CCOne(Dynamic)v10软件著作权登记证书
CCOne(Dynamic)v10软件产品登记证书
CCOne(Dynamic)v20软件著作权登记证书
DV客户服务系统软件著作权登记证书
DV客户服务系统软件产品登记证书
大唐融合统一支付平台(DC-EPS)v30著作权登记证书
网络多媒体客户端系统V1001软件著作权登记证书
广泛的市场及售后服务网络
凭借大唐电信和大唐融合广泛的销售及服务网络平台,大唐融合现已将业务顺利发展至全国各地,以保障为客户提供优质快速的售后服务和现场支持。
欢迎分享,转载请注明来源:品搜搜测评网