一道C++ 改错
4.设计一个三角形类Triangle,包含三角形三条边长的私有数据成员,另有一个重载运算符“+”,以实现求两个三角形对象的面积之和。#include<iostream.h...
4.设计一个三角形类Triangle,包含三角形三条边长的私有数据成员,另有一个重载运算符“+”,以实现求两个三角形对象的面积之和。
#include<iostream.h>
#include<math.h>
class Triangle
{int x,y,z;
double area;
public:
Triangle(int i,int j,int k)
{double s;
s=i;y=j;z=k;
s=(x+y+z)/2.0;
area=sqrt(s*(s-x)*(s-y)*(s-z);}
};
void disparten()
{cout<<"Area="<<area<<endl;
}
friend double opertor(Triangle t1,Triangle t2)
{return t1.area+t2.area;
}
};
void main()
{Triangle t1(3,4,5),t2(4,5,6);
double s;
cout<<"t1" t1.disparm();
cour<<"t2" t2.disparm();
s=t1+t2;
cout<<"总面积"<<s<<endl;
} 展开
#include<iostream.h>
#include<math.h>
class Triangle
{int x,y,z;
double area;
public:
Triangle(int i,int j,int k)
{double s;
s=i;y=j;z=k;
s=(x+y+z)/2.0;
area=sqrt(s*(s-x)*(s-y)*(s-z);}
};
void disparten()
{cout<<"Area="<<area<<endl;
}
friend double opertor(Triangle t1,Triangle t2)
{return t1.area+t2.area;
}
};
void main()
{Triangle t1(3,4,5),t2(4,5,6);
double s;
cout<<"t1" t1.disparm();
cour<<"t2" t2.disparm();
s=t1+t2;
cout<<"总面积"<<s<<endl;
} 展开
展开全部
#include<iostream.h>
#include<math.h>
class Triangle
{
private:
int x,y,z;
double area;
public:
Triangle(int i,int j,int k)
{
double s;
s=i;
y=j;
z=k;
s=(x+y+z)/2.0;
area=sqrt(s*(s-x)*(s-y)*(s-z));
}
disparten()
{
cout<<"Area="<<area<<endl;
}
friend double operator + (Triangle t1,Triangle t2)
{
return t1.area+t2.area;
}
};
void main()
{
Triangle t1(3,4,5),t2(4,5,6);
double s;
cout<<"t1"<<t1.disparten();
cout<<"t2"<<t2.disparten();
s=t1+t2;
cout<<"总面积"<<s<<endl;
}
#include<math.h>
class Triangle
{
private:
int x,y,z;
double area;
public:
Triangle(int i,int j,int k)
{
double s;
s=i;
y=j;
z=k;
s=(x+y+z)/2.0;
area=sqrt(s*(s-x)*(s-y)*(s-z));
}
disparten()
{
cout<<"Area="<<area<<endl;
}
friend double operator + (Triangle t1,Triangle t2)
{
return t1.area+t2.area;
}
};
void main()
{
Triangle t1(3,4,5),t2(4,5,6);
double s;
cout<<"t1"<<t1.disparten();
cout<<"t2"<<t2.disparten();
s=t1+t2;
cout<<"总面积"<<s<<endl;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询