活期储蓄账目管理系统-管理员版
设计菜单,以便进行人机交互,选择对应的功能来实现。主菜单应该包括主要的功能以及简单的介绍和退出功能。在主菜单打开之前应该是一个登陆界面只有当管理员账号和密码输对的时候才能进入系统进行操作,在存取款和查找交易记录时只有输入的卡号和密码正确时,才可以进行操作。这样才能保证安全性。在查找交易记录时应该包含时间、用户名、卡号、存入或取出的金额等信息。综上所诉需要构造3个类或者结构体,分别存储管理员账号信息,用户账号信息,存取款信息。为了程序的模块化,应该使用构造函数来避免重复累赘的代码,例如检查密码是否正确的函数,还有搜索卡号是否存在的函数等等。程序流程概要图 详细设计 1. 创建记录信息的结构体包含姓名,卡号,金额,时间等。 2. 创建用户类包含用户的姓名,卡号,密码,账户余额等,重载其输入输出运算符。创建管理员类,使管理员类继承用户类,表明管理员本身也可以是用户。构造函数:根据输入的卡号查询卡号是否存在,如果存在返回它的标识,否则返回 -1。 验证密码函数:根据查询卡号函数返回的标识,找到相应卡号的密码,将密码与输 入值对比,如果相同则进项下一项,如果不同则递归调用本身让使用者重新输入 密码。构造显示所有账户信息的函数,用 for 循环进行遍历输出。主函数:首先用 do-while 循环构建等会界面,让用户输入管理员用账号密码,直 到输入正确时停止循环进行下一步。再次使用一个 do-while 并通过使用 switch-case 函数进行功能选择。用 fstream.h 中的对应在开户,销户,存取款时对 user.txt 中的内容进行修改,在显 示所有用户信息时对 user.txt 文件进行读取,在查询记录时 record.txt 文件中的内 容进行读取。 源代码
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string.h>
#include<time.h>
using namespace std
;
#include<windows.h>
#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;
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 需要详细设计报告请联系我删除线格式