第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
相关文章推荐
- 第2周项目2-程序的多文件组织
- 第二周—项目二-程序的多文件组织
- C++第6周(春)项目3 用多文件组织多个类的程序
- 第三周项目3--程序的多文件组织
- 第2周 项目2 - 程序的多文件组织
- 第二周项目2 程序的多文件组织
- 第二周 项目2- 程序的多文件组织
- 第二周项目2-程序的多文件组织
- 第2周【项目2 - 程序的多文件组织】
- 第二周项目实践--程序的多文件组织
- 项目2—程序的多文件组织
- 第11周项目3-程序的多文件组织
- 第十一周项目3-程序的多文件组织
- 第3周项目4-考了语文数学的学生(多文件形式组织程序)
- 第五周项目三 程序的多文件组织
- 第三周项目3-程序的多文件组织
- 第十一周 项目6:(5)多文件组织程序
- 第2周项目2程序的多文件组织
- 第11周 项目3 程序的多文件组织
- 第三周项目三 程序的多文件组织(三角形类)