您的位置:首页 > 其它

第04周:项目三:程序的多文件组织

2014-03-23 21:22 148 查看
/*
* Copyright (c) 2014, 烟台大学计算机学院
* All rights reserved.
* 作    者:王颖
* 完成日期:2014 年 3 月 17 日
* 版 本 号:v1.0
* 输入描述: 无
* 问题描述:程序的多文件组织
* 程序输出:略
* 问题分析:略
* 算法设计:略
*/
#include <iostream>
#include<cmath>
#include "triangle.h"
using namespace std;
int main()
{
    Triangle tri1;
    double x,y,z;
    cout<<"请输入三角形的三边:";
    cin>>x>>y>>z;
    tri1.setA(x);
    tri1.setB(y);
    tri1.setC(z);
    if(tri1.isTriangle())
    {
        cout<<"三条边为:"<<tri1.getA()<<","<<tri1.getB()<<","<<tri1.getC()<<endl;
        cout<<"三角形的周长为:"<<tri1.perimeter()<<'\t'<<"面积为:"<<tri1.area()<<endl;
    }
    return 0;
}
#include <iostream>
#include<cmath>
#include "triangle.h"
using namespace std;
bool Triangle::isTriangle()
{
    bool flag=true;
    if((a+b)<=c||(a+c)<=b||(b+c)<=a)
    {
        cout<<"您输入的数字不能构成三角形"<<endl;
        flag=false;
    }
    return flag;
}
double Triangle::perimeter()
{
    double l;
    l=a+b+c;
    return l;
}
double Triangle::area()
{
    double s,p;
    p=(a+b+c)/2;
    s=sqrt(p*(p-a)*(p-b)*(p-c));
    return s;
}


#ifndef TRIANGLE_H_INCLUDED
#define TRIANGLE_H_INCLUDED

class Triangle
{
    private:
    double a,b,c;
    public:
    void setA(double d)
    {
        a=d;
    }
    void setB(double e)
    {
        b=e;
    }
    void setC(double f)
    {
        c=f;
    }
    double getA()
    {
        return a;
    }
    double getB()
    {
        return b;
    }
    double getC()
    {
        return c;
    }
    bool isTriangle();
    double perimeter();
    double area();
};

#endif // TRIANGLE_H_INCLUDED






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: