用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - c++代码库

用C语言实现的一个简单的银行系统,其中柜员号:hou520,登录密码:13145

2016-05-12 作者: 夜丶微凉举报

[c++]代码库

#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "time.h"
int menu();
int open();//开户
int save();//存钱
int take();//取钱
int check();//查询
int exchange();//转账
int getacc(int acc,float money);//接收转账
int login();//登录
int print(int count);//打印
int randopen();//生成随机账号
int root()
{
    int i,j;
    printf("\n\n\n\n\n\n");
    printf("                正在登陆\n");
    for(i=0;i<80;i++)
    {
        printf("=");
    }
    for(i=0;i<80;i++)
    {
        printf(">");
        for(j=0;j<9000000;j++);
    }
    return 0;
}
int first()
{
    int i,j;
    char username[5];
    char password[10];
    printf("\n\n\n\n\n\n\n      请输入柜员用户名:");
    scanf("%s",&username);
    printf("        请输入登录密码:");
    scanf("%s",&password);
    if(strcmp(username,"hou520")==0&&strcmp(password,"1314520")==0)
    {
        printf("            登录成功");
        for(i=0;i<3;i++)
        {
            printf(".");
            for(j=0;j<90000000;j++);
        }
    }
    else
    {
        printf("        帐号或密码错误!\n");
    }
    return 0;
}
struct
{
    char username[20];
    char password[20];
    int accont;
    float money;
}person[1000];
int count=0;
 
int main()
{
    system("color 9e");
    first();
    system("cls");
    root();
    system("cls");
    system("color 9e");
    menu();
    return 0;
}
int menu()
{
    int a;
     
    do
    {
    printf("        ***********************************************\n");
    printf("        *                                             *\n");
    printf("        *       Welcome to the BANK OF YOUMING!       *\n");
    printf("        *                                             *\n");
    printf("        ***********************************************\n");
    printf("        1、开户\n      2、存款\n      3、取款\n      4、查询\n      5、转账\n      6、退出\n");
    printf("        请选择以下操作:");
    scanf("%d",&a);
    system("cls");
    switch(a)
    {
        case 1:open();break;
        case 2:save();break;
        case 3:take();break;
        case 4:check();break;
        case 5:exchange();break;
        case 6:break;
        default:printf("        请选择1-6之间的有效选择\n");
    }
    }while(a!=6);
    return 0;
}
int randopen()
{
    int i;
    int open;
    srand(time(0));
    open=rand();
    for(i=0;i<count;i++)
    {
        if(open==person[i].accont)
        {
            open<<=2;
        }
    }
    return open;
}
int print(int count)
{
    printf("        你的账号是:%d\n",person[count].accont);
    printf("        你的用户名是:%s\n",person[count].username);
    printf("        你账户的余额:%.2f\n",person[count].money);
    return 0;
}
int open()
{
    char password[20];
    printf("        请输入注册用户名:");
    scanf("%s",&person[count].username);
    printf("        请输入用户密码:");
    scanf("%s",&password);
    printf("        请确认用户密码:");
    scanf("%s",&person[count].password);
    if(strcmp(password,person[count].password)==0)
    {
        printf("        *******************开户成功!*******************\n       账户信息如下:\n");
        person[count].accont=randopen();
        person[count].money=0.f;
        print(count);
        printf("        你的账户密码是:%s,请牢记!\n",password);
        count++;
    }
    else
    {
        printf("        *************密码不一致,开户失败!*************\n");
    }
    return 0;
}
int login()
{
    int accont,i;
    char password[20];
    printf("        请输入你的账号:");
    scanf("%d",&accont);
    printf("        请输入账户密码:");
    scanf("%s",&password);
    for(i=0;i<count;i++)
    {
        if(accont==person[i].accont)
        {
            return i;
        }
    }
    printf("        你输入的账号或密码有误!\n");
    return -1;
}
int save()
{
    float money;
    int count=login();
    if(count!=-1)
    {
        printf("        请输入你的存款数额:");
        scanf("%f",&money);
        if(money>=0)
        {
        person[count].money+=money;
        printf("        你存了%d元!\n",money);
        print(count);
        }
        else
        {
            printf("        你的输入有误,请重新输入!\n");
        }
    }
    return 0;
}
int take()
{
    float money;
    int count=login();
    if(count!=-1)
    {
        printf("        请输入你的取款数额:");
        scanf("%f",&money);
        if(money>=0&&money<=person[count].money)
        {
        person[count].money-=money;
        printf("        你取了%d元!\n",money);
        print(count);
        }
        else
        {
            printf("        你的输入有误,请重新输入!\n");
        }
    }
    return 0;
}
int check()
{
    int count=login();
    if(count!=-1)
    {
        print(count);
    }
    return 0;
}
int exchange()
{
    int acc_1,acc_2;
    float money;
    int count=login();
    if(count!=-1)
    {
    printf("        请输入转账账号:");
    scanf("%d",&acc_1);
    printf("        请确认对方账号:");
    scanf("%d",&acc_2);
    if(acc_1==acc_2)
    {
        printf("        请输入你要转入的金额:");
        scanf("%f",&money);
        if(money>=0&&money<=person[count].money)
        {
        int accCount=getacc(acc_1, money);
        if(accCount != -1)
        {
            printf("        转账成功!\n");
            person[count].money-=money;
            printf("        你向对方了%d元!\n",money);
        }
        print(count);
        }
    }
    else
    {
        printf("        你的操作有误!\n");
    }
    }
    return 0;
}
int getacc(int acc,float money)
{
    int i;
    for(i=0;i<count;i++)
    {
        if(person[i].accont==acc)
        {
            person[i].money+=money;
            return i;
        }
    }
    printf("        账号不存在!\n");
    return -1;
}


网友评论    (发表评论)

共1 条评论 1/1页

发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...