加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

员工管理系统c语言程序设计源代码

(2010-06-10 11:38:40)
标签:

杂谈

分类: C源码

#include<string.h>
#include<stdio.h>
#define N 10000     
typedef struct wage
{
float wage1;     
float Bonus;    
float tax;      
float S_fee;    
float D_fee;    
float T_fee;    
float Q_fee;    
float S_wage;    
}WAGE;
typedef struct worker
{
      char name[10];      
char ID[10];        
      int ID_P;           
char ID_Wage[10];   
char depart[10];    
    int age;            
char sex;           
char m_phone[10];   
char H_phone[10];   
      WAGE salary;

}WORK;
WORK wo[N];
int n;

void menu();

void menu1();


save()                       
{
int w=1;
FILE *fp;
int i;
system( "cls" );
if((fp=fopen("work.txt","wb"))==NULL)     
{
    printf("\nCannot open file\n");
    return NULL;
}
      for(i=0;i<n;i++)
if(fwrite(&wo[i],sizeof(struct worker),1,fp)!=1)
      
       printf("file write error\n");
    w=0;
}
if(w==1)
{
      printf("file save ok!\n");
}
fclose(fp);
getch();    
menu();
}

 


load()                        
{
FILE *fp;
int i,w;
w=1;
system( "cls" );
if((fp=fopen("work.txt","rb"))==NULL)     
{
    printf("\nCannot open file\n");
    w=0;
    return NULL;
}
n=0;
for(i=0;!feof(fp);i++)
  
    fread(&wo[i],sizeof(struct worker),1,fp);
    n++;
}
n=n-1;
fclose(fp);
if(w==1)
     printf("Load file ok!");
getch();    
menu();
return(i-1);                 
}

 

void no_input(int i,int n)                   
{
int j,k,w1;
do
{
        w1=0;
     printf("NO.:");
     scanf("%s",wo[i].ID);
     for(j=0;wo[i].ID[j]!='\0';j++)           
     if(wo[i].ID[j]<'0'||wo[i].ID[j]>'9')      
     {
            puts("Input error! Only be made up of (0-9).Please reinput!\n");
      w1=1;
            break;
     }
           if(w1!=1)
           for(k=0;k<n;k++)                 
                                       
           if(k!=i&&strcmp(wo[k].ID[j],wo[i].ID[j])==0)     
     {
              puts("This record is exist. please reinput!\n");
              w1=1;
     break;
     }
}while(w1==1);
}

 

float tax(float s)
{
float tax;
if(s<=800)
    tax=0;
else if(s>800&&s<=1400)
    tax=(s-800)*0.05;
      else if(s>1400)
    tax=(s-1400)*0.1+600*0.05;
     return tax;
}

 

void input(int i)                            
{
      int j,sum;
      no_input(i,i);                       
      printf("name:");
fflush(stdin);
gets(wo[i].name);
printf("Bank ID:");
fflush(stdin);
gets(wo[i].ID_Wage);
printf("grade");
scanf("%d",&wo[i].ID_P);
printf("Department:");
fflush(stdin);
gets(wo[i].depart);
      printf("age:");
scanf("%d",&wo[i].age);
      printf("sex:");
fflush(stdin);
scanf("%c",&wo[i].sex);
      printf("mobile phone");
fflush(stdin);
gets(wo[i].m_phone);
      printf("home phone");
fflush(stdin);
gets(wo[i].H_phone);
printf("basic salary");
scanf("%f",&wo[i].salary.wage1);
wo[i].salary.tax=tax(wo[i].salary.wage1);
printf("Bonus:");
scanf("%f",&wo[i].salary.Bonus);
printf("water fee:");
scanf("%f",&wo[i].salary.S_fee);
printf("dian fee:");
scanf("%f",&wo[i].salary.D_fee);
printf("QingJie fee:");
scanf("%f",&wo[i].salary.Q_fee);
printf("TV fee:");
scanf("%f",&wo[i].salary.T_fee);
      wo[i].salary.S_wage=wo[i].salary.wage1+wo[i].salary.Bonus-wo[i].salary.tax-wo[i].salary.D_fee-wo[i].salary.Q_fee-wo[i].salary.S_fee-wo[i].salary.T_fee;
}

 


