使用C语言制作一个简单银行系统

这个代码未使用文件函数存一些数值,如有需要,可以联系我将其加进去.

来自一个菜鸟的制作

#ifndef BANK_H_INCLUDED
#define BANK_H_INCLUDED
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <time.h>
#define upNum 2000       //系统最多能容纳的客户数

//定义全局变量
int my_passwd=123456;
int my_balance=1000000;
int draw_money;
int deposite_money;
char answer;

//定义结构变量
struct record{
    int my_passwd;      //存入我的密码
    int root_passwd;    //存入管理员的密码
    int my_balance;     //存入我的存款
    int draw_money;    //存入取款金额
    int deposite_money; //存入存款金额
    int status;         //存入用户账号状态
    char user[10];      //存入用户账号名称
};

int spending_record();//消费记录函数
int balance();     //查询余额函数
void user_login(); //用户登录函数
int draw();        //取款函数
int deposite();    //存款函数
void opencount();  //开户函数
void frzee();      //冻结账户函数
void concelfrzee();//解冻账户函数
void welcomemenu();//欢迎菜单
void rootmenu();   //管理员菜单
void usermenu();   //用户菜单函数
int currnt_time();        //时间函数
#endif // BANK_H_INCLUDED

//欢迎菜单
void welcomemenu(){
    int i;

    printf("------------中国工商银行------------\n");
    printf("                                    \n");
    printf("-----欢迎使用中国工商银行管理系统-----\n");
    printf("1.用户登录   2.管理员登录   3.退出系统\n");
    printf("                                      \n");
    printf("选择您需要的登录入口: ");
    scanf("%d",&i);
    if(i==1){
        user_login();
    }else if(i==2){
        rootmenu();
    }else{
        printf("欢迎您的使用!中国工商银行诚心为您服务。");
    }
}

//用户登录函数
void user_login(){
    int input_passwd;

    do{
       printf("请输入您的密码: ");
       scanf("%d",&input_passwd);
       if(input_passwd==my_passwd){
          printf("------登录成功!中国工商银行欢迎您!------\n");
          printf("                                \n");
          usermenu();
       }else{
           printf("密码错误!请重新登录  ");
       }
       printf("您是否需要继续输入?(y/n)");
       scanf("%s",&answer);
    }while(answer=='y' || answer=='Y');

}

//用户菜单函数
void usermenu(){
    int user_choice;

    printf("----------请选择您要查询的项目----------\n");
    printf("1.查询余额  2.最近消费记录  3.存款  4.取款  5.退出\n");
    do{
       printf("                                         \n");
       printf("请输入您要查询的项目代号: ");
       scanf("%d",&user_choice);
       switch(user_choice){
       case 1:
        balance();

       case 2:
           {
               char answer;
               printf("您是否需要查询最近的一次消费记录?(y/n): ");
               scanf("%s",&answer);
               if(answer=='y' || answer=='Y'){
                  spending_record();
               }else{
                   usermenu();
               }

           }

        case 3:
            deposite();

        case 4:
         draw();

       case 5:
        printf("感谢您使用ATM自助柜员机\n");
       }
       printf("您是否需要继续操作?(按下n或N退出)");
       scanf("%d",&answer);
    }while(answer=='y' || answer=='Y');

}

//查询余额函数
int balance(){

    printf("您的余额为%d元\n",my_balance);
    printf("您是否需要查询其他项目?(y/n): ");
    scanf("%s",&answer);
    if(answer=='y' || answer=='Y'){
        usermenu();
    }else{
        printf("感谢您的使用!\n");
    }
}

//最近消费记录函数
int spending_record(){
    int i,j,temp;
    int number;
    int low=1;
    int high=5;
    int mid=0;
    int record[5]={110,4999,299999,3999,219999};

    for(i=0;i<5;i++){
        for(j=0;j<4-i;j++){
            if(record[j]>record[j+1]){
               temp=record[j];
               record[j+1]=record[j];
               record[j+1]=temp;
            }
        }
    }
    printf("请输入您的最近一次的消费金额: ");
    scanf("%d",&number);
    for(i=0;i<5;i++){
        while(low<high){
        mid=(low+high)/2;
        if(mid==number){
            printf("您消费了%d元",number);
            return number;
        }
        if(number>mid){
            low=mid+1;
        }else if(number<mid){
            high=mid-1;
        }else{
            printf("对不起,您最近未有此消费支出!\n");
        }
      }
    }
    do{
        usermenu();
        printf("您是否需要继续操作?(y/n) ");
       scanf("%s",&answer);
    }while(answer=='y' || answer=='Y');
}

//存款函数
int deposite(){
    int deposite_money;

    printf("请输入您要存入的钞票金额:");
    scanf("%d",&deposite_money);
    my_balance=my_balance+deposite_money;

    printf("存入成功!您现在的余额为%d元\n",my_balance);

    return my_balance;
}

//取款函数
int draw(){
    printf("请输入您要取出的现金金额: ");
    scanf("%d",&draw_money);
    my_balance=my_balance-draw_money;
    printf("您的现金余额为%d元\n",my_balance);

    return my_balance;
}

//管理员菜单
void rootmenu(){
    int root_choice;
    int input_passwd;
    int root_passwd=000000;

    printf("请输入管理员密码: ");
    scanf("%d",&input_passwd);
    if(root_passwd==input_passwd){
       printf("------------管理员选项------------\n");
       printf("1.开户  2.冻结账户  3.解冻账户  4.退出\n");
       printf("                                   \n");
       do{
          printf("请选择您要操作的项目: ");
          scanf("%d",&root_choice);
          switch(root_choice){
          case 1:
            opencount();

          case 2:
            frzee();

          case 3:
            concelfrzee();

          case 4:
            printf("系统将于5秒后关闭!");
            break;
          }printf("您是否需要继续操作?");
          scanf("%d",&root_choice);
       }while(root_choice==1 || root_choice==2 || root_choice==3);

    }

}

//开户函数
void opencount(){
    int i;
    int status;
    int my_passwd;
    int passwd_pool[10];
    char username[10];

    printf("请输入您的用户名: ");
    scanf("%s",&username[i]);
    //username[i].status==0; //账户初始状态为正常状态
    do{
       printf("请输入您的密码: ");
       scanf("%d",&my_passwd);
       if(my_passwd/1==my_passwd){
         printf("注册成功!\n");
          rootmenu();
       }else{
           printf("注册失败!请重新注册!");
       }
    }while(my_passwd/1!=my_passwd);

}

//冻结函数
void frzee(){
    int i;
    char input_username;
    char username[10];
    printf("请输入需要冻结的账户: ");
    scanf("%s",&input_username);
    for(i=0;i<10;i++){
            if(username[i]==input_username){
                //username[i].status==1;
                printf("冻结成功!");
                rootmenu();
            }else{
                printf("未找到该用户!");
            }
    }
}

//解冻函数
void concelfrzee(){
    char input_username;
    char username[10];

    printf("请输入需要解冻的账户: ");
    scanf("%s",&input_username);
    printf("解冻成功!");
}

//获取时间函数
int currnt_time(){
    time_t current_time;

    // 获取当前时间
    current_time = time(NULL);

    if (current_time == ((time_t) -1)) {
        fprintf(stderr, "获取时间失败\n");
        return 1;
    }

    // 将时间戳转换为本地时间
    struct tm * local_time = localtime(&current_time);

    // 打印本地时间
    printf("当前本地时间: %s", asctime(local_time));

    return 0;
}


//主函数,函数入口
int main(){
    printf("中国工商银行欢迎您!  ");
    currnt_time();
    printf("                        \n");

    welcomemenu();
}
 

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值