求大神C++人事管理系统程序设计作业帮忙。。。邮箱1228185442@qq.com
有关学校的人事管理情况,作为基类的People(人员)类,具有的属性如下:姓名charname[11],编号charnumber[7],性别charsex[3],生日bi...
有关学校的人事管理情况,作为基类的People(人员)类,具有的属性如下:姓名char name[11],编号char number[7],性别char sex[3], 生日birthday, 身份证号 char id[16], 其中“出生日期”定义为一个“日期”类内嵌对象。
People类派生出Student(学生)类,添加属性:班号 char classNo[7]; 从People类派生出teacher(教师)类, 添加属性:职务char Principalship[11],部门char department[21]。
从Student类中派生出graduate(研究生)类,添加属性:专业char subject[21],导师teacher adviser;从graduate类和teacher类派生出TA(助教)类,其中teacher类是从People类派生而来。要求在构造函数中通过键盘实现对各类人员的录入,各类人员都有自己的显示成员函数。按照名字的字母顺序将people类的对象进行排序。注意用虚基类及虚函数。
首先要对类进行分析设计,给出系统的类图。
源程序代码必须要有详细的注释。
要可以执行(C++) 展开
People类派生出Student(学生)类,添加属性:班号 char classNo[7]; 从People类派生出teacher(教师)类, 添加属性:职务char Principalship[11],部门char department[21]。
从Student类中派生出graduate(研究生)类,添加属性:专业char subject[21],导师teacher adviser;从graduate类和teacher类派生出TA(助教)类,其中teacher类是从People类派生而来。要求在构造函数中通过键盘实现对各类人员的录入,各类人员都有自己的显示成员函数。按照名字的字母顺序将people类的对象进行排序。注意用虚基类及虚函数。
首先要对类进行分析设计,给出系统的类图。
源程序代码必须要有详细的注释。
要可以执行(C++) 展开
2个回答
2012-06-10
展开全部
#include<iostream>
#include<cstring>
using namespace std;
class employee
{
protected:
char name[20];
int individualEmpNo;
int grade;
float accumPay;
static int employeeNo;
public:
employee();
~employee();
void pay();
void promote(int);
void SetName(char *);
char * GetName();
int GetindividualEmpNo();
int Getgrade();
float GetaccumPay();
};
class technician:public employee
{
private:
float hourlyRate;
int workHours;
public:
technician();
void SetworkHours(int wh);
void pay();
};
class salesman:virtual public employee
{
protected:
float CommRate;
float sales;
public:
salesman();
void Setsales(float sl);
void pay();
};
class manager:virtual public employee
{
protected:
float monthlyPay;
public:
manager();
void pay();
};
class salesmanager:public manager,public salesman
{
public:
salesmanager();
void pay();
};
int employee::employeeNo=1000;
employee::employee()
{ individualEmpNo=employeeNo++;
grade=1;
accumPay=0.0; }
employee::~employee()
{}
void employee::pay()
{}
void employee::promote(int increment)
{ grade+=increment;}
void employee::SetName(char* names)
{ strcpy(name,names); }
char* employee::GetName()
{ return name;}
int employee::GetindividualEmpNo()
{ return individualEmpNo;}
int employee::Getgrade()
{ return grade;}
float employee::GetaccumPay()
{ return accumPay;}
technician::technician()
{ hourlyRate=100;}
void technician::SetworkHours(int wh)
{ workHours=wh;}
void technician::pay()
{ accumPay=hourlyRate*workHours;}
salesman::salesman()
{ CommRate=0.04;}
void salesman::Setsales(float sl)
{ sales=sl;}
void salesman::pay()
{ accumPay=sales*CommRate;}
manager::manager()
{ monthlyPay=8000;}
void manager::pay()
{ accumPay=monthlyPay;}
salesmanager::salesmanager()
{ monthlyPay=5000;
CommRate=0.005;}
void salesmanager::pay()
{ accumPay=monthlyPay+CommRate*sales; }
void main()
{
manager m1;
technician t1;
salesmanager sm1;
salesman s1;
char namestr[20];
cout<<"请输下一个雇员的姓名:";
cin>>namestr;
m1.SetName(namestr);
cout<<"请输下一个雇员的姓名:";
cin>>namestr;
t1.SetName(namestr);
cout<<"请输下一个雇员的姓名:";
cin>>namestr;
sm1.SetName(namestr);
cout<<"请输下一个雇员的姓名:";
cin>>namestr;
s1.SetName(namestr);
m1.promote(3);
m1.pay();
cout<<"请输入兼职技术人员"<<t1.GetName()<<"本月的工作时数:";
int ww;
cin>>ww;
t1.SetworkHours(ww);
t1.promote(2);
t1.pay();
cout<<"请输入销售经理"<<sm1.GetName()<<"所管辖部门本月的销售总额:";
float sl;
cin>>sl;
sm1.Setsales(sl);
sm1.pay();
sm1.promote(2);
cout<<"请输入推销员"<<s1.GetName()<<"本月的销售额:";
cin>>sl;
s1.Setsales(sl);
s1.pay();
cout<<m1.GetName()<<"编号"<<m1.GetindividualEmpNo()
<<"级别为"<<m1.Getgrade()<<"级,本月工资"<<m1.GetaccumPay()<<endl;
cout<<t1.GetName()<<"编号"<<t1.GetindividualEmpNo()
<<"级别为"<<t1.Getgrade()<<"级,本月工资"<<t1.GetaccumPay()<<endl;
cout<<sm1.GetName()<<"编号"<<sm1.GetindividualEmpNo()
<<"级别为"<<sm1.Getgrade()<<"级,本月工资"<<sm1.GetaccumPay()<<endl;
cout<<s1.GetName()<<"编号"<<s1.GetindividualEmpNo()
<<"级别为"<<s1.Getgrade()<<"级,本月工资"<<s1.GetaccumPay()<<endl;
}
#include<cstring>
using namespace std;
class employee
{
protected:
char name[20];
int individualEmpNo;
int grade;
float accumPay;
static int employeeNo;
public:
employee();
~employee();
void pay();
void promote(int);
void SetName(char *);
char * GetName();
int GetindividualEmpNo();
int Getgrade();
float GetaccumPay();
};
class technician:public employee
{
private:
float hourlyRate;
int workHours;
public:
technician();
void SetworkHours(int wh);
void pay();
};
class salesman:virtual public employee
{
protected:
float CommRate;
float sales;
public:
salesman();
void Setsales(float sl);
void pay();
};
class manager:virtual public employee
{
protected:
float monthlyPay;
public:
manager();
void pay();
};
class salesmanager:public manager,public salesman
{
public:
salesmanager();
void pay();
};
int employee::employeeNo=1000;
employee::employee()
{ individualEmpNo=employeeNo++;
grade=1;
accumPay=0.0; }
employee::~employee()
{}
void employee::pay()
{}
void employee::promote(int increment)
{ grade+=increment;}
void employee::SetName(char* names)
{ strcpy(name,names); }
char* employee::GetName()
{ return name;}
int employee::GetindividualEmpNo()
{ return individualEmpNo;}
int employee::Getgrade()
{ return grade;}
float employee::GetaccumPay()
{ return accumPay;}
technician::technician()
{ hourlyRate=100;}
void technician::SetworkHours(int wh)
{ workHours=wh;}
void technician::pay()
{ accumPay=hourlyRate*workHours;}
salesman::salesman()
{ CommRate=0.04;}
void salesman::Setsales(float sl)
{ sales=sl;}
void salesman::pay()
{ accumPay=sales*CommRate;}
manager::manager()
{ monthlyPay=8000;}
void manager::pay()
{ accumPay=monthlyPay;}
salesmanager::salesmanager()
{ monthlyPay=5000;
CommRate=0.005;}
void salesmanager::pay()
{ accumPay=monthlyPay+CommRate*sales; }
void main()
{
manager m1;
technician t1;
salesmanager sm1;
salesman s1;
char namestr[20];
cout<<"请输下一个雇员的姓名:";
cin>>namestr;
m1.SetName(namestr);
cout<<"请输下一个雇员的姓名:";
cin>>namestr;
t1.SetName(namestr);
cout<<"请输下一个雇员的姓名:";
cin>>namestr;
sm1.SetName(namestr);
cout<<"请输下一个雇员的姓名:";
cin>>namestr;
s1.SetName(namestr);
m1.promote(3);
m1.pay();
cout<<"请输入兼职技术人员"<<t1.GetName()<<"本月的工作时数:";
int ww;
cin>>ww;
t1.SetworkHours(ww);
t1.promote(2);
t1.pay();
cout<<"请输入销售经理"<<sm1.GetName()<<"所管辖部门本月的销售总额:";
float sl;
cin>>sl;
sm1.Setsales(sl);
sm1.pay();
sm1.promote(2);
cout<<"请输入推销员"<<s1.GetName()<<"本月的销售额:";
cin>>sl;
s1.Setsales(sl);
s1.pay();
cout<<m1.GetName()<<"编号"<<m1.GetindividualEmpNo()
<<"级别为"<<m1.Getgrade()<<"级,本月工资"<<m1.GetaccumPay()<<endl;
cout<<t1.GetName()<<"编号"<<t1.GetindividualEmpNo()
<<"级别为"<<t1.Getgrade()<<"级,本月工资"<<t1.GetaccumPay()<<endl;
cout<<sm1.GetName()<<"编号"<<sm1.GetindividualEmpNo()
<<"级别为"<<sm1.Getgrade()<<"级,本月工资"<<sm1.GetaccumPay()<<endl;
cout<<s1.GetName()<<"编号"<<s1.GetindividualEmpNo()
<<"级别为"<<s1.Getgrade()<<"级,本月工资"<<s1.GetaccumPay()<<endl;
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
"people.h"
*******************
#include <iostream>
#include <cstring>
using std::ostream;
using std::iostream;
using std::istream;
using std::endl;
using std::cin;
class birthday{
public:
birthday():year(0),month(0),day(0){}
int year;
int month;
int day;
friend istream& operator>>(istream& in, birthday& birth){
in>>birth.year>>birth.month>>birth.day;
return in;
}
friend ostream& operator<<(ostream& out,const birthday& birth){
out<<birth.year<<birth.month<<birth.day;
return out;
}
};
class People{
public:
People(istream& in=cin){
std::cout<<"input people information"<<std::endl;
in>>name>>number>>sex>>ID>>nbirth;}
virtual void ouput(ostream& out)const{output1(out);}
virtual bool operator<(const People& rhs)const{
if(strcmp(name,rhs.name)<0)
return true;
else
return false;
}
virtual~People(){}
protected:
char name[11];
char number[7];
char sex[3];
birthday nbirth;
char ID[16];
void output1(ostream& out)const{out<<"NAME "<<name<<'\t'<<"NUMBER"<<number
<<'\t'<<"SEX"<<sex<<'\t'
<<"ID "<<ID
<<"\tBIRTHDAY "<<nbirth;}
};
class Student: public virtual People{
public:
Student(istream &in=cin):People(in){
std::cout<<"input student information"<<std::endl;
in>>classNo;
}
void ouput(ostream& out)const{output1(out);out<<"CLASSNO."<<classNo;}
protected:
char classNo[7];
};
class Graduate:public Student{
public:
Graduate(istream &in=cin):People(in),Student(in){
std::cout<<"input graduater information"<<std::endl;
in>>subject>>teacheradviser;
}
void ouput(ostream& out)const{output1(out);out<<"CLASSNO. "<<classNo
<<"\tSUBJECT "<<subject
<<"\tTEACHERADVISER "<<teacheradviser<<endl;}
protected:
char subject[21];
char teacheradviser[11];
};
class Teacher:virtual public People{
public:
Teacher(istream &in=cin):People(in){
std::cout<<"input graduater information"<<std::endl;
in>>Principalship>>Department;
}
void ouput(ostream& out)const{output1(out);out<<"PRINCIPALSHIP "<<Principalship
<<"\tDEPARTMENT "<<Department<<endl;
}
protected:
char Principalship[11];
char Department[21];
};
class TA:public Graduate,public Teacher{
public:
TA(istream &in=cin):People(in),Graduate(in),Teacher(in){
std::cout<<"input TA information"<<std::endl;
}
void ouput(ostream& out)const{output1(out);out<<"PRINCIPALSHIP "<<Principalship
<<"\tDEPARTMENT "<<Department
<<"\tCLASSNO. "<<classNo
<<"\tSUBJECT "<<subject
<<"\tTEACHERADVISER "<<teacheradviser<<endl;}
};
********************************************************************************************************
主程序main
********************************************************************************
#include <iostream>
#include <algorithm>
#include "people.h"
using namespace std;
bool is_front(People*lhs,People*rhs){
return((*lhs)<(*rhs));
}
//按姓名排序
void psort(People**beg,People**end){
sort(beg,end,is_front);
}
int main()
{
People* ptr[3]={new Graduate(),new Student(),new People()};
psort(ptr,ptr+3);
for(int i=0;i<3;++i){
ptr[i]->ouput(cout);
cout<<endl<<"\t\t\tNExt Student"<<endl;
}
//删除个人相关信息
for(int i=0;i<3;++i){
delete ptr[i];
}
return 0;
}
*******************
#include <iostream>
#include <cstring>
using std::ostream;
using std::iostream;
using std::istream;
using std::endl;
using std::cin;
class birthday{
public:
birthday():year(0),month(0),day(0){}
int year;
int month;
int day;
friend istream& operator>>(istream& in, birthday& birth){
in>>birth.year>>birth.month>>birth.day;
return in;
}
friend ostream& operator<<(ostream& out,const birthday& birth){
out<<birth.year<<birth.month<<birth.day;
return out;
}
};
class People{
public:
People(istream& in=cin){
std::cout<<"input people information"<<std::endl;
in>>name>>number>>sex>>ID>>nbirth;}
virtual void ouput(ostream& out)const{output1(out);}
virtual bool operator<(const People& rhs)const{
if(strcmp(name,rhs.name)<0)
return true;
else
return false;
}
virtual~People(){}
protected:
char name[11];
char number[7];
char sex[3];
birthday nbirth;
char ID[16];
void output1(ostream& out)const{out<<"NAME "<<name<<'\t'<<"NUMBER"<<number
<<'\t'<<"SEX"<<sex<<'\t'
<<"ID "<<ID
<<"\tBIRTHDAY "<<nbirth;}
};
class Student: public virtual People{
public:
Student(istream &in=cin):People(in){
std::cout<<"input student information"<<std::endl;
in>>classNo;
}
void ouput(ostream& out)const{output1(out);out<<"CLASSNO."<<classNo;}
protected:
char classNo[7];
};
class Graduate:public Student{
public:
Graduate(istream &in=cin):People(in),Student(in){
std::cout<<"input graduater information"<<std::endl;
in>>subject>>teacheradviser;
}
void ouput(ostream& out)const{output1(out);out<<"CLASSNO. "<<classNo
<<"\tSUBJECT "<<subject
<<"\tTEACHERADVISER "<<teacheradviser<<endl;}
protected:
char subject[21];
char teacheradviser[11];
};
class Teacher:virtual public People{
public:
Teacher(istream &in=cin):People(in){
std::cout<<"input graduater information"<<std::endl;
in>>Principalship>>Department;
}
void ouput(ostream& out)const{output1(out);out<<"PRINCIPALSHIP "<<Principalship
<<"\tDEPARTMENT "<<Department<<endl;
}
protected:
char Principalship[11];
char Department[21];
};
class TA:public Graduate,public Teacher{
public:
TA(istream &in=cin):People(in),Graduate(in),Teacher(in){
std::cout<<"input TA information"<<std::endl;
}
void ouput(ostream& out)const{output1(out);out<<"PRINCIPALSHIP "<<Principalship
<<"\tDEPARTMENT "<<Department
<<"\tCLASSNO. "<<classNo
<<"\tSUBJECT "<<subject
<<"\tTEACHERADVISER "<<teacheradviser<<endl;}
};
********************************************************************************************************
主程序main
********************************************************************************
#include <iostream>
#include <algorithm>
#include "people.h"
using namespace std;
bool is_front(People*lhs,People*rhs){
return((*lhs)<(*rhs));
}
//按姓名排序
void psort(People**beg,People**end){
sort(beg,end,is_front);
}
int main()
{
People* ptr[3]={new Graduate(),new Student(),new People()};
psort(ptr,ptr+3);
for(int i=0;i<3;++i){
ptr[i]->ouput(cout);
cout<<endl<<"\t\t\tNExt Student"<<endl;
}
//删除个人相关信息
for(int i=0;i<3;++i){
delete ptr[i];
}
return 0;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询