《c語言課程設計 職工信息管理系統(tǒng)》由會員分享,可在線閱讀,更多相關《c語言課程設計 職工信息管理系統(tǒng)(8頁珍藏版)》請在裝配圖網上搜索。
1、C語言課程設計
1. 設計題目:職工信息管理系統(tǒng)
2. 系統(tǒng)功能簡介:
系統(tǒng)以菜單方式工作
1) 職工信息錄入(文件保存職工信息)
2) 輸出職工信息、瀏覽職工信息
3) 查詢職工信息
4) 根據員工號查找職工信息
5) 根據工資、年齡、性別對職工信息進行排序
6) 刪除職工信息
3. 設計實施:
#include
#include
#include typedef struct Empk {
int EmpNum;
/* staff number */
char EmpName[12];
/*
2、name*/
int Sex;
/*sex 1- woman 2- man*/
int Old;
/* old*/
int Cult;
/*education background 1-specilist 2-doctor 3-others*/
int Salary;
/*salary*/
char Address[12];
/* address*/
int Tell;
/*telephone number*/
}Emp;
Emp emp[100];
void open()
{
int i;
FILE *fp;
if((fp=fopen(〃wyl〃,〃
3、rb+〃))==NULL)
{printf("can not do it! Because of no file of information、/);
exit(0);}
for(i=0;i<100;i++)
{if(fread(&emp[i],sizeof(Emp),1,fp)==0)
{printf("Fail to output\n〃);
exit(0);}
}
fclose(fp);
}
void close() /* 跳出 */
{
int i;
FILE *fp;
if((fp=fopen(〃wyl〃,〃wr+〃))==NULL)
{printf("c
4、an not do it!\n〃);
exit(0);}
for(i=0;i<100;i++)
fwrite(&emp[i],sizeof(Emp),1,fp);
fclose(fp);
}
void inputEmpInfo() /*輸入信息 */
{
int i,k;
for(i=0;i<100;i++)
{
printf("Please enter the staff's :\nnumber:〃);
scanf(〃%d〃,&emp[i].EmpNum);
printf(〃\nname:〃);
scanf(〃%s〃,emp[i].EmpName);
print
5、f("\nsex : 1- woman 2- man:");
scanf(〃%d〃,&emp[i].Sex);
printf("\nold:");
scanf(〃%d〃,&emp[i].Old);
printf("\nEducation background:1-specialist 2-doctor 3-others");
scanf(〃%d〃,&emp[i].Cult);
printf("\nsalary:");
scanf(〃%d〃,&emp[i].Salary);
printf("\naddress:");
scanf("%s",emp[i].Address);
p
6、rintf(〃\ntellphone:〃);
scanf(〃%d〃,&emp[i].Tell);
printf("continue?(1.yes 2.no)〃); scanf(〃%d〃,&k); if(k==2) break; }
close();
}
void reorder() /* 修改 */
{
int i,s,j,k,l;
Emp temp;
open();
printf("\nChoose which category would you want to use\n1 sex \n2 salary(from
maximum to minimum) \n3—ol
7、d (from maximum to minimum) \n ( enter the
corresponding nember) \n)〃); scanf(〃%d〃,&i);
switch(i)
{
case 1:
printf("\nchoose which sex do you want to inquire? 1—woman 2 —man "); scanf(〃%d〃,&s);
for(j=0;emp[j].EmpNum!=0;j++)
{
if(emp[j].Sex==s)
{
printf(" number:%d\n〃,emp[j].EmpNum);
print
8、f(〃name:%s〃, emp[j].EmpName);
printf("\nsex 1- woman 2- man:%d", emp[j].Sex);
printf(〃\nold:%d〃, emp[j].Old);
printf("\neducation background:%d\t\t\t 1-specialist 2-doctor 3-others 〃,emp[j].Cult);
printf(〃\nsalary:%d〃, emp[j].Salary);
printf(〃\naddress:%s〃, emp[j].Address);
printf("\ntelephone
9、 nember :%d", emp[j].Tell);
}
}
break;
case 2:
for(k=0;emp[k].EmpNum!=0;j++ )
{
for(l=k;emp[l].EmpNum!=0;l++)
if(emp[l].Salary
10、- man:%d〃,emp[k].Sex);
printf(〃\nold:%d〃,emp[k].Old);
printf("\neducation background:%d\t\t\t 1-specialist 2-doctor 〃,emp[k].Cult);
printf(〃\nsalary:%d〃,emp[k].Salary);
printf(〃\nadress:%s〃,emp[k].Address);
printf("\ntelephone nember :%d〃,emp[k].Tell);
}
break;
case 3:
for(k=0;emp[k].EmpNum
11、!=0;j++ )
{
for(l=k;emp[l].EmpNum!=0;l++)
{
if(emp[l].Old
12、background:%d\t\t\t 1-specialist
3-others〃,emp[k].Cult);
printf(〃\nsalary:%d〃,emp[k].Salary);
printf(〃\naddress:%s〃,emp[k].Address);
printf("\ntelephone nember :%d",emp[k].Tell);
}
break;
}
}
void show()
{
int j;
open();
printf("\n informations
3-others
2-doctor
of
sraffs \n〃);
for
13、(j=0;emp[j].EmpNum!=0;j++)
{
printf(〃number:%d\n〃,emp[j].EmpNum);
printf(〃name:%s〃,emp[j].EmpName);
printf("\nsex 1- woman 2- man:%d〃,emp[j].Sex);
printf(〃\nold:%d〃,emp[j].Old);
printf("\neducation background:%d 1-specialist 2-doctor 3-others
〃,emp[j].Cult);
printf(〃\nsalary:%d〃,emp[j].Salar
14、y);
printf(〃\nadress:%s〃,emp[j].Address);
printf("\ntelephone nember :%d",emp[j].Tell);
}
}
void deleteEmp()
{
int j,k,m=1,d,i=0;
open();
printf("Enter the number whose date you want to delete:\n〃);
scanf(〃%d〃,&d);
for(j=0;emp[j].EmpNum!=0;j++)
{
if(emp[j].EmpNum==d)
{
for(k=j;emp[j].
15、EmpNum!=0;k++)
emp[k]=emp[k+1];
i++;
}
}
if(i==0)
printf("The staffs informations manage systerm has no date of the number your entered!!!\n〃);
close();
printf("succeeed to delete\n〃);
}
void findByEmpName() /* 查詢 */ { int j,i,k=0;
open();
printf("Please enter the number :\n〃); scanf(〃%d
16、〃,&i);
for(j=0;emp[j].EmpNum!=0;j++)
{if(emp[j].EmpNum==i)
{
printf("\n information of your want
\n〃);
printf(〃number:%d\n〃,emp[j].EmpNum);
printf(〃name:%s〃,emp[j].EmpName);
printf("\nsex 1- woman 2- man:%d〃,emp[j].Sex);
printf(〃\nold:%d〃,emp[j].Old);
printf("\neducation background:%d\t\t
17、\t\t 1-specialist 2-doctor 3-others 〃,emp[j].Cult);
printf(〃\nsalary:%d〃,emp[j].Salary);
printf(〃\nadress:%s〃,emp[j].Address);
printf("\ntelephone number:%d〃,emp[j].Tell);
k++;
}
}
if(k==0)
printf("\nHave no date of the number!!!\n〃);
}
void menu()
{
printf("\n
\n〃);
printf("\n Wellc
18、ome to the staff manage styterm
\n〃);
printf("\n
\n〃);
printf("Please choose number for what are you want to do:\n\n〃);
printf("\n 1 input: Complete inputing workers' information.");
printf("\n 2 reorder: Make the new order of the information.");
printf("\n 3 delete: Delete the inform
19、ation of the staff.");
printf("\n 4 output: Display all worker of information.");
printf("\n 5 inquire.");
printf("\n 0 exit\n");
}
void main()
{
int op,choice=1;
while(choice==1)
{
menu();
printf("\nPlease enter your order:\n");
scanf("%d",&op);
switch(op)
{case 1: inputEmpInfo();b
20、reak;
case 2: reorder();break;
case 3: deleteEmp();break;
case 4: show();break;
case 5: findByEmpName();break;
case 0: {printf("Welcome to use worker management system, goodbye!!!");
exit(0);}
getchar();}
printf("\n
\n");
printf("\nWhether continue? Yes-1 No—2\n");
scanf("%d”,choice);
}
}