现在的位置: 首页 > 综合 > 正文

第五周任务1-2

2013年12月02日 ⁄ 综合 ⁄ 共 705字 ⁄ 字号 评论关闭
/* (程序头部注释开始)
* 程序的版权和版本声明部分
* Copyright (c) 2011, 烟台大学计算机学院学生 
* All rights reserved.
* 文件名称:                              
* 作    者:刘杨                             
* 完成日期:2012 年 3 月 21 日
* 版 本 号:          

* 对任务及求解方法的描述部分
* 输入描述: 
* 问题描述: 
* 程序输出: 
* 程序头部的注释结束
*/

#include<iostream>
#include<cmath>
using namespace std;
class Triangle
{
public:
	Triangle(){a=1;b=1;c=1;} //()设计默认构造函数,即不指定参数时,默认各边长为;  
	float Perimeter(void);
	float Area(void);
	void showMessage();
private:
	float a, b, c; 
};

void Triangle:: showMessage()
{
	cout << "三角形的三边长分别为:" << a << "," << b << "," << c << endl;
	cout << "该三角形的周长为:" << Perimeter() << endl << "面积为:" << Area() << endl << endl;
}

void main(void)
{
	Triangle Tri1;	
	Tri1.showMessage();
}

float Triangle :: Perimeter(void)//计算三角形的周长   
{  
    float d;  
    d=a+b+c;  
    return d;  
}  
  
float Triangle :: Area(void)//计算并返回三角形的面积   
{  
    float p, s;  
    p=(a+b+c)/2;  
    s=sqrt(p*(p-a)*(p-b)*(p-c));  
    return s;  
}  
 
运行结果:

抱歉!评论已关闭.