c++实验-大作业-简单类的定义与实现(实验报告)_第1页
c++实验-大作业-简单类的定义与实现(实验报告)_第2页
c++实验-大作业-简单类的定义与实现(实验报告)_第3页
c++实验-大作业-简单类的定义与实现(实验报告)_第4页
c++实验-大作业-简单类的定义与实现(实验报告)_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上 课程名称: 面向对象程序设计 实验项目名称: 大作业:简单类的定义与实现 学院: 计算机与软件学院 专业: 实验时间: 2010-11-22 实验报告提交时间: 2010-11-26 教务处制实验目的与要求:类与对象的基本概念实验内容、方法、过程:实验内容:学校招生办在录取当年新生时已为每个新生建立了一个新生基础类Base,其中包含有每位新生的基本资料:学号(long num)、姓名(char name20)、性别(int sex:其中0表示男,1表示女)、年龄(int age)、住址(char addr30)、主修专业(char mdept30)。新生主修专业所在

2、系又在学生基本资料的基础上为每位该系新生建立一个主修类First,其中除了包含原来新生资料外,还设有新生主修成绩(float Mscore60)。为了促进复合型人才培养,学生在二年级可辅修另外一个专业课程。辅修接收系又为每位辅修本系第二学位同学建立一个辅修类Fbase,其中除了学生基本资料外,还设有辅修专业名称(char fdep30)、辅修成绩表(设为float Fscore4)。现假设:招生办工作人员只能访问到学生基本资料;主修系教务员只能访问到学生的基本资料和主修相关资料(但不能修改学生的基本资料);辅修系接收教务员只能访问(但不能修改)学生的基本资料和辅修相关资料;设某系现有6名学生,

3、其中有4名辅修了某系课程。期末考试时,主修系共考了5门课,辅修共考了4门课,设成绩均用百分制(int)表示。考完试后,进行下列工作:1)主修系教务员输入每位同学成绩;2)辅修系接收教务员输入每位辅修同学成绩;输入结束后:3)主修系教务员统计出期末考中至少有3门(含3门)以上课程成绩在85分(含85分)以上、其余课程成绩不低于70分的同学并显示出其相关资料;4)主修系教务员还要统计出需要参加补考的同学及其相关资料;5)辅修接收系教务员要统计出需要参加补考的辅修同学并显示出其相关资料;实验要求:1) 请按照以上的条件给出新生基础类的定义与说明。2) 给出三个不同教师角色的定义与说明。3) 在前面实

4、验的基础上,利用类与继承设计并实现出满足上述要求的类。4) 编出一个模拟程序模拟招生办工作人员、主修系教务员、辅修接收系教务员的操作且实现其工作要求。主要程序:#include<iostream>using namespace std;class Baseprivate:long num;char name20;int sex;int age;char addr30;char mdept30;public:void set_Base(long number,char *p_name,int the_sex,int the_age,char *p_addr,char *p_mdept

5、);void print();void Base:set_Base(long number,char *p_name,int the_sex,int the_age,char *p_addr,char *p_mdept)num=number;strcpy(name,p_name);sex=the_sex;age=the_age;strcpy(addr,p_addr);strcpy(mdept,p_mdept);void Base:print()cout<<"Number: "<<num<<endl;cout<<"Na

6、me: "<<name<<endl;cout<<"Sex: "if(sex=0)cout<<"male"<<endl;elsecout<<"female"<<endl;cout<<"Age: "<<age<<endl;cout<<"Address: "<<addr<<endl;cout<<"First Spec

7、ialty: "<<mdept<<endl;class First:public Baseprivate:float Mscore60;public:void get_Mscore(float the_Mscore,int n) int i;for(i=0;i<n;i+)the_Mscorei=Mscorei;void set_First(float the_Mscore,int n)int i;for(i=0;i<n;i+)Mscorei=the_Mscorei;void print1()int i;for(i=0;i<5;i+)cout&

8、lt;<"Mscore "<<i+1<<" :"<<Mscorei<<endl;class Fbase:public Firstprivate:char fdep30;float Fscore4;public:void get_Fscore(float the_Fscore,int n)int i;for(i=0;i<n;i+)the_Fscorei=Fscorei;void set_Fbase(char *p_fdep,float the_Fscore)int i;strcpy(fdep,p_

9、fdep);for(i=0;i<4;i+)Fscorei=the_Fscorei;void print2()int i;cout<<"Elective: "<<fdep<<endl;for(i=0;i<4;i+)cout<<"Fscore "<<i+1<<" :"<<Fscorei<<endl;class BTeacherpublic:void set_BTeacher(Base &a,long number,char

10、*p_name,int the_sex,int the_age,char *p_addr,char *p_mdept)a.set_Base(number,p_name,the_sex,the_age,p_addr,p_mdept);class FTeacher:private BTeacherpublic:void set_Fscore(First &a,float the_Mscore,int n)a.set_First(the_Mscore,n);void statistics(First a)int i,j=0,k=0,p=0;float the_Mscore60;a.get_M

