- /*
- * 文件名称:Ex5-6.cpp
- * 作 者:徐浩宁
- * 完成日期:2017 年 4 月 24 日
- * 版 本 号:v1.0
- * 对任务及求解方法的描述部分: 下面设计一个三角形类,请给出各成员函数的定义
- * 输入描述:
- * 问题描述:
- * 程序输出:
- * 问题分析:
- * 算法设计:
- class Triangle
{public:
void Setabc(float x, float y, float z);
void Getabc(float *x, float *y, float *z);
float Perimeter(void);
float Area(void);
private:
float a,b,c;
#include <iostream>
#include <Cmath>
#include "Triangle.h"
using namespace std;
void main(void)
{ Triangle Tri1;
Tri1.Setabc (4,5,6);
float x,y,z;
Tri1.Getabc (&x,&y,&z);
cout<<"三条边为:"<<x<<'\t'<<y<<'\t'<<z<<endl;
cout<<"三角形的周长为:"<< Tri1.Perimeter()<<'\t'<<"面积为:"<< Tri1.Area()<<endl;
system ("PAUSE");
}
#include <iostream>
#include <Cmath>
#include "Triangle.h"
using namespace std;
void Triangle::Setabc(float x, float y, float z)
{
cout << "请输入三角形三边值:" << endl;
cout << "数据违法!请重新输入: ";
else
break;
}*/
a = x;
b = y;
c = z;
}
void Triangle::Getabc(float *x, float *y, float *z)
{
*x = a;
*y = b;
*z = c;
}
float Triangle::Perimeter(void)
{
int l;
l = a + b + c;
return (l);
}
float Triangle::Area(void)
{
double s,m;
m = (a + b + c) / 2;
s = sqrt((m - a) * (m - b) * (m - c));
return (s);
} - 二.运算结果
-