类的例子

合集下载
相关主题
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
double triangle::triclength(double a,double b,double c)
{
double res;
res=a+b+c;
return res;
}
main ()
{
triangle tri;
double a,b,c;
cin>>a>>b>>c;
cout<<"三角形周长:"<<tri.triclength(a,b,c)<<endl<<"三角形面积:"<<tri.triarea(a,b,c)<<endl;
res=sqrt(real*real+imag*imag);
return res;
}
main()
{
complex comp1;
double a,b;
cin>>a>>b;
comp1.getcomp(a,b);
comp1.putcomp();
cout<<comp1.lengthcomp()<<endl;
else
cout<<"不是圆"<<endl;
return 0;
}
private:
double a;
doubleb;
doublec;
};
double triangle::triarea(double a,double b,double c)
{
double s,res;
s=(a+b+c)/2.0;
res=sqrt(s*(s-a)*(s-b)*(s-c));
return res;
return 0;
}
2.三角形类:
#include <iostream.h>
#include <math.h>
class triangle
{
public:
double triarea(double ,double ,double);
double triclength(double ,double ,double);
};
void complex::getcomp(double r,double i)
{
real=r;
imag=i;
}
void complex::putcomp()
{
cout<<real<<"+"<<imag<<"i"<<endl;
}
double complex::lengthcomp()
{
double res;
return 0;
}
3.圆类:
#include <iostream.h>
#define PI 3.14
class circle
{
public:
double area(double);
double clength(double);
private:
double r;
};
double circle::area(double r)
1.复数的类
#include <iostream.h>
#include <math.h>
class complex
{
public:
void getcomp(double ,double);
void putcomp();
double lengthcomp();
public:
double real;
double imag;
{
double res;
res=PI*r*r;
return res;
}
double circle::clength(double r)
{
double res;
res=2*PI*r;
return res;
}
main ()
{
circle cir;
double源自文库r;
cin>>r;
if (r>=0)
cout<<"周长:"<<cir.clength(r)<<endl<<"面积:"<<cir.area(r)<<endl;
相关文档
最新文档