关于事务处理的.谢谢
有一磁盘文件,内存放职工的数据,每个职工数据包括:职工姓名,职工号,性别,年龄,工资,住址,健康状况,文化程度.现在要求建立一个管理系统,能随时对职工的信息进行增加,删除,和修改操作,并且把显示在屏幕上(即打印出),这些操作由用户自己选择,用swith()语句. 问题点数:20、回复次数:3Top
1 楼lbaby(春天来了...)回复于 2006-06-04 17:16:19 得分 0
来句风凉话,我还真的以为是事务处理呢
Top
2 楼ywhbn(天涯)回复于 2006-06-04 19:30:00 得分 0
此题无解!Top
3 楼paodan(蛋)回复于 2006-06-05 13:24:39 得分 0
这是我的原码,但文件里有乱码出现,不知哪里错了.
#include"stdio.h"
struct worker {
char name[16];
int NO.;
char sex[8];
int age;
char addr[30];
int wages;
char healcontion[20];
char CulturalLevel[20];
}
main(void){
FILE *fp;
int choice;
int EnterChoice(void);
void UpdateRecord(FILE *fp);
void AddRecord(FILE *fp);
void DeleteRecord(FILE *fp);
void ModifyRecord(FILE *fp);
if((fp=fopen("d:\\emplyee.txt","r+"))==NULL)
fp=fopen("d:\\emplyee.txt","w+");
else{
clrscr();
while((choice=EnterChoice())!=5){
clrscr();
switch(choice){
case 1:UpdateRecord(fp);break;
case 2:AddRecord(fp);break;
case 3:DeleteRecord(fp);break;
case 4:ModifyRecord(fp);break;
}
}
}
fclose(fp);
}
int EnterChoice(){
int menuchoice,flag=1;
printf("Please input your choice:\n"
"1:Update information\n"
"2:Add information\n"
"3:Delete information\n"
"4:Modify information\n"
"5:Quit\n");
while(flag){
scanf("%d",&menuchoice);
if(menuchoice>6||menuchoice<0)
printf("ERROR!Please input again!\n");
else return menuchoice;
}
}
void UpdateRecord(FILE *fp){
int amount;
struct worker record;
printf("Please input the amount of the worker!\n");
scanf("%d",&amount);
rewind(fp);
while(amount>0){
printf("Please input the worker's name:\n");
scanf("%s",record.name);
printf("Please input the worker's NO.:\n");
scanf("%d",&record.code);
printf("Please input the worker's sex:\n");
scanf("%s",record.sex);
printf("Please input the worker's age:\n");
scanf("%d",&record.age);
printf("Please input the worker's address:\n");
scanf("%s",record.addr);
printf("Please input the worker's wages:\n");/*工资*/
scanf("%d",&record.salary);
printf("Please input the worker's healcontion:\n");/*健康状况*/
scanf("%s",record.HealthCondition);
printf("Please input the worker's culturallevel:\n");
scanf("%s",record.CulturalLevel);
fwrite(&record,sizeof(struct worker),1,fp);
amount--;
}
}
void AddRecord(FILE *fp){
struct worker record;
fseek(fp,0L,SEEK_END);
printf("Please input the worker's name:\n");
scanf("%s",record.name);
printf("Please input the worker's NO.:\n");
scanf("%d",&record.code);
printf("Please input the worker's sex:\n");
scanf("%s",record.sex);
printf("Please input the worker's age:\n");
scanf("%d",&record.age);
printf("Please input the worker's address:\n");
scanf("%s",record.addr);
printf("Please input the worker's wages:\n");
scanf("%d",&record.salary);
printf("Please input the worker's healcontion:\n");
scanf("%s",record.HealthCondition);
printf("Please input the worker's culturallevel:\n");
scanf("%s",record.CulturalLevel);
fwrite(&record,sizeof(struct worker),1,fp);
}
void DeleteRecord(FILE *fp){
struct worker record,blankrecord={" ",0," ",0," ",0," "," "};
int num;
printf("Please input the worker'code you want to delete:\n");
scanf("%d",&num);
fseek(fp,(num-1)*sizeof(struct worker),SEEK_SET);
fread(&record,sizeof(struct worker),1,fp);
if(record.code==0)
printf("The worker of %d doesn't exist!\n");
else{
fseek(fp,(num-1)*sizeof(struct worker),SEEK_SET);
fwrite(&blankrecord,sizeof(struct worker),1,fp);
}
}
void ModifyRecord(FILE *fp){
struct worker record;
int num;
printf("Please input the worker's code that you want to modify!\n");
scanf("%d",&num);
fseek(fp,(num-1)*sizeof(struct worker),SEEK_SET);
fread(&record,sizeof(struct worker),1,fp);
if(record.code==0)
printf("The worker of %d doesn't exist!\n");
else{
printf("Please input the worker's name:\n");
scanf("%s",record.name);
printf("Please input the worker's NO.:\n");
scanf("%d",&record.code);
printf("Please input the worker's sex:\n");
scanf("%s",record.sex);
printf("Please input the worker's age:\n");
scanf("%d",&record.age);
printf("Please input the worker's address:\n");
scanf("%s",record.addr);
printf("Please input the worker's wages:\n");
scanf("%d",&record.salary);
printf("Please input the worker's healcontion:\n");
scanf("%s",record.HealthCondition);
printf("Please input the worker's culturallevel:\n");
scanf("%s",record.CulturalLevel);
fseek(fp,(num-1)*sizeof(struct worker),SEEK_SET);
fwrite(&record,sizeof(struct worker),1,fp);
}
}
Top




