#include<iostream>
#include<cmath>
using namespace std;
class Triangle
{
public:
double perimeter();//计算三角形的周长
double area();//计算并返回三角形的面积
void showMessage();
Triangle(double x, double y, double z) :a(x), b(y), c(z){};//用参数初始化表实现
private:
double a, b, c; //三边为私有成员数据
};
void Triangle::showMessage()
{
cout << "三角形的三边长分别为:" << a << ' ' << b << ' ' << c << endl;
cout << "该三角形的周长为" << perimeter() << ",面积为:" << area() << endl << endl;
}
double Triangle::perimeter()
{
return(a + b + c);
}
double Triangle::area()
{
double p = (a + b + c) / 2;
return sqrt((p - a)*(p - b)*(p - c) + p);
}
int main(){
Triangle Tri(7, 8, 9); //定义三角形类的一个实例(对象)
Tri.showMessage();
getchar();
return 0;
}
#include<cmath>
using namespace std;
class Triangle
{
public:
double perimeter();//计算三角形的周长
double area();//计算并返回三角形的面积
void showMessage();
Triangle(double x, double y, double z) :a(x), b(y), c(z){};//用参数初始化表实现
private:
double a, b, c; //三边为私有成员数据
};
void Triangle::showMessage()
{
cout << "三角形的三边长分别为:" << a << ' ' << b << ' ' << c << endl;
cout << "该三角形的周长为" << perimeter() << ",面积为:" << area() << endl << endl;
}
double Triangle::perimeter()
{
return(a + b + c);
}
double Triangle::area()
{
double p = (a + b + c) / 2;
return sqrt((p - a)*(p - b)*(p - c) + p);
}
int main(){
Triangle Tri(7, 8, 9); //定义三角形类的一个实例(对象)
Tri.showMessage();
getchar();
return 0;
}