// 创作者:海大19级智科专业 江--林哥
// 感谢查看,使用前请收藏,点赞哦!!!!
#include
#include
#include
#include
#include
using namespace std;
#include
#define MAX 500
struct record
{
char name[20];
char cardno[20];
int card;
char money[20];
char time[50];
};
//用户类,包含用户的姓名,卡号,密码,账户余额
class account
{
public:
char name[50];
int card;
int password;
float balance;
account(){
card=0;password=123456;balance=0;};
friend istream& operator >>(istream& in,account &temple);
friend ostream& operator <<(ostream& out,account &temple);
};
// 管理员类
class manager :public account
{
public :
int jobname;
char mima[10];
friend istream& operator >>(istream& in,manager &worker);
friend ostream& operator <<(ostream& out,manager &worker);
};
//输入管理员账号
istream& operator >>(istream& in,manager &worker)
{
cout<<"工号 密码 "<<endl;
in>>worker.jobname>>worker.mima;
cout<<endl;
return in;
}
// 输出管理员账号
ostream& operator <<(ostream& out,manager &worker)
{
cout<<"工号 密码"<<endl;
out<<worker.jobname<<" "<<worker.mima;
cout<<endl;
return out;
}
//重载用户输入运算符
istream& operator >>(istream& in,account &temple)
{
cout<<"姓名 卡号 密码 开户金额"<<endl;
in>>temple.name>>temple.card>>temple.password>>temple.balance;
cout<<endl;
return in;
}
//重载用户输出运算符
ostream& operator <<(ostream& out,account &temple)
{
out<<temple.name<<" "<<temple.card<<" "<<temple.password<<" "<<temple.balance<<endl;
return out;
}
//显示所有账户的信息
void display(account user[],int total)
{
int i,j;
account templeuser;
if(total==0)
{
cout<<"无账户信息"<<endl<<endl;
}
else
{
cout<<"所有用户信息:"<<endl;
for(i=0;i<total-1;i++)
{
for(j=0;j<total-1-i;j++)
{
if(user[j].card>user[j+1].card)
{
templeuser=user[j];
user[j]=user[j+1];
user[j+1]=templeuser;
}
}
}
for(i=0;i<total;i++)
{
cout<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<"元"<<endl;
}
}
}
//查找卡号
int searchcard(account user[],int total,int templecard)
{
int i=0;
while((i<total)&&(user[i].card!=templecard))
{
i++;
}
if(i>total-1)
{
return -1;
}
else
{
return i;
}
}
// 检查密码
void chick(account user[],int k)
{
int mima;
do
{
system("cls");
cout<<"请输入密码"<<endl;
cin>>mima;
}while(user[k].password!=mima);
}
int main()
{
system("color f3");
record c[MAX];
int i,total=0,templecard,k,m;
float money,templemoney;
account temple,user[MAX]; //用户类变量
time_t timep; //为了获取系统时间
struct tm *vv; //用来输出时间的结构体
manager www,woker[MAX]; //管理员类变量
int select=0;
woker[0].jobname=20001029;//0号管理员初始账号密码
woker[0].mima[0]='l';
woker[0].mima[1]='o';
woker[0].mima[2]='v';
woker[0].mima[3]='e';
woker[0].mima[4]='h';
woker[0].mima[5]='y';
do// 管理员账号登录页面
{
system("cls");
cout<<"********管理员登录*********" <<endl;
cout<<"欢迎使用活期储蓄账目管理系统"<<endl<<"请输入您的管理员账号"<<endl;
cin>>www;
int i=-1;
do
{
i++;
} while (www.jobname!=woker[i].jobname&&i<100);
k=i;
}while (strcmp(www.mima,woker[k].mima));
do
{
system("cls");
cout<<"*******************************"<<endl;
cout<<"* 活期储蓄账目管理系统 *"<<endl;
cout<<"*******************************"<<endl;
cout<<"*1-储户开户-------------------*"<<endl;
cout<<"*2-储户销户-------------------*"<<endl;
cout<<"*3-存款-----------------------*"<<endl;
cout<<"*4-取款-----------------------*"<<endl;
cout<<"*5-显示所有账户信息-----------*"<<endl;
cout<<"*6-查询余额-------------------*"<<endl;
cout<<"*7-查询交易记录---------------*"<<endl;
cout<<"*0-退出-----------------------*"<<endl;
cout<<"*******************************"<<endl<<endl;
cout<<"********请输入您的选择: ";
cin>>select;
switch(select)
{
case 1:cout<<endl<<"开户:"<<endl;
cout<<"请输入您的基本信息:"<<endl;
cin>>temple;
i=0;
while((i<total)&&(user[i].card!=temple.card))
{
i++;
}
if(i>total-1)
{
user[total]=temple;
system("cls");
cout<<"您已经成功开户!"<<endl<<"您的基本信息为:"<<endl;
cout<<"姓名 卡号 密码 账户金额"<<endl;
cout<<user[total];
total++;
system("pause");
system("cls");
{
ofstream out("user.txt",ios::app);//打开输出文件流
if(out) //如果打开成功,就写入以下内容
{
out<<"姓名:"<<temple.name<<' '<<"卡号:"<<temple.card<<' '<<"密码:"<<temple.password<<' '<<"余额:"<<temple.balance<<"元"<<endl;//向文件输入信息
out.close();//关闭
}
}
{
ofstream out("record.txt",ios::app);
if(out) //如果打开成功,就写入以下内容
{
time(&timep);
vv = gmtime(&timep);
out<<(1900 + vv->tm_year)<<"年"<<(1 + vv->tm_mon)<<"月"<<vv->tm_mday<<"日"<< vv->tm_hour+8<<"时"<< vv->tm_min<<"分"<<vv->tm_sec<<"秒"<<" "<<"姓名:"<<temple.name<<' '<<"卡号:"<<' '<<temple.card<<' '<<"存入"<<temple.balance<<"元"<<endl;
out.close();
}
}
}
else
{
system("cls");
cout<<"账户已经存在,开户失败!!"<<endl;
system("pause");
}
break;
case 2:cout<<endl<<"销户:"<<endl;
cout<<"请输入要注销的卡号:";
cin>>templecard;
k=searchcard(user,total,templecard);
if(k==-1)
{
system("cls");
cout<<"输入有误,账户不存在"<<endl;
system("pause");
}
else
{
chick(user,k);
system("cls");
cout<<"您的账户已经成功注销!并返还您"<<user[k].balance<<"元."<<endl;
system("pause");
{
ofstream out("record.txt",ios::app);
if(out)
{
time(&timep);
vv = gmtime(&timep);
out<<(1900 + vv->tm_year)<<"年"<<(1 + vv->tm_mon)<<"月"<<vv->tm_mday<<"日"<< vv->tm_hour+8<<"时"<< vv->tm_min<<"分"<<vv->tm_sec<<"秒"<<" "<<"姓名:"<<user[k].name<<' '<<"卡号:"<<' '<<user[k].card<<' '<<"注销账户,并返还"<<user[k].balance<<"元."<<endl;
out.close();
}
}
for(i=k+1;i<total;i++)
{
user[i-1]=user[i];
}
total--;
{
ofstream out("user.txt");
if(out)
{
for(i=0;i<total;i++)
{
out<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<"元"<<endl;
out.close();
}
}
}
}
cout<<endl;
break;
case 3:cout<<endl<<"存款:"<<endl;
cout<<"请输入您的卡号:";
cin>>templecard;
k=searchcard(user,total,templecard);
if(k==-1)
{
system("cls");
cout<<"输入有误,账户不存在"<<endl;
system("pause");
}
else
{
chick(user,k);
cout<<"请输入要存入的金额:";
cin>>money;
user[k].balance=user[k].balance+money;
system("cls");
cout<<"您已经成功存入"<<money<<"元,卡上还余"<<user[k].balance<<"元."<<endl;
{
ofstream out("record.txt",ios::app);
if(out)
{
time(&timep);
vv = gmtime(&timep);
out<<(1900 + vv->tm_year)<<"年"<<(1 + vv->tm_mon)<<"月"<<vv->tm_mday<<"日"<< vv->tm_hour+8<<"时"<< vv->tm_min<<"分"<<vv->tm_sec<<"秒"<<" "<<"姓名:"<<user[k].name<<' '<<"卡号:"<<' '<<user[k].card<<' '<<"存入"<<money<<"元"<<endl;
out.close();
}
}
{
ofstream out("user.txt");
if(out)
{
for(i=0;i<total;i++)
{
out<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<"元"<<endl;
}
out.close();
}
}
system("pause");
}
break;
case 4:cout<<endl<<"取款:"<<endl;
cout<<"请输入您的卡号:";
cin>>templecard;
k=searchcard(user,total,templecard);
if(k==-1)
{
system("cls");
cout<<"输入有误,账户不存在"<<endl;
system("pause");
}
else
{
chick(user,k);
cout<<"请输入要取的金额:";
cin>>money;
if(user[k].balance<money)
{
cout<<"您的账户仅余"<<user[k].balance<<"元"<<endl;
cout<<"是否继续领取?(是按1,否按0):";
cin>>m;
if(m==0)
{
cout<<endl;
break;
}
else
{
templemoney=user[k].balance;
user[k].balance=0;
{
ofstream out("record.txt",ios::app);
if(out)
{
time(&timep);
vv = gmtime(&timep);
out<<(1900 + vv->tm_year)<<"年"<<(1 + vv->tm_mon)<<"月"<<vv->tm_mday<<"日"<< vv->tm_hour+8<<"时"<< vv->tm_min<<"分"<<vv->tm_sec<<"秒"<<" "<<"姓名:"<<user[k].name<<' '<<"卡号:"<<' '<<user[k].card<<' '<<"取出"<<templemoney<<"元"<<endl;
}
out.close();
}
{
ofstream out("user.txt");
if(out)
{
for(i=0;i<total;i++)
{
out<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<"元"<<endl;
}
out.close();
}
}
system("cls");
cout<<"您已成功取出"<<templemoney<<"元,卡上还余"<<user[k].balance<<"元."<<endl;
system("pause");
}
}
else
{
user[k].balance=user[k].balance-money;
{
ofstream out("record.txt",ios::app);
if(out)
{
time(&timep);
vv = gmtime(&timep);
out<<(1900 + vv->tm_year)<<"年"<<(1 + vv->tm_mon)<<"月"<<vv->tm_mday<<"日"<< vv->tm_hour+8<<"时"<< vv->tm_min<<"分"<<vv->tm_sec<<"秒"<<" "<<"姓名:"<<user[k].name<<' '<<"卡号:"<<' '<<user[k].card<<' '<<"取出"<<money<<"元"<<endl;
out.close();
}
}
{
ofstream out("user.txt");
if(out)
{
for(i=0;i<total;i++)
{
out<<"姓名:"<<user[i].name<<' '<<"卡号:"<<user[i].card<<' '<<"密码:"<<user[i].password<<' '<<"余额:"<<user[i].balance<<"元"<<endl;
}
out.close();
}
}
system("cls");
cout<<"您已成功取出"<<money<<"元,卡上还余"<<user[k].balance<<"元."<<endl;
system("pause");
}
}
break;
case 5:system("cls");
display(user,total);
system("pause");
break;
case 6:cout<<endl<<"查询余额:"<<endl;
cout<<"请输入您的卡号:";
cin>>templecard;
k=searchcard(user,total,templecard);
if(k==-1)
{
system("cls");
cout<<"输入有误,账户不存在"<<endl;
system("pause");
}
else
{
chick(user,k);
system("cls");
cout<<"您的账户余额为:"<<user[k].balance<<"元"<<endl;
system("pause");
}
break;
case 7:cout<<endl<<"查询交易记录:"<<endl;
cout<<"请输入要查询的卡号:";
cin>>templecard;
k=searchcard(user,total,templecard);
if(k==-1)
{
system("cls");
cout<<"输入有误,账户不存在"<<endl;
system("pause");
}
else
{
chick(user,k);
ifstream in("record.txt",ios::app);//打开输入文件流
if(in)//如果打开成功
{
for(i=0;i<MAX;i++)
{
in>>c[i].time>>c[i].name>>c[i].cardno>>c[i].card>>c[i].money;//从文件读取信息
}
system("cls");
for(i=0;i<MAX;i++)
{
if(c[i].card==templecard)
{
cout<<c[i].time<<" "<<c[i].name<<' '<<' '<<c[i].cardno<<c[i].card<<' '<<' '<<c[i].money<<endl;//显示
}
}
in.close();//关闭
system("pause");
}
}
break;
}
}while(select!=0);
system("cls");
cout<<"欢迎使用本系统!!"<<endl;
return 0;
}
记得初始登录工号:20001029
密码:lovehy
需要详细设计报告请联系我删除线格式