预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共13页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

实验四对象数组和对象指针 一、实验目的和要求 掌握对象数组、对象指针及其使用方法; 理解常对象的使用。 二、实验内容和结果 建立对象数组,放5个学生的数据(学号、成绩),用指针指向数组首元素,输出第1,3,5个学生的数据。Student类,包含学生的基本信息:学号、姓名、性别、出生日期、年级、班级、院系和专业等。有构造函数(缺省构造函数、带参数的构造函数),析构函数。 #include<iostream> #include<string> usingnamespacestd; classstudent {private: longid; floatscore; stringname; charsex; intyear; intmonth; intday; stringgrade; stringbanji; stringzhuanye; stringyuanxi; public: ~student() {} voidout(); student(longa=10011,floatk=90,stringc="路江飞",chars='m', intz=1992,inty=4,intx=19,stringn="大二",stringb="class6", stringzuan="计算机",stringyuan="computer"); }; voidstudent::out() { cout<<"学号:"<<id<<endl; cout<<"成绩:"<<score<<endl; cout<<"姓名:"<<name<<endl; cout<<"性别:"<<sex<<endl; cout<<"生日:"<<year<<"/"<<month<<"/"<<day<<endl; cout<<"年级:"<<grade<<endl; cout<<"班级:"<<banji<<endl; cout<<"专业:"<<zhuanye<<endl; cout<<"学院:"<<yuanxi<<endl; cout<<endl; cout<<endl; } student::student(longa,floatk,stringc,chars,intz,inty, intx,stringn,stringb,stringzuan,stringyuan) { id=a; score=k; name=c; sex=s; year=z; month=y; day=x; grade=n; banji=b; zhuanye=zuan; yuanxi=yuan; } intmain() { studenta[5]={ student(), student(10011,92,"杨娇娇",'f',1992,4,18,"大二","class2","计算机","computer"), student(10012,93,"田振南",'m',1990,6,16,"大二","class3","计算机","computer"), student(10013,94,"张元元",'m',1992,8,15,"大二","class4","计算机","computer"), student(10014,97,"杨光琪",'m',1992,4,25,"大二","class5","计算机","computer") }; student*p=a; for(inti=0;i<5;i+=2,p+=2) (*p).out(); return0; } 实现公司员工的管理。设计employee类,其中包含职工员工的基本信息:编号、姓名、性别、出生日期和职务等。有构造函数(缺省构造函数、带参数的构造函数),析构函数。出生日期使用自定义的Date类。对象数组保存已输入的职工对象。程序的基本功能有: 职工信息的录入 职工信息的显示 可以修改人员的职务信息 通过编号或者姓名进行人员查询(红色字体部分可以不做) #include<iostream> #include<iomanip> #include<string> usingnamespacestd; classEmployee;classEmployeeSys; classDate { public: Date(); Date(inty,intm,intd):year(y),month(m),day(d){}; ~Date(){} voidoutput_date(); voidinput_date(); friendEmployee; private: intyear,month,day; }; classEmployee{ public: Employee(intnu=10010,stringna