您的位置:首页 > 其它

课程设计 银行储蓄系统

2015-07-18 11:22 357 查看
main.cpp
/*版权所有
*文件名称:银行储蓄系统
*当前版本:V1.0
*作者:曹莉萍
*完成日期:2015.07.18
*/
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include "staff.h"
#include "bank.h"
#include "user.h"
#include <ctime>
using namespace std;
void ctime();
int main()
{
cout<<"+-----------------------------------+"<<endl;
cout<<"+ ※※※                            +"<<endl;
cout<<"+        欢迎来到暮光银行           +"<<endl;
cout<<"+                            ※※※ +"<<endl;
cout<<"+-----------------------------------+"<<endl;
//ctime();
Bank b;
if(!b.passtaff())            //业务员登录
exit(1);                 //退出系统
cout<<endl;
b.showMenu();                //显示菜单
b.manage();                  //开始工作
return 0;
}

bank.cpp

/*版权所有
*文件名称:银行储蓄系统
*当前版本:V1.0
*作者:曹莉萍
*完成日期:2015.07.18
*/
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <fstream>
#include "staff.h"
#include "bank.h"
using namespace std;
/*功能描述:验证密码
*输入参数:只能为数字的密码
*输出参数:形式如******的密码表现形式
*/
int inputPassword()
{
char ch;  //接收字符形式密码
int iPass=0;   //要转换为数字
int i;
while(1)
{
for(i=0; i<6; i++)
{
ch=getch();  //输入但不显示
putchar('*');   //输出*
if(isdigit(ch))
iPass=iPass*10+(ch-'0');
else
{
iPass=0;
break;  //退出for循环后,再次接受
}
}
fflush(stdin); //清除键盘缓存区中已经有的输入
cout<<endl;
if(iPass==0)  //此条件成立可能由两种情况引起:输入了非数字字符被直接重置为0,或6位全0后正常退出for循环
{
cout<<"密码要求全为数字,且不能全0!"<<endl;;
cout<<"请重新输入密码: ";
}
else
break;
}
return iPass;
}

//功能描述:业务员登录
bool Bank::passtaff()
{
Staff s1;
string acc;
char ch;
cout<<"请输入业务员账户:";
cin>>acc;
for(int j=0; j<3; ++j)
{
int pw=0;
cout<<"请输入密码:";
for(int i=0; i<6; i++)
{
ch=getch();  //输入但不显示
putchar('*');   //输出*
pw=pw*10+(ch-'0');
}
if(s1.pass(acc,pw))
{
return true;
}
else
{
cout<<"\n用户名或密码错误。"<<endl;
}
}
cout<<"\n错误三次,系统自动退出。"<<endl;
return false;
}
//显示菜单
void Bank::showMenu()
{
cout<<endl;
cout<<"+--------------------------------+"<<endl;
cout<<"+ 1 开户      2 销户      3 存款 +"<<endl;
cout<<"+ 4 取款      5 查询      6 转账 +"<<endl;
cout<<"+ 7 挂失      8 解挂      0 退出 +"<<endl;
cout<<"+ 9 修改信息         10 个人信息 +"<<endl;
cout<<"+--------------------------------+"<<endl;
}
//开始工作
void Bank::manage()
{
int order=1;
do
{
openfile();
cout<<"请输入操作指令:";
cin>>order;
switch(order)
{
case 1:
openAccount();
break;
case 2:
deleteAccount();
break;
case 3:
saveMoney();
break;
case 4:
drawMoney();
break;//取款
case 5:
refer();
break;//查询
case 6:
transfer();
break;//转账
case 7:
reportLoss();
break;//挂失
case 8:
hangSolution();
break;//解挂
case 9:
changedisplays();
break;//修改个人信息
case 10:
display();
break;//显示个人信息
case 0:
cout<<endl;
cout<<"+--------------------------------------+"<<endl;
cout<<"+        谢谢您的使用,再见!          +"<<endl;
cout<<"+--------------------------------------+"<<endl;
exit(1);
break;
}
savefile();
}
while(1);
}

