/*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( ¤t );
std::string timestring = ctime( ¤t );
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(¤t);
std::string timestring = ctime(¤t);
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,还是要学习一个)