一个过于简易的银行储蓄系统

/*written by cyc in 2020
no rights reserved @1145141919810.inc Shimokita,Nihonkoku
sono kaisya no syacyou wa yajuu senpai desu(24,gakuse da)*/ 
#include <bits/stdc++.h>//one for all,all in one
namespace ns1{
int starts=1;
struct account
{
    int num,oprts=0;
    float money=0;
    std::string records[32];
    float opmoney[32];
}tester[1<<15];//2^15个实例,够用了.但是有时间还是想用new重写一次
void create_new_account()
{
  tester[starts].num = starts;
  std::cout<<"account "<<starts<<" has been set"<<std::endl;
  starts++;
}
void deposit_to(int g_account, float g_number)
{
    if(g_number >= 0){
    tester[g_account].money += g_number;
    tester[g_account].opmoney[tester[g_account].oprts] = g_number;
    time_t current;
    current = time( &current );
    std::string timestring = ctime( &current );
    timestring = timestring.substr(0,timestring.length()-1);
    tester[g_account].records[tester[g_account].oprts] = timestring;
    tester[g_account].oprts ++;
}
    else std::cout<<"the value can not be a negative number"<<std::endl;
}
void withdrawal_to(int g_account, float g_number)
{
    if(tester[g_account].money > g_number){
    tester[g_account].money -= g_number;
    tester[g_account].opmoney[tester[g_account].oprts] = -g_number;
    time_t current;
    current = time(&current);
    std::string timestring = ctime(&current);
    timestring = timestring.substr(0,timestring.length()-1);
    tester[g_account].records[tester[g_account].oprts] = timestring;
    tester[g_account].oprts ++;
    }
    else std::cout<<"the value can not be larger than your savings!"<<std::endl;
}
void check_record(int g_account)
{
    int ts = tester[g_account].oprts;
    for(int i = 0;i < ts;i++){
        std::cout<<tester[g_account].records[i];
        std::cout<<" "<<tester[g_account].opmoney[i]<<std::endl;
    }
}
}
using namespace ns1;
int main()
{
        std::cout<<R"(press 1 to create a new account
press 2 to deposit & withdrawal
press 3 to check the records)"<<std::endl;//多行输出,可以偷点懒
    int flag1,flag2,f_account,f_number;
    while(std::cin >> flag1){
    if ( flag1 == 1 ) create_new_account();
    if ( flag1 == 2 )
        {
        std::cout<<"key in your account"<<std::endl;
        std::cin>>f_account;
        std::cout<<"1 for deposit and 2 for withdrawal"<<std::endl;
        std::cin>>flag2;
            if ( flag2 == 1 )
            {
                std::cout<<"key in the number you deposit";
                std::cin>>f_number;
                deposit_to(f_account, f_number);
            }
            if( flag2 == 2 )
            {
                std::cout<<"key in the number you withdrawal";
                std::cin>>f_number;
                withdrawal_to(f_account, f_number);
            }
        }
    if ( flag1 == 3 )
        {
        std::cout<<"key in your account"<<std::endl;
        std::cin>>f_account;
        check_record(f_account);
        }
    std::cout<<R"(press 1 to create a new account
press 2 to deposit & withdrawal
press 3 to check the records)"<<std::endl;
}
}

不去写代码是感觉不到自己的真正水平的 … 本来自认为会使用的一些 stl 并没能好好利用,还是要多多练习(too naive,还是要学习一个


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值