CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
不看会后悔的Windows XP之经验谈 简单快捷DIY实用家庭影院
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

关于事务处理的.谢谢

楼主paodan(蛋)2006-06-04 12:02:58 在 C/C++ / C语言 提问

有一磁盘文件,内存放职工的数据,每个职工数据包括:职工姓名,职工号,性别,年龄,工资,住址,健康状况,文化程度.现在要求建立一个管理系统,能随时对职工的信息进行增加,删除,和修改操作,并且把显示在屏幕上(即打印出),这些操作由用户自己选择,用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

相关问题

关键词

得分解答快速导航

  • 帖主:paodan

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo