c++ 银行管理系统及报告

     1.题目描写叙述:

  本代码为银行管理系统,总体分为管理员模式和普通用户模式:

1)在管理员模式中能完毕

①用户信息录入

②改动管理员password

③改动指定账户信息

④信息管理业务

2)在普通用户模式下,能完毕注冊和转账

在注冊中用户必须输入必要的注冊信息

在登录功能中将须要password,登陆成功厚能实现

①存款  ②取款   ③转账  ④查询剩余金额  ⑤改动个人信息(账号、username、password、身份证号、电话)  ⑥显示账户信息

 

2.分析思路

1)本银行管理系统下总体通过类来完毕,以实现更好的封装性。每个类对象即为一个独立的账户,在此对象中含有该账号的所有注冊信息。

2)使用链表动态开辟对象空间,以节省空间。

3)将每一个功能独立化。将其设置为单一函数如选择模式函数、注冊函数、存款函数、取款函数、转账函数、改动信息函数、显示账户信息函数、显示剩余金额函数。

4)在设计函数时,将用户的全部误操作进行考虑,即使是用户存在误操作。也会人性化的给予提示,提醒用户再次输入正确操作,使程序更加完整、全面和人性化。

详细功能及结构例如以下所看到的:

3.输入:

  依据操作指示输入123等序号以完毕选择所需业务

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;
}

 





 

posted on 2017-07-12 18:23  wgwyanfs  阅读(304)  评论(0编辑  收藏  举报

导航