永发信息网

谁能用c语言帮我编一个高校工资管理系统

答案:1  悬赏:0  手机版
解决时间 2021-04-30 21:02

能做的   QQ我   1046243304      我把任务书给你  谢了

最佳答案
给你参考一下,C++的#include <fstream.h>
#include <string.h>

class Person //人员类(抽象类)
{
protected:
int No; //编号
char Name[20]; //姓名
int Duty; //人员类别标志(0-教师,1-实验员,2-行政人员,3-教师兼实验员,4-行政兼教师)
double Salary; //基本工资
Person *next; //指针域

public:
Person() //基类构造
{
next=0; //指针域设置为空
}
virtual ~Person() //基类虚析构
{
}
virtual void Input()=0; //从键盘输入数据
virtual void Input(ifstream& ifs)=0; //从文件输入数据
virtual void Output()=0; //向屏幕输出数据
virtual void Output(ofstream& ofs)=0; //向文件输出数据
virtual double Incoming()=0; //计算收入

friend class College;
};

class Teacher:virtual public Person //教师类
{
protected:
int Hours; //教师课时

public:
//为对象设置数据分为两种途径,通过1)构造函数,2)一般成员函数
//分开可以使得程序中应用更加灵活
//本程序采用:缺省构造+Input()
Teacher() //构造函数,初始化部分数据
{
Duty=0;
Salary=800;
}

void Input() //键盘补充输入其它数据
{
cout<<"编号:"; cin>>No;
cout<<"姓名:"; cin>>Name;
cout<<"教师上学期课时:"; cin>>Hours;
}

void Input(ifstream& ifs)
{
ifs>>No>>Name>>Duty>>Hours;
}

void Output()
{
cout<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<Hours<<"\t"<<Incoming()<<endl;
}

void Output(ofstream& ofs)
{
ofs<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<Hours<<"\t"<<endl;
}

double Incoming()
{
return Salary+(Hours-120)*20;
}
};

class Assistant:virtual public Person //实验员
{
protected:
int Allowance;
int Hours;

public:
Assistant()
{
Duty=1;
Salary=650;
Allowance=150;
}

void Input()
{
cout<<"编号:"; cin>>No;
cout<<"姓名:"; cin>>Name;
cout<<"实验员上学期实验课时:"; cin>>Hours;
}

void Input(ifstream& ifs)
{
ifs>>No>>Name>>Duty>>Hours;
}

void Output()
{
cout<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<Hours<<"\t"<<Incoming()<<endl;
}

void Output(ofstream& ofs)
{
ofs<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<Hours<<"\t"<<endl;
}

double Incoming()
{
return Salary+Allowance+(Hours-70)*20;
}
};

class Manager:virtual public Person //行政人员
{
protected:
int Allowance;

public:
Manager()
{
Duty=2;
Salary=750;
Allowance=250;
}

void Input()
{
cout<<"编号:"; cin>>No;
cout<<"姓名:"; cin>>Name;
}

void Input(ifstream& ifs)
{
ifs>>No>>Name>>Duty;
}

void Output()
{
cout<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<Incoming()<<endl;
}

void Output(ofstream& ofs)
{
ofs<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<endl;
}

double Incoming()
{
return Salary+Allowance;
}
};

class Teacher_Assistant:public Teacher,public Assistant //教师兼实验员
{
public:
Teacher_Assistant()
{
Duty=3;
Teacher::Salary=800;
}
void Input()
{
cout<<"编号:"; cin>>No;
cout<<"姓名:"; cin>>Name;

cout<<"教师上学期课时:"; cin>>Teacher::Hours;
cout<<"教师兼职实验员上学期实验课时:"; cin>>Assistant::Hours;
}

void Input(ifstream& ifs)
{
ifs>>No>>Name>>Duty>>Teacher::Hours>>Assistant::Hours;
}

void Output()
{
cout<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<Teacher::Hours<<"\t"
<<Assistant::Hours<<"\t"<<Incoming()<<endl;
}

void Output(ofstream& ofs)
{
ofs<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<Teacher::Hours<<"\t"
<<Assistant::Hours<<"\t"<<endl;
}

double Incoming()
{
return Salary+(Teacher::Hours-120)*20
+Allowance+(Assistant::Hours-70)*20;
}
};

