欢迎来到天天文库
浏览记录
ID:37758574
大小:466.50 KB
页数:15页
时间:2019-05-30
《实验一 类与对象的定义和使用》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验一类与对象的定义和使用《C++程序设计》实验报告题目:类与对象的定义和使用姓名日期实验环境VisualC++6.0实验内容与完成情况实验目的:1,掌握类定义的语法2,掌握构造函数与析构函数的定义3,掌握返回对象的函数调用过程实验内容:1,完成类的定义定义学生类student,其属性有学号ID、姓名name、课程名course、成绩score2,定义中包含构造函数、析构函数提供不同的构造函数以不同方式构造对象(定义对象不初始化、定义对象初始化、用已有对象定义新对象),并定义show函数显示对象的所有信息3,定义相关功能函数定义计算对象数
2、组中多个对象的最高分max函数、计算最低分的min函数、计算平均分的average函数4,设计main函数创建对象数组,存放多个对象元素调用max函数、min函数、average函数计算最高分、最低分、平均分并输出结果源程序代码:#include#includeusingnamespacestd;classstudent{intID;stringname;stringcourse;floatscore;public:student(inta=1000,stringb="未命名",stringc="未知"
3、,floatd=0)第15页{ID=a;name=b;course=c;score=d;cout<<"构造函数调用"<4、t=*p;for(inti=1;igetscore())t=*p;returnt;}studentmin(student*p,intn){studentt;t=*p;for(inti=1;ip->getscore())t=*p;returnt;}floataverage(student*p,intn){floatt=0;for(inti=0;igetscore();returnt/n;}vo5、idmain(){studentsmax,smin;floatave;students[5]={student(1001,"张三","女",89),student(1001,"李四","男",59),student(1001,"王五","男",80),student(1001,"赵六","女",100),student(1001,"孙七","男",70)};第15页smax=max(s,5);cout<<"最高分学生信息如下:"<6、l;smin.show();cout<<"平均分是:"<#includeusingnamespacestd;cl7、assStudent{private:stringNum;stringName;floatheight;floatweigth;floatScore;public:Student(stringNum,stringName,floatheight,floatweigth,floatScore){this->Num=Num;this->Name=Name;this->height=height;this->weigth=weigth;this->Score=Score;}~Student(){}voidoutput()//输出{cout<8、um<<"t"<
4、t=*p;for(inti=1;igetscore())t=*p;returnt;}studentmin(student*p,intn){studentt;t=*p;for(inti=1;ip->getscore())t=*p;returnt;}floataverage(student*p,intn){floatt=0;for(inti=0;igetscore();returnt/n;}vo
5、idmain(){studentsmax,smin;floatave;students[5]={student(1001,"张三","女",89),student(1001,"李四","男",59),student(1001,"王五","男",80),student(1001,"赵六","女",100),student(1001,"孙七","男",70)};第15页smax=max(s,5);cout<<"最高分学生信息如下:"<6、l;smin.show();cout<<"平均分是:"<#includeusingnamespacestd;cl7、assStudent{private:stringNum;stringName;floatheight;floatweigth;floatScore;public:Student(stringNum,stringName,floatheight,floatweigth,floatScore){this->Num=Num;this->Name=Name;this->height=height;this->weigth=weigth;this->Score=Score;}~Student(){}voidoutput()//输出{cout<8、um<<"t"<
6、l;smin.show();cout<<"平均分是:"<#includeusingnamespacestd;cl
7、assStudent{private:stringNum;stringName;floatheight;floatweigth;floatScore;public:Student(stringNum,stringName,floatheight,floatweigth,floatScore){this->Num=Num;this->Name=Name;this->height=height;this->weigth=weigth;this->Score=Score;}~Student(){}voidoutput()//输出{cout<8、um<<"t"<
8、um<<"t"<
此文档下载收益归作者所有