CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
IBM Rational 系统开发最佳实践工具包 WebSphere MQ 最佳实践 TOP 15
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

网吧计费程序,高手看看?

楼主jamesfangjing(Bayes)2001-10-13 08:48:38 在 C/C++ / C语言 提问

/*这个程序主要用来网吧计费*/    
  /*头文件head.h*/    
  #include<conio.h>    
  #include<dos.h>    
  #include<stdio.h>    
  #include<stdlib.h>    
  #include<time.h>    
   
  /*主函数main*/    
  #include   "fees\head.h"    
  #include   "fees\up.c"                   /*上机函数up*/    
  #include   "fees\down.c"               /*下机函数down*/    
  #include   "fees\money.c"             /*加钱函数money*/    
  main()    
  {    
  while(1)    
        {int   button;    
          clrscr();    
          printf("Press   the   button   :   \n");    
          printf("1   Let's   go   !   \n");    
          printf("2   Goodbye   !   \n");    
          printf("3   Give   me   money   !   \n");    
          printf("4   End   the   program.\n");    
          scanf("%d",&button);    
          switch(button)    
                {case   1:up();break;    
                  case   2:down();break;    
                  case   3:money();break;    
                  case   4:exit(0);    
                  default:printf("You   press   the   wrong   botton   !   \n");    
                                  printf("Press   again   !   \n");    
                }    
        }    
  }    
   
  /*上机函数up*/    
  #include"fees\head.h"    
  void   up()    
  {    
  struct   student               /*这个结构体在其它函数中变量名相同,作用相同*/    
                                            /*实际上这几个函数的作用机制都相同,一看就明白*/    
        {long   int   num;     /*上机者的卡号*/    
          float   money;       /*上机者的钱*/    
          time_t   *times;   /*上机者的上机时间*/    
        }stdt,std;             /*stdt用来暂时存放数据,std用来从文件中读取数据*/    
  FILE   *fp;    
  fp=fopen("fees\student.txt","r+");   /*关键就在这一句,找不到合适的,r+实际上是先读完再写,但这里我要求,一打开就又能读又能写,该用什么?*/    
  printf("Please   enter   the   number   :   \n");    
  scanf("%ld",&stdt.num);    
  rewind(fp);       /*文件指针指向文件开始处*/    
  while(fread(&std,sizeof(struct   student),1,fp)==1)    
          {if(stdt.num==std.num)    
                {stdt.money=std.money;    
                  fseek(fp,-sizeof(struct   student),1);    
                  break;}    
          }    
  if(feof(fp))    
        {printf("Please   enter   the   money   :   \n");    
          scanf("%f",&stdt.money);}    
  printf("Your   number   is   :   %ld",stdt.num);    
  printf("\nYour   money   is   :   %.2f",stdt.money);    
  sleep(3);    
  time(stdt.times);     /*获得当前时间*/    
  fwrite(&stdt,sizeof(struct   student),1,fp);    
  fclose(fp);    
  }    
   
  /*下机函数down*/    
  #include"fees\head.h"    
  void   down()    
  {    
  float   hour,differ;    
  struct   student    
        {long   int   num;    
          float   money;    
          time_t   *times;    
        }stdt,std;    
  time_t   t,*timee=&t;    
  FILE   *fp;    
  fp=fopen("fees\student.txt","r+");    
  printf("Please   enter   the   number   :   \n");    
  scanf("%ld",&stdt.num);    
  rewind(fp);    
  while(fread(&std,sizeof(struct   student),1,fp)==1)    
          {if(stdt.num==std.num)    
                {stdt.money=std.money;    
                  *stdt.times=*std.times;    
                  break;}    
          }    
  time(timee);    
  differ=(float)(difftime(*timee,*stdt.times));    
  hour=differ/60/60;    
  stdt.money=stdt.money-hour*1.5;    
  printf("Your   number   is   :   %ld",stdt.num);    
  printf("\nYour   money   is   :   %.2f",stdt.money);    
  sleep(3);    
  if(stdt.money<=0)   printf("You   must   add   some   money   !   \n");    
  fseek(fp,-sizeof(struct   student),1);    
  fwrite(&stdt,sizeof(struct   student),1,fp);    
  fclose(fp);    
  }    
   
  /*加钱函数money*/    
  #include"fees\head.h"    
  money()    
  {    
  float   money;    
  struct   student    
    {long   int   num;    
    float   money;    
    time_t   *times;    
    }stdt,std;    
  FILE   *fp;    
  fp=fopen("fees\student.txt","r+");    
  printf("Please   enter   the   number   :   \n");    
  scanf("%ld",&stdt.num);    
  rewind(fp);    
  while(fread(&std,sizeof(struct   student),1,fp)==1)    
    {if(stdt.num==std.num)    
    {stdt.money=std.money;    
    *stdt.times=*std.times;    
    break;}    
    }    
  printf("Please   enter   the   money   :   \n");    
  scanf("%f",&money);    
  stdt.money=stdt.money+money;    
  printf("Your   number   is   :   %ld",stdt.num);    
  printf("\nYour   money   is   :   %.2f",stdt.money);    
  sleep(3);    
  fseek(fp,-sizeof(struct   student),1);    
  fwrite(&stdt,sizeof(struct   student),1,fp);    
  fclose(fp);    
  }    
   
  现在这个程序就只有一个问题,每次加进去的钱或是上网花的钱可以算出来,但是无法在文件中留住。为什么?    
   
  问题点数:20、回复次数:1Top

1 楼dengwei007(邓蔚)回复于 2002-07-07 18:54:20 得分 20

先把文件全部read一遍再writeTop

相关问题

  • 谁有网吧计费的源代码
  • 怎样让网吧的记费软件不计费?
  • 怎样让网吧的记费软件不计费?
  • ●能不能破解网吧里的IC卡计费系统●
  • 怎么跳过网吧的计费系统???
  • 谁做过电话计费的程序,帮一个忙!
  • !!!一个关于计费的小程序!!!在线等待!
  • 网吧监控类的程序和代码!请进来看看!
  • 我在网吧里没有编译器,怎样写程序?
  • 网吧的技术问题;关于计费服务器的系统故障!(欢迎来稿,在线等待!)

关键词

  • 函数
  • 文件
  • stdt
  • money
  • 上机
  • r+
  • fp
  • fees
  • std
  • printf

得分解答快速导航

  • 帖主:jamesfangjing
  • dengwei007

相关链接

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

广告也精彩

反馈

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