11、score(the_Mscore,5);for(i=0;i<5;i+)if(the_Mscorei>=85)j+;if(the_Mscorei<=85&&the_Mscorei>=70)k+;if(the_Mscorei<60)p+;if(j>=3&&k>=2|j>=4&&k>=1|j>=5)cout<<"The excellent student of main subject is :"<<endl;a.print();a.print1()

12、;cout<<endl;if(p>0)cout<<"The failed student of main subject is :"<<endl;a.print();a.print1();cout<<endl;class FbTeacher:private FTeacherpublic:void set_Fbscore(Fbase &a,char *p_fdep,float the_Fscore)a.set_Fbase(p_fdep,the_Fscore);void Fb_statistics(Fbase a)i

13、nt i,j=0;float the_Fscore4;a.get_Fscore(the_Fscore,4);for(i=0;i<4;i+)if(the_Fscorei<60)j+;if(j>0)cout<<"The failed student of elective is: "<<endl;a.print();a.print1();a.print2();cout<<endl;void main()int i;float score5;First s1,s2;Fbase s3,s4,s5,s6;BTeacher t1;F

14、Teacher t2;FbTeacher t3;t1.set_BTeacher(s1,01,"Zhang San",0, 19,"Qing songzhai","Management");t1.set_BTeacher(s2,02,"Li Si",0,20,"Hua chen","Economy");t1.set_BTeacher(s3,03,"Chen Wu",0,19,"Chuan hua","Computer"

15、);t1.set_BTeacher(s4,04,"Huang Liu",1,21,"Hong Douzhai","Law");t1.set_BTeacher(s5,05,"Deng Qi",1,20,"Zi Weizhai","English");t1.set_BTeacher(s6,06,"Zhen Ba",0,20,"Yun Zhuge","Mathematics");cout<<"Main

16、 teachers input the scores: "<<endl;cout<<"For student 1 :"for(i=0;i<5;i+)cin>>scorei;t2.set_Fscore(s1,score,5);cout<<"For student 2 :"for(i=0;i<5;i+)cin>>scorei;t2.set_Fscore(s2,score,5);cout<<"For student 3 :"for(i=0;i<

17、;5;i+)cin>>scorei;t2.set_Fscore(s3,score,5);cout<<"For student 4 :"for(i=0;i<5;i+)cin>>scorei;t2.set_Fscore(s4,score,5);cout<<"For student 5 :"for(i=0;i<5;i+)cin>>scorei;t2.set_Fscore(s5,score,5);cout<<"For student 6 :"for(i=0;i

18、<5;i+)cin>>scorei;t2.set_Fscore(s6,score,5);cout<<"The minor teachers input the scores: "<<endl;cout<<"For student 1 :"for(i=0;i<4;i+)cin>>scorei;t3.set_Fbscore(s3,"Physics",score);cout<<"For student 2 :"for(i=0;i<4

19、;i+)cin>>scorei;t3.set_Fbscore(s4,"Computer",score);cout<<"For student 3 :"for(i=0;i<4;i+)cin>>scorei;t3.set_Fbscore(s5,"Economy",score);cout<<"For student 4 :"for(i=0;i<4;i+)cin>>scorei;t3.set_Fbscore(s6,"English"

20、,score);t2.statistics(s1);t2.statistics(s2);t2.statistics(s3);t2.statistics(s4);t2.statistics(s5);t2.statistics(s6);t3.Fb_statistics(s3);t3.Fb_statistics(s4);t3.Fb_statistics(s5);t3.Fb_statistics(s6);程序截图如下:预设程序步骤:1) 招生办工作人员输入学生的基本信息2) 主修系教务员输入学生主修科目成绩3) 辅修系教务员输入学生辅修科目成绩4) 主修系教务员根据学生成绩打印出成绩优秀的学生和需补考

21、学生的信息5) 辅修系教务员根据学生成绩打印出需要补考学生的信息根据程序设计步骤,编写各个类,弄清楚每个类之间的继承关系,画出类的结构层次图。类层次示意图:数据处理分析:学生的姓名,学号,性别等设置为private,还设置了两个公有成员函数set_Base();和print();分别用来设置和打印学生的基本信息,这些都是基类Base的内容。因为无论学生是否有主修和辅修,基本信息都是其共同特征,所以通过公有继承产生派生类First。又在First中增加主修学生的特有数据成员Mscore和三个新的成员函数:get_Mscore();set_First();print1();用以设置和打印主修成绩。

22、又因为如果有辅修的学生,其都有基本信息和主修科目与成绩,所以First类通过公有继承产出派生类Fbase。又在Fbase中增加辅修学生的特有数据成员fdep,Fscore和三个新的成员函数:get_Fscore();set_Fbase();print2();用以设置和打印副修成绩。另外又设置一个招生办工作人员类BTeacher,其主要功能有设置学生的基本信息。所以有一个成员函数set_BTeacher();其中类Base作为参数传入函数内,让BTeacher类可以访问和设置到学生的基本信息。因为主修系教务员只能访问到学生的基本资料和主修相关资料(但不能修改学生的基本资料),所以用私有继承产生派生类FTeacher,其新增了统计学生成绩的函数statisti

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论