void Bank::openAccount()  //开户
{
int acc;   //账号
char nam[20];   //姓名
int pw;   //密码
char di[30]; //地址
char pho[11];//电话
double mon;   //金额
int sta;   //状态
char id[18];   //身份证号

cout<<"正在开户"<<endl;
acc=10001+nownum;
cout<<"账号:"<<acc<<endl;
cout<<"户主姓名:";
cin>>nam;
cout<<"身份证号:";
for(int n=0; n<18; n++)
{
cin>>id
;
}
cout<<"地址:";
cin>>di;
cout<<"联系电话(请输入正确的手机号码):";
for(int n=0; n<11; n++)
{
cin>>pho
;
}
int Pass1, Pass2;
cout<<"密码:";
Pass1=inputPassword();  //输入密码1
cout<<"确认密码:";
Pass2=inputPassword();  //输入密码2
if(Pass1==Pass2)
{
pw=Pass1;
sta=0; //账户状态为“正常”
cout<<"存入金额:";
cin>>mon;
if(mon>50) //一般银行开户最低金额为50
{
users[nownum].setUser(acc,nam,id,di,pho,pw,mon,sta);//出了好几次错的地方  id
++nownum;                           //正式用户数增加1,确认了新用户已经加入
cout<<"开户成功!"<<endl;
}
else
cout<<"金额少于50元,开户失败"<<endl;
}
else
{
cout<<"两次密码不一致,未成功开户!"<<endl; //没有N++,则读入的值无效
}
}

void Bank::deleteAccount()
{
int who;  //查找到该账号在数组中对应的下标
who=getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].showName();
if(users[who].passwordIsRight())
{
users[who].showMoney("余额:");   //提示"余额"二字,显示金额
cout<<"确认销户(y/n)?";
if(getchar()=='y'||getchar()=='Y')
{
users[who].showMoney("销户成功!本次取款金额为:");
users[who].money=0;  //取款后余额变0
users[who].status=2;  //状态变为注销

}
else
{
cout<<"你取消了操作,销户失败!"<<endl;
}
}
}
}

void Bank::saveMoney() //存款
{
int who;
double money;
who=getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
if(users[who].status==0)
{
users[who].showName();
//cout<<endl;
cout<<"输入存款额:";
cin>>money;
users[who].money+=money;
users[who].showMoney("存款后,金额为:");
}
else if(users[who].status==1)
{
cout<<"该用户处于挂失状态,存款失败!"<<endl;
}
else if(users[who].status==2)
{
cout<<"该用户已经销户,存款失败!"<<endl;
}
}
return;
}
void Bank::drawMoney() //取款
{
int who;
double money;
who=getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
if(users[who].isNormalUser())
{
users[who].showName();
if(users[who].passwordIsRight())
{

cout<<"输入取款额:";
cin>>money;

if(money>users[who].money)
{
cout<<"余额不足,取款失败!"<<endl;
}
else
{
users[who].money-=money;
users[who].showMoney("取款后,余额为:");

}
}
}
}
return;
}

void Bank::refer()    //查询
{
int who;
int cacc;
char pan;
string cnam;
string sta[3]= {"正常","挂失","已经销户"};
string hms;
string cyw;
who=getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].showName();
if(users[who].passwordIsRight())
{
users[who].showMoney("余额:");
cout<<"状态:"<<sta[users[who].status]<<endl;
cin>>pan;
if(pan!='y')
{

if(users[who].account!=cacc)
{
cout<<"当前未办理过任何业务。"<<endl;
}
}
else
{
cout<<"+-------------查询结束-------------+"<<endl;
cout<<endl;
}
}

}
return;
}
void Bank::transfer()   //转账
{
int whoout, whoin;
double money;
cout<<"转出自";
whoout=getUser();  //根据账号查询用户,返回用户的下标
if(whoout>=0)   //说明id账户存在
{
if(users[whoout].isNormalUser())
{
users[whoout].showName();
if(users[whoout].passwordIsRight())
{
cout<<"输入转账金额:";
cin>>money;
if(money>users[whoout].money)
{
cout<<"余额不足,转账失败!"<<endl;
}
else
{
cout<<"转出到";
whoin = getUser();  //根据账号查询用户,返回用户的下标
if(whoin>=0)   //说明id账户存在
{
if(users[whoin].isNormalUser())
{
users[whoout].money-=money;
users[whoin].money+=money;
users[whoout].showMoney("转账后,余额为:");

}
}
}
}
}
}
return;
}

