已阅读5页,还剩3页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
福建工程学院计算机与信息科学系实验报告 2012 2013 学年第 一 学期 任课老师: 林芳 课程名称面向对像程序设计班级软件1101座号10姓名程康实验题目实验二 面向对像编程 实验时间实验日期: 2012-9-11 提交日期: 2012-9-13 实验目的、要求实验目的: 掌握类与对象的定义方法,成员函数的实现与调用方法,领会类实现数据隐藏与封装的原理。实验要求: 在上机前写出全部源程序。实验题目1、 编写Circle类,有数据成员Radius, 成员函数get_area()用于计算面积, get_perimeter()用于计算周长, disp( )用于显示面积和周长, set_radius()设置半径, get_radius()获取半径。 完善必要的构造函数,构造一个Circle的对象进行测试,对构造函数和析构函数的调用情况进行分析。2、 编写圆柱体类Cylinder,有数据成员Circle对象和长度Len, 成员函数get_vol() 计算体积, get_area()计算表面积。完善必要的构造函数和拷贝构造函数,构造Cylinder的对象进行测试。对构造函数,拷贝构造函数和析构函数的调用情况进行分析。3、 设计学生类Stu,含no(学号),name(姓名),deg(成绩)数据成员,成员函数有setdata()用于设置对象,disp()用于输出8089分段学生数据。在main()中定义对象数组,用于存储输入学生数据。实验设计内容代码:第一题:/ 111111.cpp : 定义控制台应用程序的入口点。#include stdafx.h#include using namespace std;const float PI=3.14;class Circlepublic:Circle()cout构造函数被调用endl; Radius=0;/*赋予初值*/ ;float Radius; float set_radius(float r);/*设置圆半径*/float get_radius() /*获取圆半径*/return Radius;float get_area();/*用于计算面积*/float get_perimeter();/*用于计算周长*/ void disp(); /*用于显示面积和周长*/Circle()cout析构函数被调用endl;float Circle:set_radius(float r)Radius=r;return Radius;float Circle:get_area()return PI*Radius*Radius;float Circle:get_perimeter()return 2*PI*Radius;void Circle:disp()coutradius is:Radiusendl;coutarea is:get_area()endl;coutperimeter is:get_perimeter()endl;getchar();int main()Circle circle;float radius;coutinput the radiu:radius;circle.set_radius(radius);circle.get_radius();circle.disp();getchar();第二题:/ 222222.cpp : 定义控制台应用程序的入口点。#include stdafx.h#include using namespace std;const float PI=3.14;class Circlepublic:Circle()cout构造函数被调用endl;Radius=0;/*赋予初值*/ ;float Radius;float set_radius(float r);/*设置圆半径*/float get_radius() /*获取圆半径*/return Radius;float get_area();/*用于计算面积*/float get_perimeter();/*用于计算周长*/void disp(); /*用于显示面积和周长*/Circle()cout析构函数被调用endl;float Circle:set_radius(float r)Radius=r;return Radius;float Circle:get_area()return 2*PI*Radius;float Circle:get_perimeter()return PI*Radius*Radius;class Cylinderpublic:Cylinder() cout构造函数被调用endl; ;Circle cir;float len,s,l;Cylinder(Circle &r);float get_vol();float get_area();Cylinder()cout析构函数被调用endl;Cylinder:Cylinder(Circle &r)cout拷贝构造函数被调用!endl;float Cylinder:get_vol()return len*s;float Cylinder:get_area()return 2*s+l*len;int main()Cylinder c;float r;coutplease input the radius :r;coutplease input the len :c.len;Circle circle;circle.set_radius(r);Cylinder cylinder(circle);c.s=circle.get_area();c.l=circle.get_perimeter();coutThe cylinders vol is:c.get_vol()endl;coutThe cylinders area is:c.get_area()endl;getchar();getchar();第三题:/ 3333333.cpp : 定义控制台应用程序的入口点。#include stdafx.h#include #include using namespace std;const int MAX=100;/*设置学生类Stu,包含no(学号),name(姓名),deg(成绩)数据成员*/class Stuprivate:string no;string name;float deg;public:void setdata(Stu students,int n);void disp(Stu students,int n);/*设置对象,输入学生信息*/void Stu:setdata(Stu students,int n)for (int i=1;i=n;i+)coutinput the No of the nmnber i student no: studentsi.no;coutinput the name of the number i student name: ;coutinput the deg of the number i student deg: studentsi.deg;/*输出分段学生*/void Stu:disp(Stu students,int n)coutNotnametdegendl;for (int i=1;i=80&studentsi.deg=89)tstudentsi.degendl;getchar();int main()Stu studentsMAX;/*定义对象数组,存储输入学生数据*/Stu a;int n;coutinput the number of the students :n;a.setdata(students,n);a.disp(students,n);getchar()
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026 年防范台风大风与山区地质灾害风险
- 2026事业单位工勤技能-上海-上海中式面点师一级(高级技师)历年参考题库含答案详解3套试卷
- 导游行业职业发展现状分析
- 2026年秋季开学高三信念的力量主题班会课件
- 2026年秋季开学初三好心态决定好成绩晨会讲话课件
- 2026年秋季开学大学一年级新生军训敬礼礼毕心理课件
- 硫酸铜参比电极的工程应用与技术发展趋势
- 2025-2026学年江苏省宿迁市宿豫区中考试题猜想数学试卷含解析
- 2026年海南省海口市琼山区中考数学最后一模试卷含解析
- 2025年河南省信阳市卫生行政系统人员招聘笔试试题及答案解析
- 浙江金石亚药医药科技有限公司迁扩建项目环评报告
- 矿山爆破管理办法
- 四川省成都市2023级(2026届)高中毕业班摸底测试数学
- 扣件清理活动方案
- 科技特派团内部管理制度
- JG/T 14-2010通风空调风口
- 2025年江苏省c类行测真题及答案解析
- 招商岗位测试题及答案
- 医院后勤管理与设备职责
- 家居与室内设计培训资料
- 周三多-管理学:原理与方法(第七版),第三章
评论
0/150
提交评论