c语言综合实验药品信息管理,用 C语言 编写 综合实验 职工信息管理系统

匿名用户

1级

2011-06-28 回答

# include

# include

# include

# include

# include

using namespace std;

struct worker_inf

{

int month; //月份

int code; //工人编号

string name; //姓名

float get[4]; //基本工资,津贴,房帖,交通补贴

float pay[4]; //房租,储蓄,交通费,会费

float tax; //个人所得税

float theory_num; //应发书

float reduce_num; //应扣数

float practice_num; //实发数

worker_inf *next;

};

/

class worker //定义职工类

{

private:

worker_inf *head;

void print(worker_inf *); //输出一条指定职工的工资记录,并返回该记录的指针

worker_inf *find(int); //查找条例条件的记录,并返回该记录的指针

public:

worker(){head=NULL;}

worker_inf *get_head(){return head;}

int listcount(); //统计当前链表的记录总数,并返回一个整数

void additem(int month,int code,string name,float get[4],float pay[4]); //添加一条工资记录表尾

void removeitem(int); //删除一条指定职工的工资记录

int menu(); //修改某职工工资的菜单

void changemonth(); //修改月份

void changeitem(int); //修改职工的工资信息

void list(); //输出当月全体职工的工资信息

void search(int); //输出指定编号职工的工资信息

float tax_num(); //计算职工个人所得税

float theorynumber(); //计算应发工资

float reducenumber(); //计算应扣工资

float practicenumber(); //计算实发工资

};

//

int worker::listcount() //统计当前链表数,并返回一个整数

{

if(!head)return 0;

worker_inf *p=head;

int n=0;

while(p)

{n++;p=p->next;}

return n;

}

//

void worker::additem(int month,int code,string name,float get[4],float pay[4]) //添加一条工资记录到表尾

{

if(!head)

{

head=new worker_inf;

for(int i=0;i<4;i++)

{

head->get[i]=get[i];

head->pay[i]=pay[i];

}

head->code=code;

head->month=month;

head->name=name;

head->next=NULL;

return;

}

worker_inf *t=head;

while(t && t->code!=code)

t=t->next;

if(t)

{

cout<

return;

}

worker_inf *p=head;

while(p->next)p=p->next;

worker_inf *p1=new worker_inf;

p1->code=code;

for(int i=0;i<4;i++)

{

p1->get[i]=get[i];

p1->pay[i]=pay[i];

}

p1->code=code;

p1->month=month;

p1->name=name;

p1->next=NULL;

p->next=p1;

return;

}

void worker::removeitem(int code) //删除一条指定职工的工资记录

{

worker_inf *t=find(code);

if(!t)return;

worker_inf *p=head;//如果要删除的记录位于表头

if(head==t)

{

head=head->next;

delete p;

cout<

return;

}

while(p->next!=t)p=p->next;

worker_inf *p1=p->next;

p->next=p1->next;

delete p1;

cout<

return;

}

int worker::menu() //修改某一职工信息的菜单

{

int select=-1;

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cin>>select;

if(select<0||select>9)

{

cout<

cin>>select;

}

return select;

}

/

int menu();

void worker::changeitem(int code) //修改某职工部分工资信息

{

worker_inf *p=find(code);

if(!p){cout<

int select;

while(1)

{

float m;

select=menu();

if(select==0){system("cls");break;}

cout<

cin>>m;

int n;

if(select<=4){

n=select-1;

p->get[n]=m;}

else{

n=select-5;

p->pay[n]=m;}

tax_num();

theorynumber();

reducenumber();

practicenumber();

cout<

}

}

void worker::changemonth() //修改月份

{

worker_inf *p=head;

while(p)

{

if(p->month==12)p->month=1;

else

p->month++;

p=p->next;

}

}

//

void worker::print(worker_inf *p)//输出worker_inf制定的记录

{

cout.precision(0);

cout<month<

cout<code<

cout<name<

for(int i=0;i<4;i++)

{cout<get[i]<

for(int j=0;j<4;j++)

{cout<pay[j]<

cout<tax<

cout<theory_num<

cout<reduce_num<

cout<practice_num<

return;

}

///

void worker::list() //列出当前链表中的所有记录

{

if(listcount==0)

{

cout<

return;

}

worker_inf *p=head;

cout<

cout<

while(p)

{

print(p);

p=p->next;

}

cout<

return;

}

/

void worker::search(int code) //在当前链表查找指定记录并输出

{

cout<

worker_inf *p=find(code);

if(p)

{

cout<

print(p);

}

cout<

}

//

worker_inf *worker::find(int code) //查找条例条件的记录,并返回该指针

{

if(listcount==0)

{

cout<

return NULL;

}

worker_inf *p=head;

while(p)

{

if(p->code==code)break;

p=p->next;

}

if(!p)

{

cout<

return NULL;

}

return p;

}

//

float worker::theorynumber() //计算应发数

{

int i;

if(listcount()==0)

{

cout<

return -1;

}

float sum;

worker_inf *p=head;

while(p)

{

sum=0;

for(i=0;i<4;i++)

sum+=p->get[i];

p->theory_num=sum;

p=p->next;

}

return 0;

}

//

float worker::tax_num() //计算个人所得税

{

if(listcount==0)

{

cout<

return -1;

}

worker_inf *p=head;

while(p)

{

float s;

s=p->theory_num;

if(s<=800)

p->theory_num=0;

else if(s<=2000) p->theory_num=(s-800)*0.05;

else if(s<=5000)

p->theory_num=(s-2000)*0.1+60;

else p->theory_num=(s-5000)*0.2+360;

p=p->next;

}

return 0;

}

///

float worker::reducenumber() //计算应扣数

{

int i;

if(listcount==0)

{

cout<

}

float sum;

worker_inf *p=head;

while(p)

{

sum=0;

for(i=0;i<4;i++)

sum+=p->pay[i];

p->reduce_num=p->tax+sum;

p=p->next;

}

return 0;

}

/

float worker::practicenumber() //计算实发数

{

if(listcount()==0)

{

cout<

return -1;

}

worker_inf *p=head;

while(p)

{

float a,b;

a=p->theory_num;

b=p->reduce_num;

p->practice_num=a-b;

p=p->next;

}

return 0;

}

worker worker; //定义全局变量

int menu()

{

int select=-1;

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cout<

cin>>select;

return select;

}

/

char exit()

{

char s;

cout<

cin>>s;

return s;

}

//

void input(int *month,int*code,string *name,float get[4],float pay[4]) //输入职工信息

{

cout<

cin>>*month;

cin>>*code;

if(*code==-1)return;

cin>>*name>>get[0]>>get[1]>>get[2]>>get[3]>>pay[0]>>pay[1]>>pay[2]>>pay[3];

return;

}

///

void addnew() //增加记录

{

int month=0,code=0;float get[4]={0},pay[4]={0};

string name="";

cout<

input(&month,&code,&name,get,pay);

while(code!=-1)

{

worker.additem(month,code,name,get,pay);

worker.tax_num();

worker.theorynumber();

worker.reducenumber();

worker.practicenumber();

input(&month,&code,&name,get,pay);

}

return;

}

void dofind() //按职工编号查找

{

int code;

cout<

do

{

cout<

cin>>code;

if(code==-1)continue;

worker.search(code);

}while(code!=-1);

return;

}

/

void dodelete() //删除职工信息

{

cout<

int code;

do

{

cout<

cin>>code;

if(code==-1)continue;

worker.removeitem(code);

}while(code!=-1);

return;

}

///

void domodify() //修改职工信息

{

int code;

cout<

while(1){

cout<

cin>>code;

if(code==-1)return;

else

worker.changeitem(code);

}

return;

}

///

void SaveFilethism()//将当月工资信息写入文件

{

worker_inf *p;

char name[20];

fstream iofile;

int i=0;

iofile.open("Worker_5th.dat",ios::out|ios::binary);

if(!iofile)

{

cerr<

abort();

}

p=worker.get_head();

while(p)

{

p->name.copy(name,20,0);

name[p->name.length()]=0;

iofile.write((char *) &p->code,sizeof(int));

iofile.write((char *) &p->month,sizeof(int));

iofile.write((char *) name,20);

for(int i=0;i<4;i++)

{

iofile.write((char *) &p->get[i],sizeof(float));

}

for(int j=0;j<4;j++)

{

iofile.write((char *) &p->pay[j],sizeof(float));

}

p=p->next;

}

iofile.close();

cout<

}

void Loadfilethism() //读取当月全体职工的工资信息文件

{

int month,code;

char name[20]="";

float get[4],pay[4];

fstream iofile;

int i=0;

iofile.open("Worker_5th.dat",ios::in|ios::binary);

if(!iofile)

{

cout<

return;

}

if(iofile.eof())

{

cout<

iofile.close();

}

else

{

while(iofile.peek()!=EOF)//peek()是取文件当前指针,EOF是文件尾标符

{

iofile.read((char *) &code,sizeof(int));

iofile.read((char *) &month,sizeof(int));

iofile.read((char *) name,20);

for(int i=0;i<4;i++)

{

iofile.read((char *) &get[i],sizeof(float));

} for(int j=0;j<4;j++)

{

iofile.read((char *) &pay[j],sizeof(float));

}

worker.additem(code,month,name,get,pay);

}

worker.tax_num();

worker.theorynumber();

worker.reducenumber();

worker.practicenumber();

iofile.close();

cout<

}

}

/

void list()

{

worker.list();

}

/

int main()

{

cout<

int select;

char s;

while(1)

{

select=menu();

switch(select)

{

case 0: //退出程序

s=exit();

if(s=='y'||s=='Y') return 0;

break;

case 1: //增加新记录

addnew();

break;

case 2: //删除记录

dodelete();

break;

case 3: //修改记录

domodify();

break;

case 4: //按条件查找

dofind();

break;

case 5: //列出全部记录

list();

break;

case 6: //导入当月职工记录

Loadfilethism();

break;

case 7: //将职工记录存入磁盘

SaveFilethism();

break;

default:

cout<

}

}

return 0;

}

追问:

方便嘛???不止这个 还需要其他的 行的话 还加50

追答:

http://book.51cto.com/art/200906/127244.htm 不知道是不是

也不可能那么全面,都需要一个个找吧,这个事8.1的概要

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值