您的位置首页百科问答

职工信息管理系统

职工信息管理系统

的有关信息介绍如下:

职工信息管理系统

我有一个类似的,你把结构内容修改一下就好啦!别喷我……因为这两个几乎一个意思的。觉得还行就采纳吧,最好给点分,这个太少了……#include#includestruct clientData{//定义结构 int record; char s[21]; int amount; float price;};int enterChoice(void);void newRecord(FILE* fPtr);void listRecord(FILE* fPtr);void addRecord(FILE* fPtr);void deleteRecord(FILE* fPtr);//函数声明main(){ int choice;//存储用户输入的数字 FILE* fPtr=NULL; if((fPtr=fopen("hardware.dat","r+"))==NULL)//如果不存在进行提示 { printf("can't open the file hardware.dat.\nYou should establish one first!\n"); if((fPtr=fopen("hardware.dat","w"))!=NULL)//用w方式打开,创建文件 printf("The file hardware.dat is established now.Please run again\n"); } else//成功打开 { choice=enterChoice();//读入用户的选择 while(choice!=5)//循环进行操作 { switch(choice)//进行选择 { case 1: newRecord(fPtr); break; case 2: listRecord(fPtr); break; case 3: addRecord(fPtr); break; case 4: deleteRecord(fPtr); break; default: printf("A wrong input\n"); } choice=enterChoice(); } fclose(fPtr);//关闭文件 } system("pause"); return 0;}int enterChoice(void)//读取用户选择的函数{ int choice; printf("\nPlease enter your choice\n" "1 - set up a new record\n" "2 - list the record\n" "3 - add account(s) to the list\n" "4 - delete an account in the list\n" "5 - end of run\n?");//打印提示 scanf("%d",&choice); return choice;}void newRecord(FILE* fPtr)//进行初始化的函数{ int i; struct clientData blank={0,"",0,0.0};//建立空结构 rewind(fPtr); for(i=1;i<=100;i++) fwrite(␣,sizeof(struct clientData),1,fPtr); printf("The list is empty now\n"); return;}void listRecord(FILE* fPtr)//打印文件内容的函数{ struct clientData data; rewind(fPtr); printf("Record Name \t\t Amount Price\n");//打印第一行 fread(&data,sizeof(struct clientData),1,fPtr); while(!feof(fPtr)) { if(data.record!=0)//当记录不是空时打印数据 printf("%5d %-20s %5d %7.2f\n", data.record,data.s,data.amount,data.price); fread(&data,sizeof(struct clientData),1,fPtr); } return;}void addRecord(FILE* fPtr)//添加的记录函数{ struct clientData data; printf("\nPlease input the account number 1-100,0 to end\n" "If the account is existential, this will erase former data!\n?"); scanf("%d",&data.record); while(data.record!=0)//循环进行添加 { if(data.record<1||data.record>100) printf("Please input the right number!\n");//错误提示 else { printf("Please input the name,enter to end(no longer than 20)\n?"); getchar();//必须加入,否则会读入回车出错! gets(data.s);//gets函数只用加上地址即可,不用%s!! printf("Pease input amount(an integer), the price:\n?"); scanf("%d,%f",&data.amount,&data.price);//读入数据 fseek(fPtr,(data.record-1)*sizeof(struct clientData),SEEK_SET);//查找位置读入 fwrite(&data,sizeof(struct clientData),1,fPtr); printf("Add successfully!\n\n"); } printf("Please input the account number 1-100,0 to end\n?");//再次读入 getchar(); scanf("%d",&data.record); } return;}void deleteRecord(FILE* fPtr)//删除记录的函数{ struct clientData data; struct clientData blank={0,"",0,0.0};//空结构 printf("Please input the account number you want to delete\n?"); scanf("%d",&data.record); fseek(fPtr,(data.record-1)*sizeof(struct clientData),SEEK_SET);//进行定位 fread(&data,sizeof(struct clientData),1,fPtr); if(data.record==0) printf("Account %d doesn't exist!\n"); else {//由于查找后读入一次,位置指针已经变化,需要再次定位 fseek(fPtr,(data.record-1)*sizeof(struct clientData),SEEK_SET); fwrite(␣,sizeof(struct clientData),1,fPtr);//写入空记录 printf("The account is removed!\n\n"); } return;}