void enter()

{
int i;
system( "cls" );
printf("How many record(0-%d)?:",N);
scanf("%d",&n);                   
printf("\nEnter data now\n\n");
for(i=0;i<n;i++)
{
        printf("\nInput %dth record.\n",i+1);
     input(i);                         
    }
getch();  
menu();
}

 

void printf_one(int i)                               
{
int j;
printf("%11s    %-6s    %-6s     %d    %d    %c    %6.2f    %s     %s",wo[i].ID,wo[i].name,wo[i].ID_Wage,wo[i].ID_P,wo[i].age,wo[i].sex,wo[i].salary.S_wage,wo[i].m_phone,wo[i].H_phone);

}

void printf_one_s(int i)                               
{
int j;
printf("      %8.2f    %8.2f    %8.2f    %8.2f    %8.2f    %8.2f    %8.2f    %8.2f",wo[i].salary.wage1,wo[i].salary.S_wage,wo[i].salary.Bonus,wo[i].salary.D_fee,wo[i].salary.Q_fee,wo[i].salary.S_fee,wo[i].salary.T_fee,wo[i].salary.tax);

}

 

void browse()                           
{
int i,j;
system( "cls" );
puts("\n--------------------------------------------------------------------");
printf("\n\t工号 姓名 银行卡号    职称 年龄    性别    实发工资 手机 住宅电话\n");
for(i=0;i<n;i++)
{
      if((i!=0)&&(i%10==0))                
      {
           printf("\n\nPass any key to contiune    . . .");
     getch();
     puts("\n\n");
      }
       printf_one(i);                  
    printf("\n");
}
puts("\n--------------------------------------------------------------------");
printf("\tThere are    %d record.\n",n);
getch();                           
menu();
}

 

int search_by_ID()                           
{
int i,k;
struct worker s;
k=-1;
system( "cls" );
printf("\n\nEnter the ID:");
scanf("%s",s.ID);                 
for(i=0;i<n;i++)                   
{

    if(strcmp(s.ID,wo[i].ID)==0)
    {
     k=i;                       
           printf("\n\t工号 姓名 银行卡号    职称 年龄    性别    实发工资 手机 住宅电话\n");
              printf_one(k);
     printf("工资信息:\n");
           printf("\n\t基本工资     实发工资     奖金      电费       清洁费      水费      电视费       税金\n");
              printf_one_s(k);   
        break;                   
    }
}
if(k==-1)
{
     printf("\n\nNO exist!");
         getch();  
          menu1();
     return -1;
}
else
{
         getch();  
          menu1();
     return k;
}
}

 

int search_by_age()                           
{
int i,k,t_age,b_age;
struct worker s;
k=-1;
system( "cls" );
printf("\n\nEnter the top age:");
scanf("%d",&t_age);            
printf("\n\nEnter the    bottom age:");
scanf("%d",&b_age);  
printf("\n\t工号 姓名 银行卡号    职称 年龄    性别    实发工资 手机 住宅电话\n");
          
for(i=0;i<n;i++)                   
{

    if(wo[i].age>=b_age&&wo[i].age<=t_age)
    {
     k=i;                       
              printf_one(k);
        break;                   
    }
}
if(k==-1)
{
     printf("\n\nNO exist!");
         getch();  
          menu1();
     return -1;
}
else
{
         getch();  
          menu1();
     return k;
}


}

 