void Bank::reportLoss()   //挂失
{
int who;
who = getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].showName();
if(users[who].passwordIsRight())
{
if(users[who].status==0)
{
users[who].status=1;
cout<<"挂失成功"<<endl;

}
else if(users[who].status==1)
{
cout<<"该账户已经处于挂失状态"<<endl;
}
else if(users[who].status==2)
{
cout<<"该账户已销户,不能挂失"<<endl;
}
}
}
return;
}

void Bank::hangSolution() //解挂
{
int who;
who = getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].showName();
if(users[who].passwordIsRight())
{
if(users[who].status==0)
{
cout<<"该账户处于正常状态,不需要解除挂失"<<endl;
}
else if(users[who].status==1)
{
users[who].status=0;
cout<<"解除挂失成功"<<endl;
}
else if(users[who].status==2)
{
cout<<"该账户已销户,操作无效"<<endl;
}
}
}
return;
}

void Bank::changePassword() //改密
{
int who;
int iPass1, iPass2;
who = getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].showName();
if(users[who].passwordIsRight())
{
cout<<"新密码:";
iPass1=inputPassword();  //输入密码1
cout<<"确认密码:";
iPass2=inputPassword();  //输入密码2
if(iPass1==iPass2)
{
users[who].password=iPass1;
cout<<"密码修改成功!"<<endl;
}
else
{
cout<<"两次输入不同,修改失败!"<<endl;
}
}
}
return;
}
void Bank::changename() //修改用户名
{
int who;
string nam;
char pan;
who = getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].showName();
if(users[who].passwordIsRight())
{
cout<<"新姓名:";
cin>>nam; //输入用户名
cout<<"确认修改姓名(y/n)?";
cin>>pan;
if(pan=='y')
{
users[who].name=nam;

cout<<"用户名修改成功!"<<endl;
}
else
{
cout<<"你已取消修改!"<<endl;
}
}
}
return;
}
void Bank::changedizhi() //修改地址
{
int who;
char di[30];
char pan;
who = getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].showName();
if(users[who].passwordIsRight())
{
cout<<"新地址:";
gets(di); //输入地址
cout<<"确认修改地址(y/n)?";
cin>>pan;
if(pan=='y')
{
for(int n=0; n<30; n++)

users[who].dizhi
=di
;

cout<<"地址修改成功!"<<endl;
}
else
{
cout<<"你已取消修改!"<<endl;
}
}
}
return;
}
void Bank::changeidcard() //修改身份证号
{
int who;
char id[18];
char pan;
who = getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].showName();
if(users[who].passwordIsRight())
{
cout<<"新身份证号:";
gets(id); //输入身份证号
cout<<"确认修改身份证号(y/n)?";
cin>>pan;
if(pan=='y')
{
for(int n=0; n<18; n++)
{
users[who].idcard
=id
;
}
cout<<"身份证号修改成功!"<<endl;
}

else
{
cout<<"你已取消修改!"<<endl;
}
}

}
return;

}
void Bank::changephone() //修改手机号
{
int who;
char pho[11];
char pan;
who = getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].showName();
if(users[who].passwordIsRight())
{
cout<<"新电话号:";
gets(pho); //输入电话号
cout<<"确认修改电话号(y/n)?";
cin>>pan;
if(pan=='y')
{
for(int n=0; n<11; n++)
{
users[who].phone
=pho
;
}
cout<<"电话号修改成功!"<<endl;
}

else
{
cout<<"你已取消修改!"<<endl;
}
}
}
return;

}
void Bank::changedisplays() //修改个人信息
{
int n;
cout<<"+----请输入想要修改的项目:----+"<<endl;
cout<<"+-----------1.姓名-------------+"<<endl;
cout<<"+-----------2.身份证号---------+"<<endl;
cout<<"+-----------3.密码-------------+"<<endl;
cout<<"+-----------4.地址-------------+"<<endl;
cout<<"+-----------5.电话-------------+"<<endl;
cout<<"请输入:";
cin>>n;
switch(n)
{
case 1:
changename();
break;
case 2:
changeidcard();
break;
case 3:
changePassword();
break;
case 4:
changedizhi();
break;
case 5:
changephone();
break;
}
}

