C++实现职工工资管理系统课程设计
#define _CRT_SECURE_NO_WARNINGS 1
#include "xiaodong.h"
//初始化系统
void Initclass(System * my_sys)
{
my_sys->staff= (Staff *)calloc(START ,sizeof(Staff));
if(my_sys->staff == NULL)
{
cout<<"开辟空间失败"< exit(EXIT_FAILURE); } my_sys->len = 0 ; my_sys->width = START; } void IF_space(System * my_sys) { if(my_sys->len == my_sys->width) { Staff *temp = (Staff *)realloc(my_sys->staff,my_sys->width+ADD); if(temp == NULL) { cout<<"职工人数已达系统限定,"< } else { my_sys->staff = temp; my_sys->width += ADD; } } } //添加职工信息 void Input(System * my_sys) { IF_space(my_sys); cout<<"请输入职工信息:"< cout<<"姓名 基本工资 职务工资 津贴 医疗保险 公积金"< cin>>(my_sys->staff+my_sys->len)->name >>(my_sys->staff+my_sys->len)->mon1 >>(my_sys->staff+my_sys->len)->mon2 >>(my_sys->staff+my_sys->len)->mon3 >>(my_sys->staff+my_sys->len)->mon4 >>(my_sys->staff+my_sys->len)->mon5; (my_sys->staff + my_sys->len)->id = my_sys->len+1; my_sys->len += 1; } //查找职工信息 void Select(System * my_sys) { if(my_sys->len == 0) { cout<<"系统中没有保存职工信息"< } else { cout<<"请输入所要查询的职工姓名:"; char Name[10]={0}; cin>>Name; size_t i = 0; for( i = 0;i < my_sys->len; i++) { if(strcmp(Name,(my_sys->staff+i)->name)==0) { cout<<"该职工信息为:"< cout<<"ID号 姓名 基本工资 职务工资 津贴 医疗保险 公积金 总工资 平均工资"< my_sys->staff->print(); break; } } if(i >= my_sys->len) cout<<"系统中没有此职工信息"< } } void menu1() { cout<<"请选择要修改的信息:"< cout<<"***********************************************"< cout<<"****** 1.修改职工姓名 ******"< cout<<"****** 2.修改基本工资 ******"< cout<<"****** 3.修改职务工资 ******"< cout<<"****** 4.修改紧贴 ******"< cout<<"****** 5.修改医疗保险 ******"< cout<<"****** 6.修改公积金 ******"< cout<<"***********************************************"< } //修改职工信息 void Update(System * my_sys) { if(my_sys->len == 0) { cout<<"系统中没有保存职工信息"< } else { cout<<"请输入所要修改的职工姓名:"; char Name[MAX_NAME]={0}; cin>>Name; size_t i = 0; for( i = 0;i < my_sys->len; i++) { if(strcmp(Name,(my_sys->staff+i)->name)==0) { menu1(); cout<<"请选择对应数字序号进行操作:"; int a =0 ; char name[MAX_NAME] ={0}; double mon1 =0.0,mon2 =0.0,mon3 =0.0,mon4 =0.0,mon5 =0.0; cin>>a; switch(a) { case 1: cout<<"请输入新的职工姓名:"; cin>>name; strcpy(my_sys->staff->name,name); break; case 2 : cout<<"请输入新的基本工资:"; cin>>mon1; my_sys->staff->mon1 = mon1; break; case 3: cout<<"请输入新的岗位工资:"; cin>>mon2; my_sys->staff->mon2 = mon2; break; case 4: cout<<"请输入新的岗位工资:"; cin>>mon3; my_sys->staff->mon3 = mon3; break; case 5 : cout<<"请输入新的岗位工资:"; cin>>mon4; my_sys->staff->mon4 = mon4; break; case 6: cout<<"请输入新的岗位工资:"; cin>>mon5; my_sys->staff->mon5 = mon5; break; default: cout<<"输入不合标准"< break; } break; } } if(i >= my_sys->len) cout<<"系统中没有此职工信息"< } } //删除职工信息 void Delete(System * my_sys) { if(my_sys->len == 0) { cout<<"系统中没有保存职工信息"< } else { cout<<"请输入所要删除的职工姓名:"; char Name[MAX_NAME]={0}; cin>>Name; size_t i = 0; size_t m = my_sys->len; for( i = 0;i < my_sys->len; i++) { if(strcmp(Name,(my_sys->staff+i)->name)==0) { for(size_t j = i;j *(my_sys->staff+j) = *(my_sys->staff+j+1); my_sys->len--; break; } } if(i >= m) cout<<"系统中没有此职工信息"< } } //统计:统计符合指定条件(如职工工资前三项之和在3000元以上、3000~2000元、2000~1000元) //以内的工资职工人数及占总职工人数的百分比。 void tongji(System * my_sys) /* m-n为 1000-2000,2000-3000,3000-max*/ { double number = 0.0; double money = 0.0; double m =0.0; double n = 0.0; if(my_sys->len == 0) { cout<<"系统中没有保存职工信息"< } else { cout<<"请输入你要统计的职工信息指定的条件m 和 n:"; cin>>m>>n; for(size_t i = 0; i { money = (my_sys->staff+i)->mon1 + (my_sys->staff+i)->mon2 + (my_sys->staff+i)->mon3; if((money >= m)&& (money <= n)) number++; } cout<<"职工工资前三项之和在 " < } } //求每一项的平均值 void money(System * my_sys) { double count1 = 0; double count2 = 0; double count3 = 0; double count4 = 0; double count5 = 0; if(my_sys->len> 0) { for(size_t i = 0;i< my_sys->len; i++) { count1 = count1 + my_sys->staff->mon1; count2 = count2 + my_sys->staff->mon1; count3 = count3 + my_sys->staff->mon1; count4 = count4 + my_sys->staff->mon1; count5 = count5 + my_sys->staff->mon1; } cout<<"各项工资的平均工资为 " < < < < < } } //从文件读取职工信息 void Read(System *my_sys) { Staff s; FILE *pf =fopen(FILENAME,"r"); if(pf == NULL) { perror("error:"); Free(my_sys); exit(EXIT_FAILURE); } while(fread(&s,sizeof(Staff),1,pf))//从文件中读取数据,,直到读取的为空 { IF_space(my_sys); my_sys->staff[my_sys->len++] = s; } fclose(pf);//记着关闭文件 } //将职工信息写入文件 void Save(System *my_sys) { FILE *pf = fopen(FILENAME,"w"); if(pf==NULL) { perror("error:"); Free(my_sys); exit(EXIT_FAILURE); } for(size_t i=0; i { fwrite(my_sys->staff+i,1,sizeof(Staff),pf); } fclose(pf); } void Free(System *my_sys) { if(my_sys->staff!= NULL) { free(my_sys->staff); my_sys->staff=NULL; } }