#include <iostream>
using namespace std;
class shape {
public:
shape() {
height = 0 ;
width = 0 ;
length = 0 ;
radius = 0;
};
double area() ;
int area(int w, int h) ;
double area(int radius) ;
protected:
int height ;
int width ;
int length ;
int radius ;
};
class square : public shape {
public :
square(){
int w;
cout<<"請輸入邊長"<<endl;
cin>>w;
width = w ;
};
int area() {
return width * width ;
};
} ;
class rectangle : public shape {
public :
rectangle (){
int w;
int h;
cout<<"請輸入寬"<<endl;
cin>>w;
cout<<"請輸入高"<<endl;
cin>>h;
height = h ;
width = w ;
};
int area() {
return height * width ;
};
} ;
class circle : public shape {
public :
circle (){
int r;
cout<<"請輸入半徑"<<endl;
cin>>r;
radius=r;
};
double area() {
return 3.14159*radius*radius ;
};
} ;
class Right_triangle : public shape {
public :
Right_triangle (){
int w;
int h;
cout<<"請輸入寬"<<endl;
cin>>w;
cout<<"請輸入高"<<endl;
cin>>h;
height = h ;
width = w ;
};
double area() {
return height*width/2 ;
};
} ;
class rectangle_column : public shape {
public :
rectangle_column (){
int w;
int h;
int l;
cout<<"請輸入寬"<<endl;
cin>>w;
cout<<"請輸入長"<<endl;
cin>>h;
height = h ;
width = w ;
cout<<"請輸入高"<<endl;
cin>>l;
length=l;
};
int area() {
return height * width*length ;
};
} ;
class circle_column : public shape {
public :
circle_column (){
int r;
int l;
cout<<"請輸入半徑"<<endl;
cin>>r;
radius=r;
cout<<"請輸入高"<<endl;
cin>>l;
length=l;
};
double area() {
return 3.14159*radius*radius*length ;
};
} ;
class Right_triangle_column : public shape {
public :
Right_triangle_column (){
int w;
int h;
int l;
cout<<"請輸入寬"<<endl;
cin>>w;
cout<<"請輸入高"<<endl;
cin>>h;
height = h ;
width = w ;
cout<<"請輸入高"<<endl;
cin>>l;
length=l;
};
int area() {
return height*width/2*length ;
};
} ;
class square_column : public shape {
public :
square_column(){
int w;
int l;
cout<<"請輸入邊長"<<endl;
cin>>w;
cout<<"請輸入高"<<endl;
cin>>l;
width = w ;
length=l;
};
int area() {
return width * width*length ;
};
} ;
int main(void) {
int q;
cout<<"請問要算甚麼面積"<<endl<<"正方形請輸入 1 "<<endl<<"長方形請輸入 2 "<<endl<<"圓請輸入 3 "<<endl<<"直角三角形請輸入 4 "<<endl<<"正方形柱請輸入 5 "<<endl<<"長方形柱請輸入 6 "<<endl<<"圓柱請輸入 7 "<<endl<<"直角三角形柱請輸入 8 "<<endl;
cin>>q;
if(q==1){
square s ;
cout << "正方形面積為=" << s.area() << endl ;}
if(q==2){
rectangle r ;
cout << "長方形面積為=" << r.area() << endl ;}
if(q==3){
circle c ;
cout << "圓面積為=" << c.area() << endl ;}
if(q==4){
Right_triangle rt ;
cout << "直角三角形面積為=" << rt.area() << endl ;}
if(q==5){
square_column sc;
cout << "正方形柱體積為=" << sc.area() << endl ;
}
if(q==6){
rectangle_column rc ;
cout << "長方形柱體積為=" << rc.area() << endl ;}
if(q==7){
circle_column cc ;
cout << "圓柱體積為=" << cc.area() << endl ;}
if(q==8){
Right_triangle_column rtc ;
cout << "直角三角形柱體積為=" << rtc.area() << endl ;
return 0;}
}