一波三折才写出来这个系统,第一遍写完发现自己实现的功能和老师要求的功能完全不一样,做完又熬夜写出来,今天把错误给改了一遍,
发现自己还是很多知识点没有掌握,对很多概念不清楚,很多bug改不出来就换一种方式来写,自己的计数有待提高。
代码如下:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<cstring>
#include<vector>
#define ll long long
using namespace std;
struct riqi //定义日期
{
int year,moon,day;
ll jiaoyi;
};
class bank
{
ll zhanghao; //定义账号
ll password; //定义密码
string name; //定义姓名
ll money;
public:
vector <riqi> R; //定义日期
bank():zhanghao(201816487),password(123456),name("sgl"),money(10000)
{
R.clear();
}//初始化列表
friend void inquire(); //声明查询函数
friend void deposit(); //声明存款函数
friend void withdrawal(); //声明取款函数
};
bank a;
void input(); //声明输入函数
void deposit() //定义存款函数
{
riqi rq;
ll s_money;
int y,m,d;
ll num;
cout<<"请输入您的账号:";
cin>>num;
if(num==a.zhanghao)
{
ll word;
cout<<"请输入您的密码:";
cin>>word;
if(word==a.password)
{
sign:
cout<<"请输入存款金额:";
cin>>s_money;
if(s_money%100!=0)
{
cout<<"存入的纸币必须是一百元的倍数"<<endl;
cout<<"请重新存入纸币"<<endl;
goto sign;
} //ATM机存入纸币必须是100的倍数
rq.jiaoyi=s_money;
//a.R.push_back(rq);
a.money=a.money+s_money;
cout<<endl<<endl<<"请放入纸币"<<endl<<endl;
cout<<"请输入存款日期,年,月,日"<<endl;
cin>>y;
rq.year=y;
//cout<<y<<endl;
//a.R.push_back(rq);
cin>>m;
//cout<<m<<endl;
rq.moon=m;
//a.R.push_back(rq);
cin>>d;
//cout<<d<<endl;
rq.day=d;
a.R.push_back(rq);
input();
}
else
{
cout<<"密码输入有误,请重新选择"<<endl;
input();
}
}
else
{
cout<<"密码账号有误,请重新选择"<<endl;
input();
}
}
void withdrawal() //定义取款函数
{
riqi rq;
ll w_money;
int m,y,d;
ll num;
cout<<"请输入您的账号:";
cin>>num;
if(num==a.zhanghao)
{
ll word;
cout<<"请输入您的密码:";
cin>>word;
if(word==a.password)
{
for(int k=0;; k++)
{
sign:
cout<<"请输入取款金额:";
cin>>w_money;
if(w_money%100!=0)
{
cout<<"存入的纸币必须是一百元的倍数"<<endl;
cout<<"请重新存入纸币"<<endl;
goto sign;
} //ATM机存入纸币必须是100的倍数
if(a.money<w_money)
cout<<"余额不足"<<w_money<<"元!"<<endl;
if(a.money>=w_money)
{
rq.jiaoyi=-w_money;
//a.R.push_back(rq);
break;
}
}
a.money=a.money-w_money;
cout<<"请取款!"<<endl;
cout<<"请输入存款日期,年,月,日"<<endl;
cin>>y;
//cout<<y<<endl;
rq.year=y;
//a.R.push_back(rq);
cin>>m;
//cout<<m<<endl;
rq.moon=m;
// a.R.push_back(rq);
cin>>d;
//cout<<d<<endl;
rq.day=d;
a.R.push_back(rq);
input();
}
else
{
cout<<"密码输入有误,请重新选择"<<endl;
input();
}
}
else
{
cout<<"密码账号有误,请重新选择"<<endl;
input();
}
}
void inquire() //定义查询函数
{
ll num;
int b;
cout<<"请输入您的账号:";
cin>>num;
if(num==a.zhanghao)
{
ll word;
cout<<"请输入您的密码:";
cin>>word;
if(word==a.password)
{
cout<<"您的余额为:";
cout<<a.money<<endl;
cout<<"查询交易记录请按1,返回请按0:"<<endl;
cin>>b;
if(b==1)
{
int len=a.R.size();
for(int i=0; i<len; i++)
//for(vector<riqi>::iterator i=a.R.begin();i!=a.R.end();i++)
{
cout<<a.R[i].year<<"年 "<<a.R[i].moon<<"月 "<<a.R[i].day<<"日 "<<endl;
cout<<"交易为"<<endl;
cout<<a.R[i].jiaoyi<<endl;
}
input();
}
if(b==0)
input();
}
else
{
cout<<"密码输入有误,请重新选择"<<endl;
input();
}
}
else
{
cout<<"密码账号有误,请重新选择"<<endl;
input();
}
}
void input() //定义输入函数
{
int a;
cout<<"存款1,取款2,查询3,退出0"<<endl;
cin>>a;
if(a==0)
return;
if(a==1)
deposit();
if(a==2)
withdrawal();
if(a==3)
inquire();
}
int main()
{
cout<<"*******************************"<<endl;
cout<<"* *"<<endl;
cout<<"* 欢迎来到农大银行 *"<<endl;
cout<<"* *"<<endl;
cout<<"*******************************"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"* *"<<endl;
cout<<"*******************************"<<endl;
input();
}