class Manager_Teacher:public Manager,public Teacher //行政人员兼教师
{
public:
Manager_Teacher()
{
Duty=4;
Manager::Salary=750;
}

void Input()
{
cout<<"编号:"; cin>>No;
cout<<"姓名:"; cin>>Name;
cout<<"行政人员兼职教师上学期课时:"; cin>>Hours;
}

void Input(ifstream& ifs)
{
ifs>>No>>Name>>Duty>>Hours;
}

void Output()
{
cout<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<Hours<<"\t"<<Incoming()<<endl;
}

void Output(ofstream& ofs)
{
ofs<<No<<"\t"<<Name<<"\t"<<Duty<<"\t"<<Hours<<"\t"<<endl;
}

double Incoming()
{
return Salary+Allowance+Hours*20;
}
};

class College
{
private:
Person *PL;
void Clear();
int College::Find(int ID,Person **p1,Person **p2);
public:
College(); //构造
~College(); //析构
void Add(); //增加职工
void Delete(); //删除职工
void Modify(); //修改职工
void Print(); //输出职工信息
void Save(); //职工信息存盘
void Load(); //职工信息装入
};

College::College() //构造函数(创建1个头结点的链表)
{
Person *p=new Teacher;
PL=p;

cout<<"自动装入数据...\n";
Load();
}

College::~College() //析构函数(仅保留1个头结点)
{
Person *p=PL;
while(p) //逐个删除结点,包括头结点
{
PL=p->next;
delete p;
p=PL;
}
PL=0;
}

void College::Add() //增加职工
{
cout<<"\n** 增加职工 **\n";

//查找尾结点
Person *p=PL;
while(p->next)p=p->next;

int ch;
cout<<"输入职工分类码[0-教师,1-实验员,2-行政人员,3-教师兼实验员,4-行政兼教师]:"; cin>>ch;
//创建新结点,录入数据,连接到链表
Teacher *pt;
Assistant *pa;
Manager *pm;
Teacher_Assistant *pta;
Manager_Teacher *pmt;
switch(ch)
{
case 0: pt=new Teacher; pt->Input();
p->next=pt;
break;
case 1: pa=new Assistant; pa->Input();
p->next=pa;
break;
case 2: pm=new Manager; pm->Input();
p->next=pm;
break;
case 3: pta=new Teacher_Assistant; pta->Input();
p->next=pta;
break;
case 4: pmt=new Manager_Teacher; pmt->Input();
p->next=pmt;
break;
default: return;
}
}

void College::Clear() //清除所有的职工结点(仅保留头结点)
{
Person *p=PL->next;
while(p)
{
PL->next=p->next;
delete p;
p=PL->next;
}
}

//查找职工结点(返回1-找到,0-未找到.结点指针由p1返回,p2为前看指针)
int College::Find(int ID,Person **p1,Person **p2)
{
*p1=PL->next;
*p2=PL;
while(*p1)
{
if((*p1)->No==ID)
break; //找到
else
{
*p2=*p1; //继续查找
*p1=(*p1)->next;
}
}
return *p1?1:0;
}

void College:elete() //删除职工
{
cout<<"\n** 删除职工 **\n";

int No;
Person *p1,*p2;

cout<<"编号:"; cin>>No;
if(!Find(No,&p1,&p2))
{
cout<<"指定的人员没有找到!\n";
}
else
{
p2->next=p1->next; //连接
delete p1;
cout<<"正确删除!\n";
}
}

void College::Modify() //修改职工
{
cout<<"\n** 修改职工 **\n";

int No;
Person *p1,*p2;

cout<<"编号:"; cin>>No;
if(!Find(No,&p1,&p2))
{
cout<<"指定的人员没有找到!\n";
}
else
{
p1->Output(); //输出原来的职工信息(做提示)
p1->Input(); //输入新的职工信息(更新)
cout<<"修改完成!\n";
}
}

void College:rint() //输出职工信息
{
cout<<"\n** 职工信息表 **\n";
cout<<"编号 姓名 岗位 其它 收入情况\n";

Person *p=PL->next;
if(!p)
{
cout<<"无职工记录!\n";
return;
}

while(p) //遍历链表,输出职工信息
{
p->Output();
p=p->next;
}
}

void College::Save() //职工信息存盘
{
ofstream f("erson.dat",ios:ut); //打开文件

//遍历输出至文件
Person *p=PL->next;
while(p)
{
p->Output(f);
p=p->next;
}

f.close(); //关闭文件

cout<<"职工信息已经保存在Person.dat.\n";
}
void Collegead() //职工信息装入
{
char buf[81]; //临时空间
int Duty; //人员类型
Person *p2; //新建结点的指针
long t; //读写位置

//清除现有结点(保留头结点)
Clear();

//打开文件
ifstream f("erson.dat",ios::in);

//建立结点,读数据
Person *p=PL; //尾结点指针
while(1)
{
//读取人员类型
t=f.tellg();
f>>buf>>buf>>Duty;

if(f)
{
//根据人员类型创建新结点
switch(Duty)
{
case 0: p2=new Teacher; break;
case 1: p2=new Assistant; break;
case 2: p2=new Manager; break;
case 3: p2=new Teacher_Assistant; break;
case 4: p2=new Manager_Teacher; break;
default: f.close(); return;
}
p->next=p2;
p=p->next;
f.seekg(t);
p->Input(f);
}
else
break;
}

//关闭文件
f.close();
}


void main()
{
char ch;
College c; //定义大学对象

//显示主菜单,接受选择,并分支调用大学类的相应功能的成员函数
do
{
cout<<"\n☆☆ 高校工资管理系统 ☆☆\n";
cout<<"1-增加职工\n";
cout<<"2-删除职工\n";
cout<<"3-修改职工\n";
cout<<"4-输出职工信息(工资)\n";
cout<<"5-数据存盘\n";
cout<<"6-数据装入\n";
cout<<"7-退出\t请选择(1-7):";

cin>>ch;
switch(ch)
{
case '1': c.Add(); break;
case '2': c.Delete();break;
case '3': c.Modify();break;
case '4': c.Print(); break;
case '5': c.Save(); break;
case '6': c.Load(); break;
}
}while(ch!='7');


我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
为什么距离会让俩个人隔阂?
路西法6次围杀REMIND的视频谁有
德国ndsi 能用ak2i么?
库尔勒中心合作社轮台县第一分社在什么地方啊
你们喜欢武艺吗?
DNF加12的大蛇刀能卖多少钱
腋臭手术为什么会复发
浙江台州哪里有的卖蒙奇奇布偶
请问学畜牧兽医的可不可以做宠物医师啊!?
魔兽口号英文,求一些魔兽世界 英文版 各种族
怎么消除抬头纹?
办公室文明标语大全,禁止男生进入女生宿舍的
蒿坝林地址在什么地方,想过去办事
急求《思想道德与法律基础》论文
停电了、真的没办法生活勒?
推荐资讯
我的锐欧要首保了,要注意什么啊?
安徽阜阳到淮北有多远,我是阜阳的,我想坐火
怎么我76就没东山岛的重复任务拉
哪个大哥大姐有{三国赵云传}的下载地址
一个我喜欢的,一个我忘不了的,我该选谁!?
飞利浦液晶电视问题?
为什么我的手机早晨屏幕还是好的,到下午半截
喜欢一个人是不是一定要告诉对方啊?
谁有会下雪的桌面?无毒的!发个网址来,谢谢
CMD命令里的CHKDSK怎么修复文
天啊,我暑假除了睡觉就是上网,但是经常上就
地下城与勇士1级公会大还是6级公会大
正方形一边上任一点到这个正方形两条对角线的
阴历怎么看 ?