吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 3541|回复: 21
收起左侧

[C&C++ 转载] 偶然翻出的自己用C写的模拟银行柜台机的程序

  [复制链接]
xiaomayi2012 发表于 2019-8-26 13:35
本帖最后由 xiaomayi2012 于 2019-8-26 13:42 编辑

今天翻看以前写的代码,偶然发现自己用c写的一个模拟银行柜台机的程序,程序写的一般,现在分享出来作为一个记录。
大家看看就可以了。。
[C] 纯文本查看 复制代码
#include <stdio.h>

//定义全局变量 
int n;
struct userinfo *head;
/*===========================
作者:sst
日期:2008-12-03 
函数:struct userinfo
作用:结构体实现用户信息传输 
============================*/ 
struct userinfo
{
 int  id;
 char name[4];
 char sex[2];
 int age;
 char address[10];
 int money;
 struct userinfo* next;
};
/*===========================
作者:sst
日期:2008-12-03 
函数:main()
作用:程序的入口点 
============================*/ 
int main(int argc,char **argv)
{   
    read1();
    login();
   
     
    //system("cls");
   
} 
/*===========================
作者:sst
日期:2008-12-03 
函数:show()
作用:实现业务的选择 
============================*/ 
void show()
{
     
      system("cls");
     while(1)
     {      
             content();
             int i;
             printf("                请选择您所需要的业务代号:");
             scanf("%d",&i);
             printf("/n");
             switch(i)
             {
                      case 1:
                           system("cls");
                           openAccount();//开户实现 
                           break;
                      case 2:
                           system("cls");
                           getmoney();break;//存款的实现 
                      case 3:
                           system("cls");
                           outmoney();break;//取款实现 
                      case 4:
                           system("cls");
                           Transfer();break;//转账实现 
                      case 5:
                           system("cls");
                           search();break;//查询实现 
                      case 6:
                           printf("             欢迎下次光临!");
                           system("cls");
                           printf("/n/n/n/n");
                           printf("            ╭══╦═╗╔════╗/n");
                           sleep(200);
                           printf("            ╔══╠═╗║ ╔  ║/n");
                           sleep(200);
                           printf("            ║  ║ ║║ ║  ║/n");
                           sleep(200);
                           printf("            ╠══╠═╣║ ║  ║/n");
                           sleep(200);
                           printf("            ╠══╩═╠╚ ║║ ╗/n");
                           sleep(200);
                           printf("            ╚   ╚╯╚═╯╚═╯/n");
                           sleep(2000);
                           updata();
                           system("cls");
                           exit(0); 
                           
                      default:
                              printf("您输入的有误,请从重新输入!");
                              break;
             } 
             sleep(2000);
             system("cls");
      }       
}


/*===========================
作者:sst
日期:2008-12-03 
函数:content()
作用:通过I/O读入显示界面目录
============================*/ 
content()
{
 char buffer1[100];
 
 FILE *file=fopen("MainUI.txt","r");//定义一个文件指针 
 while(1)
 {
  fgets(buffer1,100,file);
  if(strlen(buffer1)==0)
   break;
  fputs(buffer1,stdout);
  memset(buffer1,'/0',sizeof(buffer1));
   fflush(stdout);
 }
 
}


/*===============
作者:sst
日期:2008-12-03 
函数:login()
作用:用户登录实现 
===============*/ 
login()
{
       char n[10];
       char pwd[10];
       start:
       printf("/n");
       printf("            ===============================/n/n");
       printf("                欢迎光临银行管理系统v1.0!/n/n");
       printf("            ===============================/n/n");
       printf("            用户名:");
       scanf("%s",n);
       printf("/n");
       sleep(200);//在屏幕上暂停一段时间(200毫秒 
       printf("            密  码:");
       scanf("%s",pwd);
       if(strcmp(n,"abc")==0 && strcmp(pwd,"123")==0)
       {        system("cls"); 
                printf("/n/n/n");
                printf("           登录中请稍候.../n/n");
                printf("           ");
                bar();//进度条函数 
                system("cls");
                sleep(500); 
                show();
        }
        else
        printf("您输入的有误!请重新输入!");
        sleep(1000);
        system("cls");
        goto start;
}

