第2个回答 2010-07-01
我这正好有一个 稍微改改就可以了!!
//gongzi.cpp
#include <iostream.h>
#include <string.h>
#include <fstream.h>
#include "H1.H"
//using namespace std;
#define N 30 //人员的总数
char filename[]="system.txt";
people::people(int no1,char *name1,int age1,double salary1,double workyear1)
{
no=no1;
strcpy(name,name1);
age=age1;
salary=salary1;
workyear=workyear1;
}
int people::getno()
{
return no;
}
char *people::getname()
{
return name;
}
int people::getage()
{
return age;
}
double people::getsalary()
{
return salary;
}
double people::getworkyear()
{
return workyear;
}
void people::input()
{
cout<<"\t\t 名字:";
cin>>name;
cout<<"\t\t 编号:";
cin>>no;
cout<<"\t\t 年龄:";
cin>>age;
cout<<"\t\t 工龄:";
cin>>workyear;
}
void people::output()
{
cout<<"\t\t 人员编号:"<<no<<endl;
cout<<"\t\t 姓名:"<<name<<endl;
cout<<"\t\t 年龄:"<<age<<endl;
cout<<"\t\t 工龄:"<<workyear<<endl;
}
manager::manager(int no1,char *name1,int age1,double salary1,double workyear1,double allowance1):
people(no1,name1, age1, salary1, workyear1)
{
allowance=allowance1;
}
void manager::input()
{
people::input();
cout<<"\t\t 每月津贴:";
cin>>allowance;
}
double manager::computesalary()
{
salary=salary+allowance+workyear*50;//行政人员的工资:基本工资+每月津贴
//+工龄*每年50
}
void manager::output()
{
people::output();
cout<<"\t\t 每月津贴:"<<allowance;
// cout<<"\t\t 行政人员工资:"<<b[s].outsalary()<<endl<<endl;
}
//教师
teacher::teacher(int no1,char *name1,int age1,double salary1,double workyear1,double classes1):
people(no1,name1,age1,salary1,workyear1)
{
classes=classes1;
}
void teacher::input()
{
people::input();
cout<<"\t\t 上课课时:";
cin>>classes;
}
double teacher::computesalary()
{
salary=salary+classes*30+workyear*50;//教师工资:基本工资+上课课时*每节课30块钱
//+工龄*每年50
}
void teacher::output()
{
people::output();
cout<<"\t\t 上课课时:";
cin>>classes;
// cout<<"\t\t 教师工资:"<<c[s].outsalary()<<endl<<endl;
}
//实验人员
laber::laber(int no1,char *name1,int age1,
double salary1,double workyear1,double allowance1,double classes1):
people( no1,name1, age1, salary1, workyear1)
{
allowance=allowance1;
classes=classes1;
}
void laber::input()
{
people::input();
cout<<"\t\t 每月津贴:";
cin>>allowance;
cout<<"\t\t 上课课时:";
cin>>classes;
}
double laber::computesalary()
{
salary=salary+allowance+classes*15+workyear*50;//实验员工资:基本工资+津贴+课时*每节课15
//+工龄*每年50
}
void laber::output()
{
people::output();
cout<<"\t\t 每月津贴:"<<allowance<<endl;
cout<<"\t\t 上课课时:"<<classes<<endl;
// cout<<"\t\t 实验人员工资:"<<d[s].outsalary()<<endl;
}
//后勤人员
logistic::logistic(int no1,char *name1,int age1,double salary1,double workyear1,double workhour1):
people( no1,name1, age1, salary1, workyear1)
{
workhour=workhour1;
}
void logistic::input()
{
people::input();
cout<<"\t\t 工作小时数:";
cin>>workhour;
}
double logistic::computesalary()
{
salary=salary+(workhour-100)*20+workyear*50;//后勤人员:基本工资+工作小时*每小时20
//+工龄*每年50
}
void logistic::output()
{
people::output();
cout<<"\t\t 工作小时数:"<<workhour<<endl;
// cout<<"\t\t 工资:"<<e[s].outsalary()<<endl;
}
//外聘人员
invitor::invitor(int no1,char *name1,int age1,double salary1,double workyear1,double classes1):
people(no1,name1,age1,salary1,workyear1)
{
classes=classes1;
}
void invitor::input()
{
people::input();
cout<<"\t\t 上课课时:";
cin>>classes;
}
double invitor::computesalary()
{
salary=salary+classes*60;//外聘人员工资:基本工资+上课课时*60
}
void invitor::output()
{
people::output();
cout<<"\t\t 上课课时:"<<classes<<endl;
// cout<<"\t\t 外聘人员工资:"<<f[s].outsalary()<<endl;
}
//system
int system::j1=0;
int system::j2=0;
int system::j3=0;
int system::j4=0;
int system::j5=0;
system::system()
{
save();
}
void system::interface1()
{
cout<<"\n\n\n";
cout<<"\t\t********************学校工资管理系统******************"<<endl;
cout<<"\t\t********************高校人员分类***********************"<<endl;
cout<<"\t\t 1.行政人员 "<<endl;
cout<<"\t\t 2.教师 "<<endl;
cout<<"\t\t 3.实验人员 "<<endl;
cout<<"\t\t 4.后勤人员 "<<endl;
cout<<"\t\t 5.外聘人员 "<<endl;
cout<<"\t\t 6.退出系统 "<<endl;
cout<<"\t\t 请选择你要查询的人员类别:1——6 ";
}
void system::addinformation()
{
int n;
int again=1;
char t;
while (again)
{
interface1();
cin>>n;
switch(n)
{
case 1:
infor1();
break;
case 2:
infor2();
break;
case 3:
infor3();
break;
case 4:
infor4();
break;
case 5:
infor5();
break;
case 6:
Interface();
break;
default:
cout<<"\t\t\t 没有此类人员! "<<endl;
continue;
}
cout<<"\t\t\t 信息存储成功!"<<endl;
cout<<"\t\t\t 是否继续输入(y/n)?";
cin>>t;
cout<<endl;
if(!(t=='y'||t=='Y'))
again=0;
}
Interface();
}
void system::infor1()//行政人员
{
manager a;
fstream datafile(filename,ios::in|ios::out|ios::binary);
datafile.seekp(0,ios::end);//写指针到文件尾部
a.input();
datafile.write((char*)&a,sizeof(class manager));
b[j1]=a;
datafile.close();
}
void system::infor2()//教师
{
teacher a;
fstream datafile(filename,ios::in|ios::out|ios::binary);
datafile.seekp(0,ios::end);
a.input();
datafile.write((char*)&a,sizeof(class teacher));
c[j2]=a;
datafile.close();
}
void system::infor3()//实验人员
{
teacher a;
fstream datafile(filename,ios::in|ios::out|ios::binary);
datafile.seekp(0,ios::end);
a.input();
datafile.write((char*)&a,sizeof(class laber));
// d[j3]=a;
datafile.close();
}
void system::infor4()//后勤人员
{
teacher a;
fstream datafile(filename,ios::in|ios::out|ios::binary);
datafile.seekp(0,ios::end);
a.input();
datafile.write((char*)&a,sizeof(class logistic));
// e[j4]=a;
datafile.close();
}
void system::infor5()//外聘人员
{
teacher a;
fstream datafile(filename,ios::in|ios::out|ios::binary);
datafile.seekp(0,ios::end);
a.input();
datafile.write((char*)&a,sizeof(class invitor));
// f[j5]=a;
datafile.close();
}
void system::save()//save 读入数据信息
{
// int i,j;
int n;
fstream datafile(filename,ios::out|ios::in|ios::binary);
datafile.read((char*)&a,sizeof( people));
while(!datafile.eof())
{
n=a.getno();
switch(n)
{
case 1:
{
datafile.seekp(-1*sizeof(class people),ios::cur);
datafile.read((char *)&b[j1],sizeof(manager));
j1++;
break;
}
case 2:
{
datafile.seekp(-1*sizeof(class people),ios::cur);
datafile.read((char *)&c[j2],sizeof(teacher));
j2++;
break;
}
case 3:
{
datafile.seekp(-1*sizeof(class people),ios::cur);
datafile.read((char *)&d[j3],sizeof(laber));
j3++;
break;
}
case 4:
{
datafile.seekp(-1*sizeof(class people),ios::cur);
datafile.read((char *)&e[j4],sizeof(logistic));
j4++;
break;
}
case 5:
{
datafile.seekp(-1*sizeof(class people),ios::cur);
datafile.read((char *)&f[j5],sizeof(invitor));
j5++;
break;
}
default:
break;
}
datafile.read((char *)&a,sizeof(people));
}
datafile.close ();
}
void search1(int h,char ch[20])
{
int s=0,found=0;
switch(h)
{
case 1:
while(s<N)
{
if(strcmp(ch,b[s].getname())==0)
{
b[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
case 2:
while(s<N)
{
if(strcmp(ch,c[s].getname())==0)
{
c[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
case 3:
while(s<N)
{
if(strcmp(ch,d[s].getname())==0)
{
d[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
case 4:
while(s<N)
{
if(strcmp(ch,e[s].getname())==0)
{
e[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
case 5:
while(s<N)
{
if(strcmp(ch,f[s].getname())==0)
{
f[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
}
if(found==0)
cout<<"\t\t\t 对不起,该人员类别中没有您所要找的人!"<<endl;
}
void search2(int h,int no1)
{
int s=0,found=0;
switch(h)
{
case 1:
while(s<N)
{
if(no1==b[s].getno())
{
b[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
case 2:
while(s<N)
{
if(no1==c[s].getno())
{
c[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
case 3:
while(s<N)
{
if(no1==d[s].getno())
{
d[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
case 4:
while(s<N)
{
if(no1==e[s].getno())
{
e[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
case 5:
while(s<N)
{
if(no1==f[s].getno())
{
f[s].output();
cout<<"\t\t\t**********************"<<endl;
found=1;
}
s++;
}
break;
}
if(found==0)
cout<<"\t\t\t 对不起,该人员类别中没有您所要找的人!"<<endl;
}
void system::search()//查询
{
int n;
char name[20];
int again=1;
char t;
int no;
while(again)
{
interface1();
cout<<"\t\t **************************"<<endl;
cout<<"\t\t 1.按姓名查询 "<<endl;
cout<<"\t\t 2.按编号查询 "<<endl;
cout<<"\t\t **************************"<<endl;
cin>>n;
switch(n)
{
case 1:
{ cout<<"\t\t 请输入您要查找的人员姓名:";
cin>>name;
search1(h,name);
break;
}
case 2:
{
cout<<"\t\t 请输入您要查找的人员工作证号:";
cin>>no;
search2(h,no);
break;
}
default:
cout<<"\t\t 请选择正确的查询方式:";
}
cout<<"\t\t\t 是否继续查询(y/n)?";
cin>>t;
cout<<endl;
if(!(t=='Y'||t=='y'))
again=0;
}
Interface();
}
void outsalary1(int h,char *name)
{
int s=0,found=0;
float salary;
switch(h)
{
case 1:
while(s<N)
{
if(strcmp(name,b[s].getname())==0)
{
b[s].computesalary();
salary=b[s].compute();
found=1;
}
s++;
}
break;
case 2:
while(s<N)
{
if(strcmp(name,c[s].getname())==0)
{
c[s].computesalary();
salary=c[s].compute();
found=1;
}
s++;
}
break;
case 3:
while(s<N)
{
if(strcmp(name,d[s].getname())==0)
{
d[s].computesalary();
salary=d[s].compute();
found=1;
}
s++;
}
break;
case 4:
while(s<N)
{
if(strcmp(name,e[s].getname())==0)
{
e[s].computesalary();
salary=e[s].compute();
found=1;
}
s++;
}
break;
case 5:
while(s<N)
{
if(strcmp(name,f[s].getname())==0)
{
f[s].computesalary();
salary=f[s].compute();
found=1;
}
s++;
}
break;
}
if(found==0)
cout<<"\t\t\t 对不起,该人员中没有您要找的人!"<<endl;
else
{
cout<<"\t\t 姓名:"<<name<<endl;
cout<<"\t\t 工资:"<<salary<<endl;
cout<<"\t\t *******************"<<endl;
}
}
void outsalary()//计算并显示总工资
{
int n;
char name[20];
int again=1;
char t;
while(again)
{
interface1();
cout<<"\n\t\t 请输入所要查看工资的人员类别:";
cin>>n;
cout<<"\n\t\t 请输入所要查看工资的人员姓名:";
cin>>name;
outsalary1(n,name);
cout<<"\t\t\t 是否继续查看利润(y/n)?";
cin>>t;
cout<<endl;
if(!(t=='y'||t=='Y'))
again=0;
}
Interface();
}
void system::Interface()//界面
{
int n;
cout<<"\n\n\n\n\n\n\n";
cout<<"\t\t *****************欢迎使用";
cout<<"*****************"<<endl;
cout<<"\t\t **********高校工资管理系统";
cout<<"**********"<<endl;
cout<<"\t\t 1.输入信息 "<<endl;
cout<<"\t\t 2.查询信息并显示 "<<endl;
cout<<"\t\t 3.计算工资并显示 "<<endl;
cout<<"\t\t 4.退出 "<<endl;
cout<<"\t\t 请您选择(1——4): ";
cin>>n;
switch(n)
{
case 1:
addinformation();
break;
case 2:
search();
break;
case 3:
outsalary();
break;
case 4:
break;
}
}
// main.cpp
void main()
{
system s;
s.Interface();
}