作者在 2009-05-21 12:40:55 发布以下内容
#include<iostream>
#include<cmath>
#include<iomanip>
using namespace std;
#include<cmath>
#include<iomanip>
using namespace std;
class shape
{
public:
virtual double area()const{return 0.0;}
virtual double zhouchang()const{return 0.0;}
};
class sanjiaoxing :public shape
{double a,b,c;
public:
sanjiaoxing(double x,double y,double z){a=x;b=y,c=z;}
virtual double area()const
{ double p;
p=(a+b+c)/2;
cout<<"三角形的面积是 "<<endl;
return(sqrt(p*(p-a)*(p-b)*(p-c)));
}
virtual double zhouchang()const{cout<<"三角形的周长是 "<<endl;return(a+b+c);}
{ double p;
p=(a+b+c)/2;
cout<<"三角形的面积是 "<<endl;
return(sqrt(p*(p-a)*(p-b)*(p-c)));
}
virtual double zhouchang()const{cout<<"三角形的周长是 "<<endl;return(a+b+c);}
void showa(){cout<<"三角形的第一条边 "<<a<<endl;}
void showb(){cout<<"三角形的第二条边 "<<b<<endl;}
void showc(){cout<<"三角形的第三条边 "<<c<<endl;}
void showb(){cout<<"三角形的第二条边 "<<b<<endl;}
void showc(){cout<<"三角形的第三条边 "<<c<<endl;}
bool panduan(){if((a+b>c)&&(abs(a-b)<c)&&(a+c>b)&&(abs(a-c)<b&&(b+c>a)&&(abs(b-c)<a))) return 1;else return 0;}
};
class circle:public shape
{ double r;
public:
circle(double m){r=m;}
virtual double area()const{cout<<"圆的面积是 "<<endl;return(3.14*r*r);}
virtual double zhouchang()const{cout<<"圆的的周长是 "<<endl;return(2*3.14*r);}
void showr(){cout<<"圆的半径"<<r<<endl;}
{ double r;
public:
circle(double m){r=m;}
virtual double area()const{cout<<"圆的面积是 "<<endl;return(3.14*r*r);}
virtual double zhouchang()const{cout<<"圆的的周长是 "<<endl;return(2*3.14*r);}
void showr(){cout<<"圆的半径"<<r<<endl;}
};
class juxing:public shape
{ double chang,kuan;
public:
juxing(double x,double y){chang=x;kuan=y;}
virtual double area()const{cout<<"矩形的面积是"<<endl;return(chang*kuan);}
virtual double zhouchang()const{cout<<"矩形周长是 "<<endl;return(chang*2+kuan*2);}
void showchang(){cout<<"矩形的长为 "<<chang<<endl;}
void showkuan(){cout<<"矩形的宽为"<<kuan<<endl;}
{ double chang,kuan;
public:
juxing(double x,double y){chang=x;kuan=y;}
virtual double area()const{cout<<"矩形的面积是"<<endl;return(chang*kuan);}
virtual double zhouchang()const{cout<<"矩形周长是 "<<endl;return(chang*2+kuan*2);}
void showchang(){cout<<"矩形的长为 "<<chang<<endl;}
void showkuan(){cout<<"矩形的宽为"<<kuan<<endl;}
};
void fn(const shape& s)
{cout<<s.area()<<endl;
cout<<s.zhouchang ()<<endl;
{cout<<s.area()<<endl;
cout<<s.zhouchang ()<<endl;
}
void main()
{
circle m(3);
m. showr();
fn(m);
juxing n(3,5);
n. showchang();
n. showkuan();
fn(n);
n. showchang();
n. showkuan();
fn(n);
sanjiaoxing p(3,4,7);
p. showa();
p. showb();
p. showc();
p.panduan ();
fn(p);
}
判断三条边能不能构成三角形 有点问题 帮我改改吧
就是如果能构成三角形的话 执行输出周长和面积 如果构不成的话就不执行