/*===============
作者:sst
日期:2008-12-03 
函数:bar()
作用:进度条实现 
===============*/ 
bar()
{    
    int i=0; 
    for(;i<50;i++)
    {
/*=====================================================================
当i<79时打印一个>
如果i == 79 那么使用/r使光标回到这行的开始处使用/t来把前一次打印的>擦除
接着使用/r再回到这行开始处准备下次的动画,同时把记数器i改为0
=======================================================================*/
        if(i < 79)
        {
            printf(">");
        }
        else
        {
            printf("/r");
            printf("/t/t/t/t/t/t/t/t/t ");
            printf("/r");
            i = 0;
        }
       sleep(200);//让当前线程休眠200毫秒再打印下一个>
       i=i+2;
      } 
}
/*===================
作者:sst
日期:2008-12-03 
函数:openAccount()
作用:实现开户 
=====================*/
openAccount()
{
      FILE *fp;
      struct userinfo *p;
      p=(struct userinfo*)malloc(sizeof(struct userinfo));
      p->id=1001;
      p->money=0;
      p->age=1;
             printf("            =============================/n/n");
             printf("                  欢迎进入开户界面/n");
             printf("            =============================/n/n");
             printf("            请输入您的开户个人信息:/n");
             printf("/n");
             printf("            请输入账号:");
             scanf("%d",&(p->id));
             printf("/n"); 
             printf("            请输入用户名:");
             scanf("%s",p->name);
             printf("/n"); 
             printf("            请输入性别:");
             scanf("%s",p->sex);
             printf("/n"); 
             printf("            请输入年龄:");
             scanf("%d",&(p->age));
             printf("/n"); 
             printf("            请输入家庭住址:"); 
             scanf("%S",p->address);
             printf("/n"); 
             printf("            请输入存款金额:");
             scanf("%d",&(p->money));
             insert(p);
             p=head;
             printf("/n");
             printf("            ================================/n");
             printf("                 您的银行帐户已开户成功!/n/n");
             printf("            ================================/n");
             printf("   ┌────┬────┬───┬───┬─────┬─────┐/n");
             printf("   │ 帐户:  │姓名:   │性别: │年龄: │家庭住址: │存款金额: │/n");
             printf("   ├────┼────┼───┼───┼─────┼─────┤/n"); 
             printf("   │%8d│%8s│%6s│%6d│%10s│%10d│/n",p->id,p->name,p->sex,p->age,p->address,p->money);
             printf("   └────┴────┴───┴───┴─────┴─────┘");
    sleep(4000);
    
}

 

/*==================================
作者:sst
日期:2008-12-03 
函数:insert(struct userinfo *user) 
作用:链表实现往文本中插入数据
===================================*/
insert(struct userinfo *user)
{      
       struct userinfo *p0,*p1,*p2;
      p1=head;
      p0=user;
    if(head==NULL)
    {
        head=p0;
        p0->next=NULL;
    }
    else
    {
        while((p0->id > p1->id) && (p1->next!=NULL))
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->id <= p1->id)
        {
            if(head==p1) head=p0;
            else p2->next=p0;
            p0->next=p1;
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;
        }
    }
    n=n+1;
       }
     

/*===============
作者:sst
日期:2008-12-03 
函数:getmoney() 
作用:存款实现 
===============*/
getmoney()
{       
   struct userinfo *s;
   int id;
   int money;
   start:
   printf("            =============================/n/n");
   printf("                  欢迎进入存款界面/n/n");
   printf("            =============================/n/n");      
   printf("            请输入您的账号:"); 
   scanf("%d",&id);
   s=head;
  while(s->id!=id&&s->next!=NULL)
           s=s->next;
   if(s->id!=id)
   {
          printf("对不起您输入的账号不存在/n");
          goto start;
  }
          printf("/n");
          printf("        请输入存款金额:"); 
          scanf("%d",&money);
          printf("/n/n");
          s->money=(s->money)+money;
          printf("        >>>>>>>>>>>存款成功!<<<<<<<<<<</n");
          printf("        您的余额为: %d",s->money);
          sleep(2500);
          system("cls");
   }

/*===============
作者:sst
日期:2008-12-03 
函数:outmoney() 
作用:取款的实现 
===============*/ 
outmoney()
{
   FILE *fp;
   struct userinfo *s;
   int id;
   int money;
   start:
   printf("            =============================/n/n");
   printf("                  欢迎进入取款界面/n/n");
   printf("            =============================/n/n");
   printf("            请输入您的账号:"); 
   scanf("%d",&id);
   s=head;
   while(s->id!=id&&s->next!=NULL)
        s=s->next;
   if(s->id!=id)
   {
          printf("         对不起您输入的账号不存在");
          goto start;
   }
          printf("/n");
          printf("       请输入取款金额:");
          scanf("%d",&money);
          if(money>s->money)
                  printf("对不起您的余额不足!");
          
          printf("/n");
          s->money=(s->money)-money;
          printf("       >>>>>>>>>>>取款成功!<<<<<<<<<<</n/n");
          sleep(2000);
         
          printf("       您的余额为:%d",s->money);
          sleep(2000);
          system("cls"); 
      
   }
/*===============
作者:sst
日期:2008-12-03 
函数:Transfer() 
作用:转账实现 
===============*/
Transfer()
{
   struct userinfo *s1;
   struct userinfo *s2;
   int id;
   int money;
   start:
   printf("            =============================/n/n");
   printf("                  欢迎进入转账界面/n/n");
   printf("            =============================/n/n");
   printf("            请输入您的账号:"); 
   scanf("%d",&id);
   s1=head;
   while(s1->id!=id&&s1->next!=NULL)
   s1=s1->next;
   if(s1->id!=id)
   {
          printf("        对不起您输入的账号不存在");
          goto start;
   }
          printf("/n");
          printf("          请输入您要转户账号:");
          scanf("%d",&id);
          s2=head;
          while(s2->id!=id&&s2->next!=NULL)
          
             s2=s2->next;
             if(s2->id!=id)
             {
                 printf("/n");
                 printf("转户账号不存在!");
                 goto start;
             }
          printf("/n"); 
          printf("          请输入转账金额;");;
          scanf("%d",&money);
          if(money>s1->money)
          {
                  printf("对不起您的余额不足!不能转户!");
                  printf("/n/n");
          }
          else
          { 
                  s1->money=(s1->money)-money;
                  s2->money=(s2->money)+money;
                  printf(">>>>>>>>>>>转帐成功!<<<<<<<<<<</n/n");
          }
          sleep(2000);
         
          printf("        您的余额为:%d",s1->money);
          sleep(2000); 
          system("cls");
}