int Bank::getUser() //查找用户   二分法
{
int id;
cout<<"账号:";
cin>>id;
int index=-1;
int low=0, high=nownum-1, mid;
while(low<=high)
{
mid = (low+high)/2;
if(users[mid].account==id)
{
index=mid;
break;   //找到了,立即退出循环
}
else if (users[mid].account>id)
high=mid-1;
else
low=mid+1;
}
if (index<0)
cout<<"该用户不存在,本次操作失败!"<<endl;
return index; //若找到,其值在0~N-1间,否则,保持-1
}

void Bank::openfile()//导入文件
{
ifstream infile("users.txt",ios::in);
int i=0;
if(!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}
nownum=jis();        //jis里面有return当前总用户数
users=new User[nownum+1];
while(infile>>users[i].account>>users[i].name>>users[i].idcard>>users[i].dizhi>>users[i].phone>>users[i].password>>users[i].money>>users[i].status)
{
++i;
}
infile.close();
}
void Bank::savefile() //保存文件
{
ofstream qingkfile("users.txt",ios::trunc);//trunc 打开并清空文件
qingkfile.close();
ofstream outfile("users.txt",ios::out);
if(!outfile)
{
cerr<<"open error!"<<endl;
exit(1);
}
for(int i=0; i<nownum; ++i)          //注意这里的空格即‘\t',关系到是否能正常保存用户信息
{
outfile<<users[i].account<<'\t'<<users[i].name<<'\t';
for(int n=0; n<18; n++)
{
outfile<<users[i].idcard
;
}
outfile <<'\t'<<users[i].dizhi<<'\t';
for(int n=0; n<11; n++)
{
outfile<<users[i].phone
;
}
outfile<<'\t'<<users[i].password<<'\t'<<users[i].money<<'\t'<<users[i].status<<endl;
}
outfile.close();
delete []users;                   //释放剩余空间
return;
}
void Bank::display()      //显示个人信息
{
int who;
who = getUser();  //根据账号查询用户,返回用户的下标
if(who>=0)   //说明id账户存在
{
users[who].displays();
}
}
int Bank::jis()
{
int acc;   //账号
char nam[20];   //姓名
char id[18]; //身份证号
char di[30];//地址
char pho[11];//电话
int pw;   //密码
double mon;   //金额
int sta;   //状态
int i=0;
int nownum;
ifstream infile("users.txt");
while(infile>>acc>>nam>>id>>di>>pho>>pw>>mon>>sta)
{
++i;
}
infile.close();
return i;
}


staff.cpp

/*版权所有
*文件名称:银行储蓄系统
*当前版本:V1.0
*作者:曹莉萍
*完成日期:2015.07.18
*/
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include "staff.h"
using namespace std;
bool Staff::pass(string sacc,int ps)
{
bool judge=false;
fstream infile("staff.txt",ios::in);
if(!infile)
{
cerr<<"open error!"<<endl;
exit(1);
}
while(!infile.eof())
{
infile>>stafft.account>>stafft.password;
if(stafft.account==sacc&&ps==stafft.password)
{
judge=true;
break;
}
}
infile.close();
return judge;
}


user.cpp

/*版权所有
*文件名称:银行储蓄系统
*当前版本:V1.0
*作者:曹莉萍
*完成日期:2015.07.18
*/
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <conio.h> //将密码变成*号
#include "user.h"
using namespace std;
bool inputpassw()
{
char ch;  //接收字符形式密码(这里必须输入字符,因为只有字符才能转化成'*')
int iPass=0;   //要转换为ascll的形式
int i;
while(1)
{
for(i=0; i<6; i++)
{
ch=getch();  //输入但不显示
putchar('*');   //输出*
if(iPass=ch)
return true;  //假设第一位输入1,第二位输入2,那么此时密码就应该是1*10+2=12####
else
{
iPass=0;
return false;
break;  //退出for循环后,再次接受
}
}
}
return iPass;
}
void User::setUser(int acc,string nam,char id[18],char di[30],char pho[11],int pw, double mon,int sta)
{
account=acc;
name=nam;
for(int n=0; n<30; n++)
{
dizhi
=di
;
}
for(int n=0; n<11; n++)
{
phone
=pho
;
}
password=pw;
money=mon;
for(int n=0; n<18; n++)
{
idcard
=id
;
}
status=sta;
}
bool User::passwordIsRight()
{
int iPass;
bool right=true;

cout<<"输入密码:";
iPass=inputpassw();
if(iPass!=password)
{
right = false;
cout<<"输入密码错误,不能继续操作!"<<endl;
}
return right;
}

