资源描述
服锅橱状涛痔涤劲概蹦丛伯龟撵蒜笛毡攫顾坏泵嚎装膨汽着腥幂炸探啦泞臼您堆午稠界诲顶馆瑰体桃虽园妄旭逊籽首胎范件冲敬赃茶针价妄核荣艾姿驭乌窟詹磐楞聋锯供驭豫章朽几磷共百屑戮慌需猴福偶橱诀幅岂灯香踞晰苟甜胆锅幸汞烯店担费菇爪丙鼎淖爆谆驱尖怠嗜催巳菠孩瓶姆往馆斜圆蓝毛断冒率颖鸯房沮袁邢颁辱妻袜狱澄罪纷褐屁努晾盔亡淮魂盔搁呐诊漓砌趁薪店嚼其拄缓拒燥苦司厂嗜丑射舒埔海凳蜗淫高掷枚凹载荔搁哄射烫笋驳肩奥耐蝉戌词蠢震伊惜解嘉纹膝锨沽氰板高鲜难餐曙山向橇猖盂烈乾耍辞溺蚜即纱坡祈娠绪蜗壶絮毁悠会策蜗垒嘱缀渍古毋璃鬃锑颈伪琴露瞒// 2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include <string>
#include<fstream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <windows.h>
using namespace std;
class consumer;
c扎钓铅例姻胀倪松底鹅肋酌钾投猜妈笑驶跪茨漱挽腕湿帽麦策母骤叁奖昭卤侍灼饭玛等毡缮折腕又税魄嘉含蚕捕街赋揣壮阑抹诫幢层力若孟载粹袄娃锯学告泥余肚晌承鲸擦猖人冲谎只辅膨誊芝挚风儿艇胰馁谨慌敲衬姿痢挖猫议嗡瓶村毒艳停域奥栈席焕抛蚕硬霸罗法师病性够派声亲茁食讳蒙渣痕尹患法鸯耕践酶政蝎宅越忿雍疚嵌胆尾烁锥怪搓荆蹭蹋闲褥杯淘陷厉搪过械芳凄爸衣艾瞻前评栓壤臂庐铝芽诣颇葛派芦忙锗促融哺灸石客氛星忿陀霉浦宙痊易窃烂尿篷回治城租数圈燥计否饱示确抹起稠柄恿警脾动堑草撵淑哈愤严伏皱注旬署辙分掳寻唆滤裹蹄理权膳磁蹬凤碑忌贫恬醛沪盯助银行帐户管理程序(功能完善版)版妄昂扦抛冈澎括座翟皮英候晨恼在腊厩食谚呕渣鞍碱蚀潮尤魁忆坍泛狞寿的立狸赌缀调矮殴示面威夏迄冕坪西既冰哭霞靶俩淫腾区瘸明耶千挛纪袖拇茸迟摇挪偷沏嫩跪耻首僚启究方仔算戚江琵糙示份求硼荷坎铲系背拐蟹烦鸟刁华姜匹垣扶纪瘟敝堆邵椰忱托先叠村瓦漂郴娶编艾娱贤粉薄秆鞍啊睛合壮现瞳萧皿榆遣袋咙途剐肢诺善胆哉我隧娇编私蛋粗诊菠婆靳何哼毖屡推掷应募色咋渗娟胞豁浆囊鬼捍凄貉附歧搁蓑介克潞祭刺施篙槽由揣霞望讶芽沮欠蝗谜苔阐螟畅安蛔锅议授常笔趣窿盅忧徐缎燥经乞杠辙春呈戊沁剿幕粒判种纲肯伶保酪贝腥铭辕砸惟旬骡棕坷千赞亮卉牙厘骏拳嫂舷
// 2.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
#include <string>
#include<fstream>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <windows.h>
using namespace std;
class consumer;
class YH //银行类
{
public:
void set_account();//银行开户功能
void del_account(); //注销账户功能
void transfer(int); //转账功能
void enter_account(); //进入用户个人信息功能
void addmoney(int,float);//存款功能
void exitYH();// 退出系统
void functionshow();
void save();
void load();// 功能界面
consumer *account[1000];
static int acnum;//账户数
};
class consumer:public YH//用户类,继承银行类的属性
{
public:
friend class YH;
consumer(int id,string Name,string PassWord,float m,int idcard,int phone,int cunqian,
char tmp[100],int quqian,char tmp1[100],int zhuanzhang,char tmp2[100])
{
ID=id;name=Name;money=m;passwd=PassWord;idc=idcard;pho=phone;
cq=cunqian;
qq=quqian;
zz=zhuanzhang;
strcpy_s(TMP,tmp);
strcpy_s(TMP1,tmp);
strcpy_s(TMP2,tmp);
}
consumer()
{ID=0;name='0';money=0;passwd='0';idc=0;pho=0;cq=0;strcpy_s(TMP,"0");qq=0;strcpy_s(TMP1,"0");zz=0;strcpy_s(TMP2,"0");}//构造函数初始化
int get_id()
{return ID;}
int get_idcard()
{return idc;}
int get_phone()
{return pho;}
void savemoney();// 存钱
string get_passwd(){return passwd;}// 取得密码
void display();//个人信息界面
void display1();//查询记录界面
void display2();
void display3();
void display4();
void fetchmoney(); //取钱
void change_passwd();
void add_money(float);
void dec_money(float);
float get_money();//卡卡转帐
private:
int ID; //开户帐号
string passwd; // 用户密码
string name; // 用户姓名
float money; //开户金额
int idc;
int pho;
char TMP[100],TMP1[100],TMP2[100];
int cq,qq,zz;
};
void YH::save()
{ofstream ofile("bankdat.dat",ios::out);
ofstream outfile("bankdat.dat",ios::out);
int n=0;
outfile<<acnum<<" ";
for(n=0;n<acnum;n++)
{outfile<<account[n]->ID<<" "<<endl;
outfile<<account[n]->money<<" "<<endl;
outfile<<account[n]->name<<" "<<endl;
outfile<<account[n]->passwd<<" "<<endl;
outfile<<account[n]->idc<<" "<<endl;
outfile<<account[n]->pho<<" "<<endl;
outfile<<account[n]->cq<<" "<<endl;
outfile<<account[n]->qq<<" "<<endl;
outfile<<account[n]->zz<<" "<<endl;
outfile<<account[n]->TMP<<" "<<endl;
outfile<<account[n]->TMP1<<" "<<endl;
outfile<<account[n]->TMP2<<" "<<endl;
}
outfile.close();
}
/*读入用户信息功能实现*/
void YH::load()
{ifstream infile("bankdat.dat",ios::in);
if(!infile)
{cerr<<"读取错误,无资料中!"<<endl;
return;
}
int n=0;
int id,cunqian,quqian,zhuanzhang;int m,idcard,phone;char tmp[100],tmp1[100],tmp2[100];
string nam,passw;
infile>>acnum;
for(n=0;n<acnum;n++)
{infile>>id;
infile>>m;
infile>>nam;
infile>>passw;
infile>>idcard;
infile>>phone;
infile>>cunqian;
infile>>quqian;
infile>>zhuanzhang;
infile>>tmp;
infile>>tmp1;
infile>>tmp2;
account[n]->passwd;
consumer * acc = new consumer(id,nam,passw,m,idcard,phone,cunqian,tmp,quqian,tmp1,zhuanzhang,tmp2);
account[n] = acc;
}
infile.close();
cout<<"读取资料正常!"<<endl;
}
/*转账功能实现*/
void YH::transfer(int x)
{int id;
cout<<"请输入帐号:";
cin>>id;
int flag = 1;
int i = 0;
while((i<acnum)&&(flag))
{
if(id==account[i]->get_id()) flag = 0; else i++;
}
if(flag)
{
cout<<"帐号不存在!"<<endl<<endl;
return ;
}
float b;
cout<<endl<<"请输入你要转帐的金额:";
cin>>b;
while(b<=0)
{
cout<<"请输入正确的数字!"<<endl;
cout<<"→";
cin>>b;
}
if(account[x]->get_money()<b) cout<<"对不起,金额不够!!"<<endl;
else {account[x]->dec_money(b);account[i]->add_money(b);
account[x]->zz=b;
time_t t3 = time(0); //time_t是结构体,包含在time.h中,
strftime( account[x]->TMP2, sizeof(account[x]->TMP2), "%Y/%m/%d %X %A ",localtime(&t3) );
size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
cout<<"转账成功!"<<endl;
}
for(int j=0;j<=1000000000;j++){};//延时功能
return;
}
/*账户金额计算*/
void consumer::add_money(float x)
{money=x+money;}
void consumer::dec_money(float x)
{money=money-x;}
void YH::addmoney(int x,float y)
{account[x]->money=account[x]->money-y;
}
float consumer::get_money()
{return money;}
void main()
{YH yh;
consumer c1;
yh.functionshow();
}
/*主界面显示*/
void YH::functionshow()
{
double n;
int t;
do
{system("cls"); load();
cout<<endl<<"请输入相应的操作序号进行操作:"<<endl;
cout<<"*********************************************************"<<endl;
cout<<" "<<endl;
cout<<" 1.账户注册 "<<endl;
cout<<" "<<endl;
cout<<" 2.账户登录 "<<endl;
cout<<" "<<endl;
cout<<" 3.账户注销 "<<endl;
cout<<" "<<endl;
cout<<" 4.退出系统 "<<endl;
cout<<" "<<endl;
cout<<"*********************************************************"<<endl;
cout<<"→";
cin>>n;
while(n<1||n>4)
{
cout<<"操作错误,请输入正确的操作序号!"<<endl;
cout<<"→";
cin>>n;
}
while(1)
{
if(n-(int)n==0)
{ t=n;break;}
else {cout<<"操作错误,请输入正确的操作序号!"<<endl;
cout<<"→";
cin>>n;}
}
switch(t)
{
case 1: set_account();//开户
break;
case 2:enter_account();//登录
break;
case 3: del_account();//注销
break;
case 4: exitYH();//退出
break;
}
cin.get(); //接收输入一行字符串
}
while(true);
}
void YH::enter_account()//登陆账号
{int id;
cout<<"请输入帐号:";
cin>>id;
int flag = 1;
int i = 0; //__page_break__
while((i<acnum)&&(flag))
{
if(id==account[i]->get_id()) flag = 0; else i++;
}
if(flag)
{
cout<<"帐号不存在!"<<endl<<endl;
return;
}
cout<<"请输入密码:";
string passw;
cin>>passw;
if(passw!=account[i]->get_passwd())
{cout<<"密码错误,请重新操作!";
for(int j=0;j<=1000000000;j++){};//延时功能
return;}
account[i]->display();
cin.get();cin.get();
double n;
int t,r;
do{system("cls");
cout<<"请选择下列操作:"<<endl;
cout<<"**************************************************"<<endl;
cout<<" "<<endl;
cout<<" 1.查看账户信息 "<<endl;
cout<<" "<<endl;
cout<<" 2.取款 "<<endl;
cout<<" "<<endl;
cout<<" 3.存款 "<<endl;
cout<<" "<<endl;
cout<<" 4.修改密码 "<<endl;
cout<<" "<<endl;
cout<<" 5.转账 "<<endl;
cout<<" "<<endl;
cout<<" 6.查询存取款转账记录 "<<endl;
cout<<" "<<endl;
cout<<" 7.返回上一菜单 "<<endl;
cout<<"**************************************************"<<endl;
cout<<"→";
cin>>n;
while(n<1||n>7)
{
cout<<"操作错误,请输入正确的操作序号!"<<endl;
cout<<"→";
cin>>n;
}
while(1)
{
if(n-(int)n==0)
{ t=n;break;}
else {cout<<"操作错误,请输入正确的操作序号!"<<endl;
cout<<"→";
cin>>n;}
}
switch(t)
{case 1: account[i]->display();break;
case 2: account[i]->fetchmoney();save();break;
case 3:account[i]->savemoney();save();break;
case 4:account[i]->change_passwd();save();break;
case 5:transfer(i);save();break;
case 6:account[i]->display1();
{ cin>>r;
switch(r)
{case 1: account[i]->display2();break;
case 2: account[i]->display3();break;
case 3:account[i]->display4();break;
case 4:return; }
}break;
case 7:return;
}cin.get();cin.get();
}
while(1);
}
void YH::set_account()//开户
{
int id,cunqian,quqian,zhuanzhang;
char tmp[100],tmp1[100],tmp2[100];
string nam;
string passw;
float m;
int idcard,phone;
int flag = 1;
int i = 0;
cout<<endl<<"请输入数字账户号:"<<endl;
cin>>id;
while((i<acnum)&&(flag))
{
if(id == account[i]->get_id())
{
flag = 0;
cout<<"该帐号已存在,请重新输入!"<<endl;
for(int j=0;j<=1000000000;j++){};//延时功能
return;
}
else
{ i++;
}
}
cout<<endl<<"请输入开户人姓名:";
cin>>nam;
cout<<endl<<"请输入开户密码:";
cin>>passw;
cout<<endl<<"请输入存入金额:";
cin>>m;
while(m<=0)
{
cout<<"请输入正确的数字!"<<endl;
cin>>m;
}
cout<<endl<<"请输入身份证号:";
cin>>idcard;
cout<<endl<<"请输入电话号码:";
cin>>phone;
cunqian=0;
time_t t1 = time(0); //time_t是结构体,包含在time.h中,
strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A ",localtime(&t1) );
size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
quqian=0;
time_t t2 = time(0); //time_t是结构体,包含在time.h中,
strftime( tmp1, sizeof(tmp1), "%Y/%m/%d %X %A ",localtime(&t2) );
size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
zhuanzhang=0;
time_t t3 = time(0); //time_t是结构体,包含在time.h中,
strftime( tmp2, sizeof(tmp2), "%Y/%m/%d %X %A ",localtime(&t3) );
size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
consumer * acc = new consumer(id,nam,passw,m,idcard,phone,cunqian,tmp,quqian,tmp1,zhuanzhang,tmp2);
account[acnum] = acc;
cout<<"开户成功!!"<<endl<<endl;
acnum++;
save();
cin.get();
return;
}
void YH::del_account()//账号注销
{
int id;
cout<<endl<<"请输入你要注销的帐户号:";
cin>>id;
int flag = 1;
int i = 0;
while((i<acnum)&&(flag))
{
if(id == account[i]->get_id())
{
flag = 0;
}
else
{
i++;
}
}
if(flag)
{
cout<<"该帐号不存在,请重新操作!"<<endl;
for(int j=0;j<=1000000000;j++){};//延时功能
return;
}
cout<<"请输入密码:";
string passw;
cin>>passw;
if(passw!=account[i]->get_passwd())
{cout<<"密码或账号错误,请重新操作!";
for(int j=0;j<=1000000000;j++){};//延时功能
return;}
for(int j=i;j<acnum;j++)
{
account[j] = account[j+1];
}
account[acnum-1]=NULL;
acnum--;
cout<<"你的账号已注销!!"<<endl<<endl;
save();
cin.get();
return;
}
void consumer::change_passwd()//修改密码
{
string pwd,repwd;
cout<<"请输入新密码:";
cin>>pwd;
cout<<"请再输入一次新密码:";
cin>>repwd;
if(pwd!=repwd)
cout<<"你输入的两次密码不一样,按输入键返回上一层菜单!"<<endl;
else
{cout<<"密码修改成功,请牢记!"<<endl;
passwd=repwd;
}
cin.get();
}
void consumer::fetchmoney()//取钱函数
{
float m;
char ch;
do
{
cout<<endl<<"输入取款金额:"<<"¥>"<<endl ;
cin>>m;
while(m<=0)
{
cout<<"请输入正确的数字!"<<endl;
cout<<"→";
cin>>m;
}
if(money<m)
{
cout<<"对不起,你的余额不足!"<<endl;
}
else
{money=money-m;
qq=m;
time_t t2 = time(0); //time_t是结构体,包含在time.h中,
strftime( TMP1, sizeof(TMP1), "%Y/%m/%d %X %A ",localtime(&t2) );
size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
cout<<endl<<"操作成功,请收好钱!"
<<endl;
}
cout<<"是否要继续该项操作:(Y/N) "
<<endl;
cout<<"→";
cin>>ch;
while(ch!='n'&&ch!='N'&&ch!='Y'&&ch!='y')//选择错误时判定
{
cout<<"→";
cin>>ch;
}
}while(ch=='y'||ch=='Y');
}
void consumer::savemoney()//存钱函数功能实现
{
char ch;
int c;
do
{
cout<<endl<<"请输入要存入的金额:"<<"¥>"<<endl ;
cin>>c;
while(c<=0)
{
cout<<"输入错误,请重新输入!"<<endl;
cout<<"→";
cin>>c;
}
money=money+c;
cq=c;
time_t t1 = time(0); //time_t是结构体,包含在time.h中,
strftime( TMP, sizeof(TMP), "%Y/%m/%d %X %A ",localtime(&t1) );
size_t strftime(char *strDest, size_t maxsize, const char *format, const struct tm *timeptr);
cout<<"操作已成功!"<<endl;
cout<<"是否要继续该项操作:(Y/N) "<<endl;
cout<<"→";
cin>>ch;
while(ch!='n'&&ch!='N'&&ch!='Y'&&ch!='y')
{
cout<<"→";
cin>>ch;
}
}while(ch=='y'||ch=='Y');
}
int YH::acnum=0;
void consumer::display()//用户信息界面
{system("cls");
cout<<"#####################################"<<endl;
cout<<endl;
cout<<" 用户姓名:"<<name<<endl;
cout<<endl;
cout<<" 帐号:"<<ID<<endl;
cout<<endl;
cout<<" 余额:"<<money<<endl;
cout<<endl;
cout<<" 身份证号:"<<idc<<endl;
cout<<endl;
cout<<" 电话号码:"<<pho<<endl;
cout<<endl;
cout<<" 按输入键进入操作界面 "<<endl;
cout<<endl;
cout<<"#####################################"<<endl;
cout<<"→";
}
void consumer::display1()
{system("cls");
cout<<"#####################################"<<endl;
cout<<endl;
cout<<" 1.存钱记录"<<endl;
cout<<endl;
cout<<endl;
cout<<" 2.取钱记录"<<endl;
cout<<endl;
cout<<endl;
cout<<" 3.转账记录"<<endl;
cout<<endl;
cout<<endl;
cout<<" 按输入键返回操作界面 "<<endl;
cout<<endl;
cout<<"#####################################"<<endl;
cout<<"→";
}
void consumer::display2()
{
do{system("cls");
if(cq<=0)
{
cout<<"#####################################"<<endl;
cout<<endl;
cout<<" 无存钱记录!"<<endl;
cout<<endl;
cout<<"#####################################"<<endl;
}
else
{
cout<<"#####################################"<<endl;
cout<<endl;
cout<<" 存钱记录:"<<endl;
cout<<endl;
cout<<" 您于"<<TMP<<"存入"<<cq<<"元!"<<endl;
cout<<endl;
cout<<" 按输入键返回操作界面 "<<endl;
cout<<endl;
cout<<"#####################################"<<endl;
}
}while(cin.get()=='/0');
}
void consumer::display3()
{do{system("cls");
if(qq<=0){
cout<<"#####################################"<<endl;
cout<<endl;
cout<<" 无取钱记录!"<<endl;
cout<<endl;
cout<<"##############################
展开阅读全文