C++编程 图形类 画简单图形类
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
{
cout<<"请输入图形名称:(圆形、矩形、平行四边形、梯形、三角形)"
<<endl<<"图形类型: "<<endl;
cin>>name;
}
virtual void getarea()
{
}
char* getname()
{
return (char*) name;
}
};
class yuan:public tuxing
}
};
class sanjiaoxing:public tuxing
{
void gettuxing()
{
cout<<"请输入底和高:"<<endl;
cin>>length>>width;
}
void getarea()
{
double area=0.5*length*width;
cout<<"所求三角形面积为:"<<endl<<area<<endl;
{
public:
void gettuxing()
{
cout<<"请输入长宽:(格式为:长+空格+宽)"<<endl;
cin>>length>>width;
}
void getarea()
{Байду номын сангаас
area=length*width;
cout<<"矩形面积为:"<<endl<<area<<endl;
}
};
class pxsbx:public tuxing
{
tixing B;
b=&B;
b->gettuxing();
b->getarea();
}
if(strcmp(A.getname(),"三角形")==0)
{
sanjiaoxing B;
b=&B;
b->gettuxing();
b->getarea();
}
goto label;
}
{
juxing B;
b=&B;
b->gettuxing();
b->getarea();
}
if(strcmp(A.getname(),"平行四边形")==0)
{
pxsbx B;
b=&B;
b->gettuxing();
b->getarea();
}
if(strcmp(A.getname(),"梯形")==0)
{
private:
double w1,w2,h;
public:
void gettuxing()
{
cout<<"请输入上底下底和高:"<<endl;
cin>>w1>>w2>>h;
}
void getarea()
{
double area=0.5*(w1+w2)*h;
cout<<"所求梯形面积为:"<<endl<<area<<endl;
{
private:
double r;
public:
void gettuxing()
{
cout<<"请输入半径:"<<endl;
cin>>r;
}
void getarea()
{
area=r*r*4*atan(1);
cout<<"所求圆面积为:"<<endl<<area<<endl;
}
};
class juxing:public tuxing
图形类
#include<iostream.h>
#include<string.h>
#include<math.h>
//定义图形类
class tuxing
{
private:
char name[50];
public:
double length,width,area;
virtual void gettuxing()
}
};
void main()
{
tuxing A,*b;
label:
A.gettuxing();
if(strcmp(A.getname(),"圆")==0)
{
yuan B;
b=&B;
b->gettuxing();
b->getarea();
}
if(strcmp(A.getname(),"矩形")==0)
{
void gettuxing()
{
cout<<"请输入底和高:(格式为:底边长+空格+高)"<<endl;
cin>>length>>width;
}
void getarea()
{
area=length*width;
cout<<"平行四边形面积为:"<<endl<<area<<endl;
}
};
class tixing:public tuxing
cout<<"请输入图形名称:(圆形、矩形、平行四边形、梯形、三角形)"
<<endl<<"图形类型: "<<endl;
cin>>name;
}
virtual void getarea()
{
}
char* getname()
{
return (char*) name;
}
};
class yuan:public tuxing
}
};
class sanjiaoxing:public tuxing
{
void gettuxing()
{
cout<<"请输入底和高:"<<endl;
cin>>length>>width;
}
void getarea()
{
double area=0.5*length*width;
cout<<"所求三角形面积为:"<<endl<<area<<endl;
{
public:
void gettuxing()
{
cout<<"请输入长宽:(格式为:长+空格+宽)"<<endl;
cin>>length>>width;
}
void getarea()
{Байду номын сангаас
area=length*width;
cout<<"矩形面积为:"<<endl<<area<<endl;
}
};
class pxsbx:public tuxing
{
tixing B;
b=&B;
b->gettuxing();
b->getarea();
}
if(strcmp(A.getname(),"三角形")==0)
{
sanjiaoxing B;
b=&B;
b->gettuxing();
b->getarea();
}
goto label;
}
{
juxing B;
b=&B;
b->gettuxing();
b->getarea();
}
if(strcmp(A.getname(),"平行四边形")==0)
{
pxsbx B;
b=&B;
b->gettuxing();
b->getarea();
}
if(strcmp(A.getname(),"梯形")==0)
{
private:
double w1,w2,h;
public:
void gettuxing()
{
cout<<"请输入上底下底和高:"<<endl;
cin>>w1>>w2>>h;
}
void getarea()
{
double area=0.5*(w1+w2)*h;
cout<<"所求梯形面积为:"<<endl<<area<<endl;
{
private:
double r;
public:
void gettuxing()
{
cout<<"请输入半径:"<<endl;
cin>>r;
}
void getarea()
{
area=r*r*4*atan(1);
cout<<"所求圆面积为:"<<endl<<area<<endl;
}
};
class juxing:public tuxing
图形类
#include<iostream.h>
#include<string.h>
#include<math.h>
//定义图形类
class tuxing
{
private:
char name[50];
public:
double length,width,area;
virtual void gettuxing()
}
};
void main()
{
tuxing A,*b;
label:
A.gettuxing();
if(strcmp(A.getname(),"圆")==0)
{
yuan B;
b=&B;
b->gettuxing();
b->getarea();
}
if(strcmp(A.getname(),"矩形")==0)
{
void gettuxing()
{
cout<<"请输入底和高:(格式为:底边长+空格+高)"<<endl;
cin>>length>>width;
}
void getarea()
{
area=length*width;
cout<<"平行四边形面积为:"<<endl<<area<<endl;
}
};
class tixing:public tuxing