/*========================
作者:sst
日期:2008-12-03 
函数:updata() 
作用:更新到文本文件中 
=========================*/
updata()
{       FILE *fp;
        struct userinfo *s;
          fp=fopen("account.txt","r+");
          s=head;
     while(s!=NULL)
     {    
          fprintf(fp,"%d %s %s %d %s %d/n",s->id,s->name,s->sex,s->age,s->address,s->money);
          s=s->next;
            
     }     
     fclose(fp); 
}

/*=====================
作者:sst
日期:2008-12-03 
函数:search() 
作用:查询的实现 
=======================*/
search()
{   
    int id; 
    struct userinfo * s;
    s=head;
    printf("            =============================/n/n");
    printf("                  欢迎进入查询界面/n/n");
    printf("            =============================/n/n");
    printf("            请输入您要查询的帐号:");
    scanf("%d",&id);
    while(s->id!=id&&s->next!=NULL)
        s=s->next;
        if(s->id==id)
        {
        //printf("/n帐号:%d 用户名:%s 性别:%s 年龄:%d 地址:%s  金额:%d/n",s->id,s->name,s->sex,s->age,s->address,s->money);
             printf("/n");
             printf("   查询结果:/n"); 
             printf("   ┌────┬────┬───┬───┬─────┬─────┐/n");
             printf("   │ 帐户:  │姓名:   │性别: │年龄: │家庭住址: │存款金额: │/n");
             printf("   ├────┼────┼───┼───┼─────┼─────┤/n"); 
             printf("   │%8d│%8s│%6s│%6d│%10s│%10d│/n",s->id,s->name,s->sex,s->age,s->address,s->money);
             printf("   └────┴────┴───┴───┴─────┴─────┘");
        sleep(2000);
        s=s->next;
        }
    sleep(3000);
    //free(s);
}
/*=========================
作者:sst
日期:2008-12-03 
函数:read()
作用:将用户资料读入链表 
==========================*/
read1()//让该函数随着程序的启动而加载 
{
    FILE * fp;
    struct userinfo *s1,*s2;
    n=0;
    fp=fopen("account.txt","r");
    s1=s2=(struct userinfo*)malloc(sizeof(struct userinfo));
    fscanf(fp,"%d %s %s %d %s %d",&s1->id,s1->name,s1->sex,&s1->age,s1->address,&s1->money);
    head=NULL;
    while(!feof(fp))
    {
        n=n+1;
        if(n==1)head=s1;
        else s2->next=s1;
        s2=s1;
        s1=(struct userinfo* )malloc(sizeof(struct userinfo));
        fscanf(fp,"%d %s %s %d %s %d",&s1->id,s1->name,s1->sex,&s1->age,s1->address,&s1->money);
         
    } 
    s2->next=NULL;
   
}

免费评分

参与人数 3吾爱币 +5 热心值 +3 收起 理由
苏紫方璇 + 3 + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
某猫 + 1 + 1 热心回复!
kevinchou1996 + 1 + 1 用心讨论,共获提升!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

某天大魔王 发表于 2019-8-26 20:41
xiaomayi2012 发表于 2019-8-26 13:41
不好意思 只是以前初学c的实话写的一个小程序。。

夸你呢!兄弟。这东西对我像是天书。。。。。。
 楼主| xiaomayi2012 发表于 2019-8-29 08:32
破竹而入 发表于 2019-8-28 23:08
大佬你这应该要学了近半年,结构体才能玩得这么6吧。。。

没有,就学了俩个星期。。
某天大魔王 发表于 2019-8-26 13:40
 楼主| xiaomayi2012 发表于 2019-8-26 13:41

不好意思 只是以前初学c的实话写的一个小程序。。
头像被屏蔽
coradong1985 发表于 2019-8-26 13:43
提示: 作者被禁止或删除 内容自动屏蔽
yywapj 发表于 2019-8-26 14:01
这是准备对美金融系统下脚了吗
云梦墨溪 发表于 2019-8-26 14:06
挺好的,学习了
免票的破船 发表于 2019-8-26 14:11
很有纪念意义
mmic 发表于 2019-8-26 14:12

挺好的,支持一下
glk1010282338 发表于 2019-8-26 14:20
支持一下!
duduhao 发表于 2019-8-26 14:31
我只是打酱油路过而已
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-23 16:48

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表