void User::showName()
{
cout<<"用户名:"<<name<<endl;

}

void User::showMoney(string prompt)
{
cout<<prompt<<money<<endl;
}

bool User::isNormalUser()            //判断用户状态是否正确
{
bool normal = true;
if(status!=0)
{
normal = false;
cout<<"该账户处于"<<(status==1?"挂失":"销户")<<"状态,不能继续操作..."<<endl;
}
return normal;
}
void User::displays()
{
cout<<"卡号:"<<account<<endl;
cout<<"姓名:";
cout<<name<<endl;
cout<<"地址:";
cout<<dizhi<<endl;
cout<<"电话: ";
for(int n=0; n<11; n++)
{
cout<<phone
;
}
cout<<endl;
}


bank.h

/*版权所有
*文件名称:银行储蓄系统
*当前版本:V1.0
*作者:曹莉萍
*完成日期:2015.07.18
*/
#ifndef BANK_H_INCLUDED
#define BANK_H_INCLUDED
#include <iostream>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <ctype.h>
#include <cstdlib>
#include <cstdio>
#include <conio.h>
#include "user.h"
using namespace std;
class Bank
{
public:
Bank()
{
nownum=0;
}
bool passtaff();             //业务员信息
void openfile();             //导入文件
void savefile2(int acc, string nam, char id[18], char di[30],char pho[11],int pw, double mon,int sta);   //保存一行数据
void caculfile();            //计算
void savefile();             //保存文件
void manage();               //开始工作
void showMenu();             //显示菜单
void openAccount();          //开户
void deleteAccount();        //销户
void saveMoney();            //存款
void drawMoney();            //取款
void refer();                //查询
void transfer();             //转账
void reportLoss();           //挂失
void hangSolution();         //解挂
void changePassword();       //改密
void changename();           //改姓名
void changeidcard();         //改身份证
void changedizhi();          //改地址
void changephone();          //改电话
void display();             //显示个人信息
void changedisplays();      //修改个人信息
int getUser();              //查找用户
int jis();                  //计算用户数
private:
int nownum;
User *users;
//User数组,动态数组 体现在保存文件方面   delete[]users
};

#endif // BANK_H_INCLUDED


staff.h

/*版权所有
*文件名称:银行储蓄系统
*当前版本:V1.0
*作者:曹莉萍
*完成日期:2015.07.18
*/
#ifndef STAFF_H_INCLUDED
#define STAFF_H_INCLUDED
#include <iostream>
#include <cmath>
using namespace std;
struct staffTatus
{
string account;
int password;
};
class Staff
{
public:
bool pass(string sacc,int ps);
private:
staffTatus stafft;
};

#endif // STAFF_H_INCLUDED


user.h

/*版权所有
*文件名称:银行储蓄系统
*当前版本:V1.0
*作者:曹莉萍
*完成日期:2015.07.18
*/
#ifndef USER_H_INCLUDED
#define USER_H_INCLUDED
#include <iostream>
#include <cmath>
using namespace std;
//定义user类
class User
{
public:
User() {}
void setUser(int acc, string nam,char id[18],char di[30],char pho[11],int pw, double mon,int sta);
bool isNormalUser();       //判断用户状态是否正确
bool passwordIsRight();    //判断密码是否正确
void showName();          //输出用户名
void displays();          //输出用户个人信息
void showMoney(string prompt);//显示余额
friend class Bank;        //友元类
private:
int account;
string name;
char dizhi[30];
char phone[11];
int password;
double money;
char idcard[18];
int status;
};

#endif // USER_H_INCLUDED






内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: