百度空间 | 百度首页 | 登录 乘风破浪会有时,直挂云帆济沧海!编程日记,积累点点滴滴! 主页博客相册|个人档案 |好友 查看文章
C++课程设计-人事管理系统2007-12-21 18:22要求:
(1)设计一个人事管理的People(人员)类.考虑到通用性,这里只抽象出所有类型人员都具有的属性:name(姓名),number(编号),sex(性别),birthday(出生日期),id(身份证号)等等.其中"出生日期"定义为一个"日期"类(具有属性:year(年),month(月),date(日)内嵌子对象.用成员函数实现对人员信息的录入和显示等必要功能操作(自己独立思考设计).要求包括:构造函数和析构函数,拷贝构造函数,内联成员函数.
(2)从People(人员)类派生出student(学生)类,添加属性:班号char chassNO[7];从People类派生出teacher(教师)类,添加属性:职务char principalship[11],部门char department[21].从student类中派生出graduate(研究生)类,添加属性:专业char subject[21],导师teacher adviser(为(教师类内嵌子对象);从graduate类和teacher类派生出TA(助教生)类,注意虚基类的使用,重载相应的成员函数.
(3)对People类重载"=="运算符和"="运算符,"=="运算符判断两个People类对象的id属性是否相等;"="运算符实现People类对象的赋值操作.
(4)定义一个对People类对象数组按编号排序的函数,一个按编号查找people对象的函数.
(5)设计主控模块程序.
(6)对给出的程序源代码要给出各部分的详细注释.
相关程序代码为:这是我的课程设计,大家可以参考一下哦!不足之处还请大家多多指点哦!!!
#include<iostream>
#include <string.h>
using namespace std;
class day
{
public:
day(int y=0,int m=0,int d=0);
~day();
day(day&one);
void Setday();
void Getday();
private:
int year,month,date;
};
class people
{
public:
people();
people(char*name,int number,char*sex,char*id,day bir);
~ people();
void Setpeople();
void Getpeople();
void operator==(people p1);
void operator=(people p2);
char id[20];int number;
private:
char name[20]; char sex;day birthday;
};
//student类的定义
class student : public people
{ public:
student();
student(char*name,int number,char*sex,char*id,day bir,char*classNO);
void Setstudent1();
void Setstudent2();
void Getstudent1();
void Getstudent2();
~student();
private:
char classNO[7];
};
//teacher类的定义
class teacher: virtual public people
{public:
teacher();
~teacher();
teacher(teacher&a);
void Setteacher1();
void Setteacher2();
void Getteacher1();
void Getteacher2();
private:
char principalship[11];char department[21];
};
//graduate类的定义
class graduate:virtual public student
{
public:
graduate();
~graduate();
void Setgraduate1();
void Setgraduate2();
void Getgraduate1();
void Getgraduate2();
private
:
char subject[21]; teacher teacheradviser;
};
//TA类的定义
class TA: public graduate,public teacher
{
public:
TA();
~TA();
void SetTA();
void GetTA();
private:
int time;float pay;
};
//day类的实现
day::day(int y,int m,int d){ year=y;month=m;date=d;}
day::~day() {}
day::day(day&one)
{ date=one.date;
month=one.month;
year=one.year;
}
void day::Setday(){cout<<"请输入出生日期(年月日之间以空格键或回车键分开):";cin>>year>>month>>date;}
void day::Getday(){cout<<"出生日期为:"<<year<<"年"<<month<<"月"<<date<<"日"<<endl;}
//people类的实现
people::people(){}
people:: people(char*name,int number,char*sex,char*id,day bir){birthday=bir;}
people::~people(){}
void people::Setpeople()
{
cout<<"请输入姓名:";cin>>name;cout<<"请输入编号:";cin>>number;
cout<<"请输入该人的性别(x代表女,y代表男):";cin>>sex;cout<<"请输入身份证号码:";cin>>id;
birthday.Setday();
}
void people::Getpeople()
{
cout<<"该人的姓名为:"<<name<<endl<<"该人的编号为:"<<number<<endl;
cout<<"该人的性别为:";if(sex=='x')cout<<"女"<<endl; else cout<<"男"<<endl;
cout<<"该人的身份证号码为:"<<id<<endl;birthday.Getday();
}
void people::operator==(people p1)
{
if(id==p1.id)cout<<"这两个people类对象的id相同"<<endl;
else cout<<"这两个people类的对象的id不相同"<<endl;
}
void people::operator=(people p2)
{ people p;
strcpy(name,p2.name);number=p2.number;sex=p2.sex;strcpy(id,p2.id);birthday=p2.birthday; }
//student类的实现
student::student(){}
student::~student(){}
void student::Setstudent1(){people::Setpeople();}
void student::Setstudent2(){cout<<"请输入班号:";cin>>classNO;}
void student::Getstudent1(){people::Getpeople();}
void student::Getstudent2(){cout<<"该学生的班号为:"<<classNO<<endl;}
//teacher类的实现
teacher::teacher(){}
teacher::~teacher(){}
teacher::teacher(teacher&a){cout<<"拷贝构造函数被调用";}
void teacher::Setteacher1(){people::Setpeople();}
void teacher::Setteacher2(){cout<<"请输入老师的职务:";cin>>principalship;
cout<<"请输入老师的部门:";cin>>department;}
void teacher::Getteacher1(){people::Getpeople();}
void teacher::Getteacher2(){cout<<"该老师的职务是:" <<principalship<<endl<<"该老师的部门是:"<<department<<endl;}
//graduate类的实现
graduate::graduate(){}
graduate::~graduate(){};
void graduate::Setgraduate1(){student::Setstudent1();student::Setstudent2();}
void graduate::Setgraduate2(){ cout<<"请输入专业:";cin>>subject;cout<<"请输入导师的信息为:"<<endl;
teacheradviser.Setteacher1();teacheradviser.Setteacher2();}
void graduate::Getgraduate1(){student::Getstudent1();student::Getstudent2();}
void graduate::Getgraduate2(){cout<<"该研究生的专业为:"<<subject<<endl;cout<<"导师的信息为:"<<endl;
teacheradviser.Getteacher1();teacheradviser.Getteacher2();}
//TA类的实现
TA::TA(){}
TA::~TA(){}
void TA::SetTA(){student::Setstudent1();student::Setstudent2();graduate::Setgraduate2();
cout<<"请输入该助教生的助教信息:"<<endl;teacher::Setteacher2();
cout<<"请输入助教生的工作时间:";cin>>time;cout<<"请输入助教生的工资:";cin>>pay;}
void TA::GetTA(){student::Getstudent1();student::Getstudent2();graduate::Getgraduate2();
cout<<"该助教生的助教信息为:"<<endl;teacher::Getteacher2();
cout<<"该助教生的工作时间为:"<<time<<endl<<"该助教生的工资为:"<<pay<<endl;}
people p;student t;teacher a;graduate g;TA T;
int peopleNO=0,studentNO=0,teacherNO=0,graduateNO=0,TANO=0;int number;
void Set(int i)
{
switch(i)
{
case 0:{cout<<"请输入people的信息:"<<endl;p.Setpeople();peopleNO++;}break;
case 1:{cout<<"请输入student的信息:"<<endl;t.Setstudent1();t.Setstudent2();studentNO++;}break;
case 2:{cout<<"请输入teacher的信息:"<<endl;a.Setteacher1();a.Setteacher2();teacherNO++;}break;
case 3:{cout<<"请输入graduate的信息:"<<endl;g.Setgraduate1();g.Setgraduate2();graduateNO++;}break;
case 4:{cout<<"请输入TA的信息:"<<endl;T.SetTA();TANO++;}break;
default:cout<<"Error!you must enter 0,1,2,3or4"<<endl;
}
}
void Swap(people&p1,people&p2)//辅助函数交换people类的对象
{
people t;
t=p1;
p1=p2;
p2=t;
}
void SelectionSort(people p[] ,int n)//对people类的对象进行排序
{
int smallIndex;
int i,j;
for(i=0;i<n-1;i++)
{
smallIndex=i;
for(j=i+1;j<n;j++)
if(p[j].number<p[smallIndex].number)
smallIndex=j;
Swap(p[i],p[smallIndex]);
}
cout<<"按编号由小到大排列为:"<<endl;
for(i=0;i<n;i++)
{
p[i].Getpeople();
}
}
void SeqSeach(people p[],int n)
{
int number;char ch;
cout<<"请输入你要查找对象的编号:"<<endl;
cin>>number;
for(int i=0;i<n;i++)
{
if(number==p[i].number)p[i].Getpeople();
}
if(number!=p[i].number) cout<<"there is not the people"<<endl;
cout<<"继续输入吗?是'Y'否'N':"<<endl;
cin>>ch;
if(ch=='Y')
SeqSeach( p, n);
}
int main()
{
cout<<"*********Welcome to you!***********"<<endl;
int i; char ch;int t=1;
line:do
{
cout<<"请选择你要输入的人员信息"<<endl;
cout<<"0-people 1-student 2-teacher 3-graduate 4-TA:";
cin>>i;Set(i);cout<<"你还要输入其他人得信息吗?是“Y”,否“N”:";cin>>ch;
}
while(ch=='Y');
if(ch=='N'){cout<<"输入任务结束,请执行其他任务"<<endl;}
else
{cout<<"Error!you must enter 'Y'or'N'"<<endl<<"请重新输入"<<endl;goto line ;}
cout<<"你要对people类执行操作吗?是'Y',否'N':";//处理people类的对象
cin>>ch;
if(ch=='Y')
{ cout<<"请先输入people类的对象:"<<endl;
cout<<"你能够输入三个people类的对象"<<endl;
int t,i,a,b;people p[3];
for(t=0;t<3;t++)
{
cout<<"请输入people类对象的信息:"<<endl;p[t].Setpeople();
}
do
{
cout<<
jie1793162945
- 粉丝: 3
- 资源: 9
最新资源
- awewq1132323
- 手写流程图检测31-YOLO(v5至v8)、COCO、CreateML、Darknet、Paligemma、TFRecord数据集合集.rar
- frida拦截微信小程序云托管API
- 肝脏及其肿瘤分割的 CT 数据集,已经切片成jpg数据,约2w张数据和mask
- 基于Java的网上教务评教管理系统的设计与实现.doc
- 2024圣诞节海外消费市场趋势及营销策略分析报告
- JWaaaaaaaaaaaaaaaaaaaa
- Python实现常见排序算法详解
- 等发达地区的无穷大无穷大无穷大请问
- 微藻检测19-YOLO(v5至v11)、COCO、CreateML、Paligemma、TFRecord、VOC数据集合集.rar
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