第五周实验报告1
来源:互联网 发布:淘宝修改差评链接地址 编辑:程序博客网 时间:2024/05/16 17:09
/* (程序头部注释开始)* 程序的版权和版本声明部分* Copyright (c) 2011, 烟台大学计算机学院学生 * All rights reserved.* 文件名称: class Triangle * 作 者: 刘程程 * 完成日期: 2012 年 03 月 19 日* 版 本 号: 1.0 * 对任务及求解方法的描述部分* 输入描述:三角形的三边 * 问题描述: 计算周长和面积* 程序输出: 三角形的周长和面积* 程序头部的注释结束*/(1)使用带参数构造函数,即Triangle(float x, float y, float z),三边长在调用时由实参直接给出; #include<iostream>#include<cmath>using namespace std;class Triangle{public: Triangle(float, float, float); float perimeter(void);//计算三角形的周长 float area(void);//计算并返回三角形的面积 void showMessage();private: float a,b,c; //三边为私有成员数据};Triangle :: Triangle(float x, float y, float z){ a = x; b = y; c = z;}float Triangle :: perimeter(void){ float t; t = a + b + c; return t;}float Triangle :: area(void){ float s, f; s = (a + b + c)/2; f = sqrt(s * (s - a)*(s - b)*(s - c) ); return f;}void Triangle:: showMessage(){ cout<<"三角形的三边长分别为:"<<a<<" "<<b<<" "<<c<<endl; cout<<"该三角形的周长为:"<< perimeter()<<'\t'<<"面积为:"<< area()<<endl;}void main(void){ Triangle Tri2(7,8,9); //定义三角形类的一个实例(对象) Tri2.showMessage();}
感悟:通过反复的改错,我更加深刻了解了类及对象。
- 第五周实验报告1
- 第五周实验报告1
- 第五周实验报告1
- 第五周实验报告1
- 第五周实验报告1
- 第五周实验报告1
- 第五周实验报告1
- 第五周实验报告任务1-1
- 第五周实验报告 1-1
- 《第五周实验报告任务1》
- 第五周实验报告(任务1)
- 第五周实验报告(1)
- 第五周实验报告(任务1)
- 第五周实验报告 1-2
- 第五周实验报告1-3
- 第五周实验报告1-4
- 第五周实验报告1-5
- 第五周实验报告(1-2)
- 5-3 类的应用——求长方体的面积体积
- 架构师之路(转载)
- 2012年 上半年 第三周 C++程序设计 (七)
- 两台电脑间文件传输Java编程源代码
- vs 调试
- 第五周实验报告1
- NAL的基本特征
- C++程序设计实验报告《一》(2)
- jQuery对象与dom对象的联系、区别和转换
- 用代码来解释警察和小偷的一个悖论
- 第五周实验报告一——(1)
- 隐藏的<tbody>
- Run Loop
- Android Service 服务 —— Service