第3周项目3--多文件组织三角形
2015-03-21 10:16
211 查看
/* * Copyright (c) 2015, 烟台大学计算机学院 * All rights reserved. * 文件名称:test.cpp * 作 者:姜甜甜 * 完成日期:2015年 3 月 19日 * 版 本 号:v1.0 * * 问题描述: 利用多文件组织,实现项目2主文件: main.cpp,用于定义main()函数 头文件: triangle.h,头文件,声明类,定义内置成员函数类 定义文件: triangle.cpp,用于定义类Triangle中其他成员函数 注意,将3个set函数和3个get函数设计成内置成员函数,其他函数不作为内置函数。
main.cpp
#include <iostream> #include "student.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; } else cout<<"不能构成三角形"<<endl; return 0; }
student.cpp
#include "student.h" #include<cmath> double Triangle::perimeter() { return x+y+z; } double Triangle::area() { double p; p=(x+y+z)/2; p=sqrt(p*(p-x)*(p-y)*(p-z)); return p; } bool Triangle::isTriangle() { if((x+y)>z&&(x+z)>y&&(y+z)>x) return true; else return false; }
student.h
#ifndef STUDENT_H_INCLUDED #define STUDENT_H_INCLUDED class Triangle { private: double x,y,z; public: inline void setA(double a) { x=a; } inline void setB(double b) { y=b; } inline void setC(double c) { z=c; } inline double getA() { return x; } inline double getB() { return y; } inline double getC() { return z; } double perimeter(); double area(); bool isTriangle(); }; #endif // STUDENT_H_INCLUDED
相关文章推荐
- 第3周项目3-三角形类(程序的多文件组织)
- 第3周项目3三角形类2的多文件组织形式
- 第2周-项目3-程序的多文件组织-三角形类
- 第3周项目5多文件组织
- 第3周 项目2—数据结构之自建算法库——顺序表 (程序的多文件组织形式)
- 第3周项目3——多文件组织
- 第3周 项目2——数据结构之自建算法库——顺序表(程序的多文件组织形式)
- 第4周-项目3-用多文件组织多个类的程序-三角形类
- 2015-第3周项目3-程序的多文件组织
- 第3周项目3 程序的多文件组织
- 6-4 三角形类(求面积,周长,判断直角,等腰...) 多文件组织项目
- 第六周项目四----用点类做成员的三角形类以及多文件组织的三角形类
- 第3周项目3多文件组织
- 第3周项目3-程序的多文件组织
- 第5周项目多文件组织三角形类
- 第五周项目三 对象作数据成员之三角形顶点类----多文件组织
- 第二学期第三周项目3 三角形类的多文件组织
- 第3周项目3-程序的多文件组织
- 第三周项目三 程序的多文件组织(三角形类)
- 第3周项目4-考了语文数学的学生(多文件形式组织程序)