1.題目描寫敘述:
本代碼為銀行管理系統,總體分為管理員模式和普通用戶模式:
(1)在管理員模式中能完畢
①用戶信息錄入
②改動管理員password
③改動指定賬戶信息
④信息管理業務
(2)在普通用戶模式下,能完畢注冊和轉賬
在注冊中用戶必須輸入必要的注冊信息
在登錄功能中將須要password,登陸成功厚能實現
①存款 ②取款 ③轉賬 ④查詢剩余金額 ⑤改動個人信息(賬號、username、password、身份證號、電話) ⑥顯示賬戶信息
2.分析思路
(1)本銀行管理系統下總體通過類來完畢。以實現更好的封裝性。每個類對象即為一個獨立的賬戶。在此對象中含有該賬號的所有注冊信息。
(2)使用鏈表動態開辟對象空間。以節省空間。
(3)將每一個功能獨立化。將其設置為單一函數如選擇模式函數、注冊函數、存款函數、取款函數、轉賬函數、改動信息函數、顯示賬戶信息函數、顯示剩余金額函數。
(4)在設計函數時。將用戶的全部誤操作進行考慮,即使是用戶存在誤操作,也會人性化的給予提示,提醒用戶再次輸入正確操作,使程序更加完整、全面和人性化。
詳細功能及結構例如以下所看到的:
3.輸入:
依據操作指示輸入1、2、3等序號以完畢選擇所需業務
4.輸出:
輸出引導用戶的提示以及客戶所要查詢的信息
#include<iostream>
#include<string>
using namespace std;
//bool manbermark=0;//標記是否有注冊成員
string loginmarknumber ;//記錄登錄時還沒有一個注冊的,注冊時的賬號
class information
{
public :
string num ;//賬號
string name;//username
string key;//password
string ID;//身份證號
string tel;//電話號碼
double money;//剩余金額
information *next;//記錄下一空間地址
};
int cheak_num(string str,information *head)//檢查賬號是否存在
{
int t=0;//記錄該賬號是否存在
information * p=head;
if(head==NULL)
t=0;
else
{
while(p->next!=NULL)//對已有賬號進行遍歷
{
if(p->num!=str)
p=p->next;
else
{t=1;
break;
}
}
if(t==0)
if(p->num==str)
t=1;
}
return t;//若賬號已經存在則返回1。否則返回0
}
information * get_information (information *head)//管理員錄入信息
{
information *s,*p;
s=new information;
cout<<"請錄入信息:"<<endl;
cout<<"賬號:";
cin>>s->num;
cout<<"username:";
cin>>s->name;
cout<<"password:";
cin>>s->key;
cout<<"身份證號:";
cin>>s->ID;
cout<<"電話號碼:";
cin>>s->tel;
cout<<"剩余金額:";
cin>>s->money;
cout<<endl<<"====================================信息錄入成功==============================="<<endl;
while ( 1 )
{
char ch;
if( head==NULL )
{
head = s ;
//head->next=NULL;//頭指針賦值
}
else
p->next = s ; //將新結點插入已有鏈表的最后
cout<<"是否繼續錄入信息 是(1),(2)否"<<endl;
cin>>ch;
while(ch!='1' && ch!='2'){
cout<<"請又一次輸入是否繼續錄入 是(1) 否(2)";
cin>>ch;
}
if(ch=='1'){
//選擇“是?
p = s ;// p指向鏈表中最后的結點
p->next=NULL;
s=new information;
s->next=NULL;
cout<<"請輸入注冊信息:"<<endl;
cout<<"賬號:";
string str111;
cin>>str111;
int t;
t=cheak_num(str111,head);
while(t==1) //對已有賬號進行推斷 。直到新注冊賬號不存在為止
{
cout<<"賬號已存在。請又一次注冊:";
cin>>str111;
t=cheak_num(str111,head);
}
s->num=str111;
cout<<"username:";
cin>>s->name;
cout<<"password:";
cin>>s->key;
cout<<"身份證號:";
cin>>s->ID;
cout<<"電話號碼:";
cin>>s->tel;
cout<<"剩余金額:";
cin>>s->money;
cout<<endl;
}
else//選擇“否”
{
s->next=NULL;
break;
}
cout<<endl<<"====================================信息錄入成功==============================="<<endl;
}
return head;
}
void output_information (information *head)//顯示全部賬號信息
{
if(head==NULL){
cout<<"暫無注冊信息";
return ;
}
int i=1;
information *s;
s=head;
while(s->next!=NULL)
{
cout<<"用戶注冊編碼:"<<i<<endl;
cout<<"賬號:"<<s->num<<endl;
cout<<"username: "<<s->name<<endl;
cout<<"password:"<<s->key<<endl;
cout<<"身份證號:"<<s->ID<<endl;
cout<<"電話:"<<s->tel<<endl;
cout<<"金額:"<<s->money<<endl<<endl;
s=s->next;
i++;
}
cout<<"用戶注冊編碼:"<<i<<endl;
cout<<"賬號:"<<s->num<<endl;
cout<<"username: "<<s->name<<endl;
cout<<"password:"<<s->key<<endl;
cout<<"身份證號:"<<s->ID<<endl;
cout<<"電話:"<<s->tel<<endl;
cout<<"金額:"<<s->money<<endl;
}
int check_keys(string number,string keys,information *head)//檢查賬號是否存在且password是否正確
{
int t=0;
information *p=head;
while(p->next!=NULL)
{
if(p->num!=number)
p=p->next;
else
{
if(p->key==keys)
{t=3;//賬號存在且password正確
break;
}
else
{t=2;//賬號存在可是password不對
break;
}
}
}
if(t==0)
if(p->num==number)
if(p->key==keys)
t=3;//賬號存在且password正確
else
t=2;//賬號存在可是password不對
return t;
}
void take_money(information * p)//取錢函數
{
double m;
cout<<"請輸入提款金額:";
cin>>m;
if(m<=p->money)//推斷是否超過賬號剩余金額
{ p->money=p->money-m;
cout<<"取款成功"<<endl;
}
else
{
while(m>p->money)//若取錢金額超過賬戶剩余金額
{cout<<"剩余金額不足。請又一次操作"<<endl;
cout<<"請輸入提款金額:";
cin>>m;
}
p->money=p->money-m;//對取現后的剩余金額進行改動
cout<<endl<<"======================================取款成功=================================="<<endl;
}
}
void save_money(information *p)//存錢函數
{
double m;
cout<<"請輸入存款金額:";
cin>>m;
p->money=p->money+m;//對所存入的賬戶剩余金額改動
cout<<endl<<"======================================存款成功=================================="<<endl;
}
information*cheak_number(string number,information *head)//在管理員模式下或者是客戶在正確輸入password后查找客戶信息
{
int a=0 ;//標記賬戶是否存在
information *p=head;
while(p->next!=NULL)
{
if(p->num==number)
{ a=1;
break;
}
else
p=p->next;
}
if(p->num==number)
a=1;
if(a==0)
p=NULL;
return p;//返回所查找的客戶地址信息
}
void move_money(information *p,information *head)// 轉賬函數 p是正在登陸的賬號地址
{
information *x;//記錄所轉賬號地址
x=NULL ;
double m;//轉賬金額
string str;//轉賬賬號
char ch ;//記錄用戶輸入的是否繼續轉賬決定
cout<<"請輸入要轉賬的賬號:";
cin>>str;
x=cheak_number(str,head);//記錄下了所轉賬好的地址
while(x==NULL)//假設賬戶不存在
{
x=cheak_number(str,head);//記錄下了所轉賬好的地址
cout<<"賬號不存在,是否又一次操作:(1)是 (2)否"<<endl;
cin>>ch;
if(ch=='1')
{
cout<<"請又一次輸入要轉賬的賬戶:";
cin>>str;
x=cheak_number(str,head);//記錄下了所轉賬好的地址
}
else
break;
}
if(x!=NULL)//假設賬戶存在
{
cout<<"請輸入轉賬金額:";
cin>>m;
while(p->money<m)
{cout<<"剩余金額不足,請又一次輸入轉賬金額:"<<endl;
cin>>m;
}
x->money=x->money+m ;
p->money=p->money-m;
cout<<endl<<"=====================================轉賬成功================================"<<endl;
}
}
void revise_information(information *p)//"改動信息"
{
string str,str1;//記錄用戶賬號信息
char ch;//記錄用戶決定
while(1)
{
cout<<"請選擇要改動的信息 (1)賬號 (2)username (3)password (4)身份證號 (5)電話 (6)退出改動當前賬戶信息 ";
cin>>ch;
while(ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5'&&ch!='6')//用戶若輸入業務已有誤
{
cout<<"請又一次輸入有效的業務:";
cin>>ch;
}
if( ch=='1')//改動賬號
{
cout<<"請輸入新賬號:";
cin>>str;
p->num=str;
cout<<endl<<"====================================改動賬號成功================================"<<endl;
}
else
if( ch=='2')//改動username
{
cout<<"請輸入新的username:";
cin>>str;
p->name=str;
cout<<endl<<"===================================改動username成功=============================="<<endl;
}
else
if( ch=='3')//改動password
{
cout<<"請輸入原password:";
cin>>str;
while(p->key!=str)
{
cout<<"與原password不一致,請又一次輸入原password:";
cin>>str;
}
cout<<"請輸入新password:";
cin>>str;
cout<<"請確認password:";
cin>>str1;
while(str!=str1)
{
cout<<"與第一次輸入不同,請又一次設定:";
cout<<"請輸入新password:";
cin>>str;
cout<<"請確認password:";
cin>>str1;
}
cout<<endl<<"===============================設定成功,請記好新password=========================="<<endl;
}
else
if( ch=='4')//改動身份證號
{
cout<<"請輸入新身份證號:";
cin>>str;
p->ID=str;
cout<<endl<<"==================================改動身份證成功==============================="<<endl;
}
else
if( ch=='5')//改動電話號碼
{
cout<<"請輸入新電話號碼:";
cin>>str;
p->tel=str;
cout<<endl<<"==================================電話號碼改動成功============================="<<endl;
}
else
break;//退出改動賬戶信息
}
}
void show_information(information*p)//顯示當前賬戶信息
{
cout<<"賬號:"<<p->num<<endl;
cout<<"username:"<<p->name<<endl;
cout<<"password:"<<p->key<<endl;
cout<<"身份證號:"<<p->ID<<endl;
cout<<"電話:"<<p->tel<<endl;
cout<<"金額:"<<p->money<<endl;
}
void query_money(information *p)//顯示當前賬戶剩余金額
{
cout<<"您的剩余金額為:";
cout<<p->money<<endl;
}
information* logon(information *head)//用戶注冊賬號
{
information *s;
string str;//記錄賬號信息
cout<<"請輸入注冊賬號:";
cin>>str;
int t;
if(head==NULL)//假設鏈表不存在信息,默覺得新注冊的賬號不存在
t=0;
else
t=cheak_num(str,head);//推斷賬號是否已經存在
while(t==1)//賬號已經存在 又一次輸入
{
cout<<"賬號已存在。請又一次注冊:";
cin>>str;
t=cheak_num(str,head);
}
s=new information ;//為鏈表開辟新空間
s->num=str;
if(head==NULL)
loginmarknumber=str;
cout<<"username:";
cin>>s->name;
cout<<"password:";
cin>>s->key;
cout<<"身份證號:";
cin>>s->ID;
cout<<"電話號碼:";
cin>>s->tel;
cout<<"剩余金額:";
cin>>s->money;
if(head==NULL)//假設當前鏈表沒有不論什么信息
{
head=s;
head->next=NULL;
}
else//將新注冊的插入當前鏈表
{
s->next=head->next;
head->next=s;
}
cout<<endl<<"=====================================注冊成功==================================="<<endl;
return head;
}
information * choose(information *head)//普通用戶登陸賬號以及選擇須要的業務
{
int t,loginmark=0;
if(head==NULL){//還沒有注冊賬號
cout<<endl<<"未有賬戶注冊,無法完畢登陸功能。請先注冊賬戶信息"<<endl<<"是否如今注冊:(1)是,(2)稍后注冊"<<endl;
int x;
cin>>x;
while(x!=1&&x!=2){
cout<<"請又一次選擇:";
cin>>x;
}
if(x==1){
head=logon(head);
loginmark=1;
}
else
return head ;
}
information *p;//p是用來記錄所查找到的賬號的地址的
string number,keys;//number 記錄登陸賬號 keys記錄賬password
if(loginmark==0){
cout<<"請輸入賬號:";
cin>>number;
cout<<"請輸入賬號password:";
cin>>keys;
t=check_keys(number,keys,head); //t是用來記錄是否存在賬號以及password是否正確的。若賬號不存在則返回0,若賬號password錯誤返回2,賬號存在且password正確時返回3
while(t==0||t==2)//假設賬號不存在或者是password輸入錯誤
{
if(t==2)//用戶輸入password有誤
{cout<<"password輸入錯誤,請又一次輸入賬號及password";
cout<<"賬號:";
}
else//賬號不存在
cout<<"賬號不存在。請又一次輸入賬號及password,賬號:";
cin>>number;
cout<<"password:";
cin>>keys;
t=check_keys(number,keys,head);//調用推斷password 賬號是否正確
}
}
else
number=loginmarknumber;
cout<<endl<<"==================================普通用戶登陸成功=============================="<<endl<<endl;
cout<<"請選擇業務:(1)取錢 (2)存錢 (3)轉賬 (4)改動信息 (5)剩余金額查詢 (6)顯示賬號信息 (7)退出賬號"<<endl;
p=cheak_number(number,head); //記錄所登陸的賬號地址
char ch; //記錄用戶所做的選擇
cin>>ch;
while(1)
{
while(ch!='1'&&ch!='2'&&ch!='3'&&ch!='4'&&ch!='5'&&ch!='6'&&ch!='7')//用戶若出入業務有誤
{cout<<"請又一次輸入所需業務:(1)取錢 (2)存錢 (3)轉賬 (4)改動信息 (5)剩余金額查詢 (6)顯示賬號信息 (7)退出賬號"<<endl;
cin>>ch; //又一次輸入業務
}
if(ch=='7') //退出當前賬戶
break;
else
{
switch(ch)
{
case '1':take_money(p);break; //取錢
case '2':save_money(p);break; //存錢
case '3':move_money(p,head);break; //轉賬
case '4':revise_information(p);break; //改動信息
case '5':query_money(p);break; //查詢剩余金額
case '6':show_information(p);break; //查看信息
}
cout<<"請選擇業務:(1)取錢 (2)存錢 (3)轉賬 (4)改動信息 (5)剩余金額查詢 (6)顯示賬號信息 (7)退出賬號"<<endl;
cin>>ch;
}
}
return head;
}
string change_monitor_keys(string monitor)
{
string string1,string2;//記錄用戶兩次輸入password
cout<<"請輸入原password:";
cin>>string1;
while(string1!=monitor)//假設管理員password輸入不對
{
cout<<"與原password不符,是否又一次輸入 (1)是 (2) 否 "<<endl;
char chra;
cin>>chra;//記錄用戶是否繼續登陸
while(chra!='1'&&chra!='2')//推斷用戶是否存在誤操作
{
cout<<"選擇有誤,請又一次選擇:(1)是 (2) 否 "<<endl;
cin>>chra;
}
if(chra=='1')//繼續登陸輸入賬號
{
cout<<"請再次輸入原password:";
cin>>string1;
}
else{//停止登陸
cout<<endl<<"==================================password未改動===================================="<<endl;
break;
}
}
if(string1!=monitor)//退出改動管理員password
return monitor;
cout<<"請輸入新password:";
cin>>string1;
cout<<"請再次輸入確認改動password:";
cin>>string2;
while(string1!=string2)//推斷兩次輸入的新password是否一致
{
cout<<"兩次輸入password不同樣,請選擇是否繼續改動:(1)是 (2)否"<<endl;
char jilu;//記錄用戶選擇是否繼續改動
cin>>jilu;
while(jilu!='1'&&jilu!='2')//推斷用戶是否存在誤操作,是則提示
{
cout<<"請重修選擇是否改動:(1)是 (2)否"<<endl;
cin>>jilu;
}
if(jilu=='1')//繼續改動password
{
cout<<"請輸入新password:";
cin>>string1;
cout<<"請再次輸入確認改動password:";
cin>>string2;
}
else{//退出改動password
break;
}
}
if(string2==string1)//假設在兩次輸入改動password一致,成功改動
{
monitor=string1;
cout<<endl<<"====================================password改動成功==============================="<<endl;
}
else
cout<<endl<<"==================================password未改動=============================="<<endl;
return monitor;
}
void choose_model(information *head,string monitor)//選擇開始界面業務
{
information *p;
char ch,mon_cho;//記錄用戶選擇
string str;//后面用到的是管理員password 客戶賬號
cout<<"==============================歡迎進入銀行管理系統=============================="<<endl;
while(1)
{
cout<<"請選擇進入模式:"<<endl;
cout<<"(1)管理員模式 (2)普通用戶模式 (3)退出系統 "<<endl;
cin>>ch;
while(ch!='1'&&ch!='2'&&ch!='3')//假設用戶輸入有誤。提示
{ cout<<"請選擇進入模式:"<<endl;
cout<<"(1)管理員模式 (2)普通用戶模式 (3)退出系統 "<<endl;
cin>>ch;
}
if(ch=='1')//管理員模式
{
cout<<"您已進入管理員模式"<<endl<<"請輸入管理員password:";
cin>>str;
if(monitor!=str)
{
char judge;//用來記錄選擇
while(monitor!=str)//推斷管理員password是否正確
{
cout<<"管理員password輸入錯誤,是否又一次輸入 (1)是 (2)否"<<endl;//此處考慮到可能是客戶不小心進入能夠選擇退出管理員模式
cin>>judge;
while(judge!='1'&&judge!='2')//假設用戶輸入有誤,提示
{
cout<<"請又一次選擇是否又一次輸入password (1)是 (2)否"<<endl;
}
if(judge=='1')//繼續輸入password
{
cout<<"請又一次輸入管理員password:";
cin>>str;//又一次輸入管理員password
}
else
{break;//結束本輸入password循環
}
}
}
if(monitor==str)//成功登陸管理員
{
cout<<endl<<"==================================管理員登陸成功==============================="<<endl;
while(1)
{
cout<<endl<<endl<<"請輸入要運行的操作"<<endl;
cout<<"(1)客戶信息錄入 (2)管理客戶信息 (3)改動管理員password (4)顯示全部賬戶信息 (5)退出管理員模式"<<endl;
cin>>mon_cho;//記錄用戶選擇
while(mon_cho!='1'&&mon_cho!='2'&&mon_cho!='3'&&mon_cho!='4'&&mon_cho!='5')//假設用戶輸入有誤,提示
{
cout<<endl<<endl<<"請又一次選擇模式"<<endl;
cout<<"(1)客戶信息錄入 (2)管理客戶信息 (3)改動管理員password (4)顯示全部賬戶信息 (5)退出管理員模式"<<endl;
cin>>mon_cho;
}
if(mon_cho=='1')//客戶信息錄入
head=get_information(head);
else
if(mon_cho=='2')//管理賬戶信息
{
if(head==NULL){
cout<<"對不起,因為暫無賬戶注冊信息,該操作無法運行"<<endl;
continue;
}
cout<<"請輸入要改動的客戶賬號:";
cin>>str;
p=cheak_number(str,head);//推斷賬戶是否存在
while(p==NULL)//賬戶不存在。提示又一次輸入
{
cout<<"該賬號不存在,請又一次輸入:";
cin>>str;
p=cheak_number(str,head);
}
revise_information(p);//改動已存在的賬戶信息
}
else
if(mon_cho=='5')//結束管理員模式
break;
else
if(mon_cho=='4')//輸出全部賬戶信息
output_information (head);
else//改動管理員password
monitor=change_monitor_keys(monitor);
}
}
}
else
if(ch=='2')//選擇普通客戶模式
{
char jilu;//記錄用戶所選業務
cout<<"==============================歡迎進入銀行管理系統=============================="<<endl;
while(1)
{
cout<<"請選擇須要業務:(1) 注冊 (2) 登錄 (3)退出普通用戶模式 "<<endl;
cin>>jilu;
while(jilu!='1'&&jilu!='2'&&jilu!='3')//推斷用戶誤操作,提示
{
cout<<"輸入錯誤。請又一次選擇業務::(1) 注冊 (2) 登錄 (3)退出普通用戶模式 "<<endl;
cin>>jilu;
}
if(jilu=='1')//注冊
head=logon(head);
else
if(jilu=='2')//登陸
head=choose(head);
else
break;//退出普通用戶模式
}
}
else //退出該系統
break;
}
}
int main ()
{ information *head=NULL;
string monitor="123";//monitor為管理員初始password
choose_model(head,monitor);
return 0;
}
