欢迎来到天天文库
浏览记录
ID:38701461
大小:83.50 KB
页数:29页
时间:2019-06-17
《沈阳理工C++上机实验》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、实验:定义学生类,在主函数中定义对象的同时初始化各数据成员的值,调用成员函数实现对数据的输出#include#includeusingnamespacestd;classstudent{private:intnumble;stringname;intage;public:student(stringn,intnum,inta);~student();voidShow();};student::student(stringn,intnum,inta){name=n;numble=num;age=a
2、;}voidstudent::Show(){cout<<"name:"<usingnamespacestd;#includeconstdoublePI=3.14159;cla
3、ssCircle//圆类{private:doubler;//圆的半径public:Circle(doubler=0)//构造函数{this->r=r;}~Circle()//析构函数{}doubleArea()//圆面积{returnPI*r*r;}doublePerim()//圆周长{return2*PI*r;}voidShow()//输出圆的面积和周长{cout<<"Areais:"<
4、er=12.5;cout<<"Circle:"<usingnamespacestd;classUndergraduate{protected:lo
5、ngid;char*name;char*major;public:Undergraduate(longid_val,char*name_val,char*major_val){id=id_val;name=newchar[50];strcpy(name,name_val);major=newchar[50];strcpy(major,major_val);}virtualvoidshowInfo();~Undergraduate(){deletename;deletemajor;}};voidUndergraduate::show
6、Info(){cout<<"学号"<7、char[100];strcpy(tutor,tutor_val);paperNumber=paperNumber_val;}voidshowInfo(){cout<<"学号"<8、ategraduate(2003131452,"Jack","计算机","kate",10);undergraduate.showInfo();graduate.showInfo();return0;}实验:描述一个学校的情况,描述对象包括教师和学
7、char[100];strcpy(tutor,tutor_val);paperNumber=paperNumber_val;}voidshowInfo(){cout<<"学号"<8、ategraduate(2003131452,"Jack","计算机","kate",10);undergraduate.showInfo();graduate.showInfo();return0;}实验:描述一个学校的情况,描述对象包括教师和学
8、ategraduate(2003131452,"Jack","计算机","kate",10);undergraduate.showInfo();graduate.showInfo();return0;}实验:描述一个学校的情况,描述对象包括教师和学
此文档下载收益归作者所有