void count_by_P()                           
{
int i,k;
float S_sal[3]={0,0,0},sal[3]={0,0,0},bon[3]={0,0,0},tax[3]={0,0,0};
      system( "cls" );
for(i=0;i<n;i++)                   
{

    if(wo[i].ID_P==1)
    {
     S_sal[0]=S_sal[0]+wo[i].salary.S_wage;
     sal[0]=sal[0]+wo[i].salary.wage1;
     bon[0]=bon[0]+wo[i].salary.Bonus;
     tax[0]=tax[0]+wo[i].salary.tax;

    }
    else if(wo[i].ID_P==2)
    {
     S_sal[1]=S_sal[1]+wo[i].salary.S_wage;
     sal[1]=sal[1]+wo[i].salary.wage1;
     bon[1]=bon[1]+wo[i].salary.Bonus;
     tax[1]=tax[1]+wo[i].salary.tax;

    }
    else if(wo[i].ID_P==3)
    {
     S_sal[2]=S_sal[2]+wo[i].salary.S_wage;
     sal[2]=sal[2]+wo[i].salary.wage1;
     bon[2]=bon[2]+wo[i].salary.Bonus;
     tax[2]=tax[2]+wo[i].salary.tax;

    }
}
      printf("\n级别为高级工程师的工资统计为:\n");
printf("实发工资:%f,基本工资:%f,奖金:%f,税金:%f\n",S_sal[0],sal[0],bon[0],tax[0]);
printf("\n级别为中级工程师的工资统计为:\n");
printf("实发工资:%f,基本工资:%f,奖金:%f,税金:%f\n",S_sal[1],sal[1],bon[1],tax[1]);
printf("\n级别为初级工程师的工资统计为:\n");
printf("实发工资:%f,基本工资:%f,奖金:%f,税金:%f\n",S_sal[2],sal[2],bon[2],tax[2]);
printf("\n公司所有人员的工资统计为:\n");
printf("实发工资:%f,基本工资:%f,奖金:%f,税金:%f\n",S_sal[2],sal[2],bon[2],tax[2]);
getch();  
menu1();


}

 

 

void order()                            
{
int i,j,k;
struct worker s;
system( "cls" );
for(i=0;i<n-1;i++)               
{
    k=i;
    for(j=i+1;j<n;j++)
    if(wo[j].salary.S_wage>wo[k].salary.S_wage)
    k=j;
    s=wo[i];
       wo[i]=wo[k];
       wo[k]=s;
    }
printf("The ordered data is:\n");
browse();
getch();  
menu1();
}

 

 

void menu1()
{
int n,w1;
      do
      {
          system( "cls" );                    
          puts("\t\t\t\t    员工管理操作!\n\n");
          puts("\t\t*********************MENU*********************\n\n");
          puts("\t\t\t\t1.search by ID");
          puts("\t\t\t\t2.search by age");
          puts("\t\t\t\t3.count salary");
          puts("\t\t\t\t4.order by salary");
          puts("\t\t\t\t5.return to menu");
          puts("\n\n\t\t**********************************************\n");
          printf("Choice your number(1-5): [ ]\b\b");
          scanf("%d",&n);
          if(n<0||n>5)                                   
         {
            w1=1;
            printf("your choice is not between 1 and 4,Please input again:");
            getchar();
          }
         else    w1=0;
      } while(w1==1);


switch(n)
{
       case 1:search_by_ID();break;       
       case 2:search_by_age();break;     
       case 3:count_by_P();break;      
       case 4:order();break;     
       case 5:menu();
    }

}

void menu()
{
int n,w1;
      do
      {
          system( "cls" );                    
          puts("\t\t\t\t    员工管理系统!\n\n");
          puts("\t\t*********************MENU*********************\n\n");
          puts("\t\t\t\t1.Enter new data");
          puts("\t\t\t\t2.Browse all");
          puts("\t\t\t\t3.opreration");
          puts("\t\t\t\t4.Save file");
          puts("\t\t\t\t5.Load file");
          puts("\t\t\t\t6.Exit");
          puts("\n\n\t\t**********************************************\n");
          printf("Choice your number(1-6): [ ]\b\b");
          scanf("%d",&n);
          if(n<0||n>6)                                   
         {
            w1=1;
            printf("your choice is not between 1 and 7,Please input again:");
            getchar();
          }
         else    w1=0;
      } while(w1==1);

switch(n)
{
       case 1:enter();break;       
       case 2: browse();break;     
       case 3:menu1();break;      
       case 4:save();break;      
       case 5:n=load();break;      
       case 6:exit(0);
    }
}

main()
{
menu();
}

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有