第一次写这个,还有蛮多不足的地方,功能相对简单
具体功能
1:登陆
2:查询
3:记录
4:修改登录信息
5:模拟存/取
note:
1:可以用修改完的信息再次登陆 ^ ^
2:当输入用户名为 end 的时候退出系统,否则持续工作
以下是代码
//ILSSWFR
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<conio.h>
#include<vector>
#include<ctime>
#define zero 1e-6
using namespace std;
struct node
{
long long inf_tot;
string name;
string counts;
string password;
double money;
struct node *next;
vector<string> information;
};
void input(char *str);
struct node *finds(string n);
void change_pawrd(struct node *s);
void make(int sign, struct node *s, int value);
struct node user3={0,"CC","1000003","QAZWSX",172198.83,NULL},
user2={0,"BB","1000002","qwertk",38929.39,&user3,},
user1={0,"AA","1000001","sdafads",318971.37,&user2};
const string end_system="end";
int main()
{
string ZH;
char MM[27];
struct node *rem;
for (;;){
for (;;){
system("cls");
cout<<"=================欢迎使用================"<<endl<<endl;
cout<<"账号:";
cout<<" 密码:\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b";
cin>>ZH;
cout<<endl;
if (ZH==end_system)
return 0;
if ((rem=finds(ZH))==NULL){
string rad;
cout<<" 用户名错误,请重新输入!"<<endl;
cout<<" 按任意键继续 ";
cin>>rad;
}
else
break;
}
int i;
system("cls");
for (i=2;i>=0;--i){
cout<<"=================欢迎使用================"<<endl<<endl;
cout<<"账号:";
cout<<ZH;
auto k=ZH.size();
for (int i=0;i<14-k;++i)
cout<<' ';
cout<<"密码:";
input(MM);
if (MM==rem->password)
break;
else {
string choose;
cout<<endl;
cout<<" 您还有"<<i<<"次尝试的机会"<<endl;
cout<<" 退出请按6,按c重新输入"<<endl;
cin>>choose;
if (choose=="6")
return 0;
system("cls");
}
}
if (i==-1){
system("cls");
cout<<"您的账户已冻结"<<endl; return 0;
}
else {
int choose,flag=0;
for (;;){
system("cls");
cout<<"=================选择服务================"<<endl<<endl;
cout<<"1:基本信息及交易记录"<<endl;
cout<<"2:修改密码"<<endl;
cout<<"3:查询余额"<<endl;
cout<<"4:取款(每次限额5000)"<<endl;
cout<<"5:存款"<<endl;
cout<<"6:退出"<<endl;
if (!flag)
cin>>choose;
if (!(1<=choose&&6>=choose)){
cout<<endl<<"输入错误请重新输入";
flag=1;
cin>>choose;
continue;
}
if (choose==1){
system("cls");
cout<<"用户名:"<<rem->name<<endl;
long long cnt=rem->inf_tot;
if (!cnt){
cout<<endl<<" 暂无交易记录"<<endl;
}
else {
cout<<"交易记录:"<<endl;
for (int j=0;j<cnt;++j){
cout<<"----------------------------------------------------"<<endl;
cout<<rem->information[j]<<endl;
}
cout<<"----------------------------------------------------"<<endl;
}
string i;
cout<<" 按任意键返回";
cin>>i;
}
else if(choose==2){
system("cls");
flag=0;
change_pawrd(rem);
}
else if (choose==3){
system("cls");
cout<<"您的账户余额为:"<<rem->money<<endl<<endl;
string i;
cout<<" 按任意键返回"<<endl;
cin>>i;
}
else if (choose==4){
system("cls");
for (;;){
long long money;
cout<<"输入您要支出的金额:";
cin>>money;
if (money-rem->money>zero){
system("cls");
cout<<"余额不足,请重新输入"<<endl<<endl;
cout<<" 取消交易请按6,其他键继续"<<endl;
string i;
cin>>i;
if(i=="6")
break;
else{
system("cls"); continue;
}
}
else{
rem->money -=money;
make(-1,rem,money);
system("cls");
cout<<"您已成功支出:"<<money<<"元"<<endl<<endl;
string i;
cout<<" 按任意键返回"<<endl;
cin>>i;
break;
}
}
}
else if (choose==5) {//假设存款的结果
system("cls");
int money=rand()%5000;//假设用户要存入的金额;
rem->money+=money;
cout<<"您已成功存入:"<<money<<"元"<<endl<<endl;
string i;
cout<<" 按任意键返回"<<endl;
cin>>i;
make(1,rem,money);
}
else if (choose==6){
system("cls");
break;
}
}
}
}
return 0;
}
void input(char *str)//密码替换输入
{
char c;
for (int i=0;;){
//cout<<i<<endl;
c=getch();
if (c=='\r'){
str[i]='\0';return;
}
if (c=='\b'){
if (i>0){
cout<<"\b"<<' '<<"\b"; --i;
}
}
else{
str[i++]=c; cout<<"*";
}
}
}
struct node *finds(string n)//查找用户是否存在
{
struct node *p =&user1;
while (p!=NULL && p->counts!=n)
p=p->next;
if (p==NULL)
return NULL;
return p;
}
void change_pawrd(struct node *s)
{
char a[27],b[27];
for (;;){
system("cls");
cout<<"请输入要修改的密码:";
input(a);
cout<<endl;
cout<<"请确认您的输入密码:";
input(b);
cout<<endl;
if (strcmp(a,b)){
cout<<"两次输入密码不一致,请重新输入"<<endl;
cout<<" 若要返回请按6,其他键继续";
string i;
cin>>i;
if (i=="6")
return ;
}
else {
s->password=a;
system("cls");
cout<<"您已成功修改密码"<<endl;
cout<<" 按任意键返回"<<endl;
string i;
cin>>i;
return ;
}
}
return ;
}
void make(int sign, struct node *s, int value)//生成交易记录
{
string add="交易时间:";
char ad[27],ad2[27];
time_t rawtime;
rawtime=time(NULL);
int i;
auto k=ctime(&rawtime);
add=add+k+"------------------------------------交易金额:";
if (sign>0)
add+="+";
else
add+="-";
for (i=0;value;){
ad[i++]=(value%10+'0');
value/=10;
}
int j;
for (j=0;i>0;++j,--i)
ad2[j]=ad[i-1];
ad2[j]='\0';
add+=ad2;
auto q=add.size();
add[q]='\0';
(s->information).push_back(add);
(s->inf_tot)++;
}