银行储蓄管理系统

今天终于考完试了,这学期课程顺利结束,c++面向对象程序设计和数据结构课程设计都已经告一段落。c++课程设计也是我独自一个人第一次尝试着去写代码设计一个简单的系统,还是比较有成就感滴。今天就想跟大家分享一下我的c++课程设计,数据结构的课程设计代码因为不是我一个人写的,是团队一起写的就不分享了。当然,代码肯定有不足,欢迎各位大佬给我指出不足的地方,我也会慢慢去改正的。

#include<iostream>
#include<stdio.h>
#include<cstdlib>
#include<algorithm>
#include<string.h>
#include<fstream>
using namespace std;
typedef long long LL;
bool judge(char s[]){//判断输入的密码格式是否正确
    if(strlen(s)>6||strlen(s)<6)return false;
    for(int i=0;i<6;i++){
        if(s[i]<'0'||s[i]>'9')return false;
    }
    return true;
}
string zhuanhua(string u){//将调用系统的日期和时间修改一下格式
	string s;
	for(int i=0;i<u.length();i++){
		if(u[i]!=' ')s=s+u[i];
		else if(u[i]==' '&&u[i+1]==' ')continue;
		else if(u[i]==' '&&u[i+1]!=' ')s=s+'/';
	}
	return s;
}
void menu(){//主菜单
   cout<<endl;
   cout<<"\t******************欢迎使用储蓄管理系统*****************"<<endl;
   cout<<"\t+-----------------------------------------------------+"<<endl;
   cout<<"\t|                                                     |"<<endl;
   cout<<"\t|                                                     |"<<endl;
   cout<<"\t|                请选择您需要办理的业务               |"<<endl;
   cout<<"\t|                                                     |"<<endl;
   cout<<"\t|             1.开户               2.销户             |"<<endl;
   cout<<"\t|             3.存款               4.取款             |"<<endl;
   cout<<"\t|             5.查询余额           6.挂失             |"<<endl;
   cout<<"\t|             7.修改账户信息       8.转账             |"<<endl;
   cout<<"\t|             9.查询历史交易记录   10.退出            |"<<endl;
   cout<<"\t|                                                     |"<<endl;
   cout<<"\t+-----------------------------------------------------+"<<endl;
}
void menu1(){//子菜单
       cout<<endl;
       cout<<"\t=====================请选择您想要修改的信息========================"<<endl;
	   cout<<"\t*******************************************************************"<<endl;
	   cout<<"\t*                                                                 *"<<endl;
	   cout<<"\t*      (1)用户名 (2)密码 (3)身份证号码 (4)电话号码 (5)退出        *"<<endl;
	   cout<<"\t*                                                                 *"<<endl;
	   cout<<"\t*******************************************************************"<<endl;
}
void menu2(){//子菜单 
	cout<<endl;
	cout<<"\t################请选择您想要进行的操作################"<<endl;
	cout<<"\t******************************************************"<<endl;
	cout<<"\t*                                                    *"<<endl;
	cout<<"\t*             (1)挂失          (2)取消挂失            *"<<endl;
	cout<<"\t*                                                    *"<<endl;
	cout<<"\t******************************************************"<<endl;
}
class person{
   private:
       string number;//录入银行卡账号
       string name;//录入账户姓名
       char password[10];//录入账户密码
       double money;//记录卡内余额
       string telephone;//录入电话号码
       string shenfenzheng;//录入身份证号
       bool lost;//判断是否挂失
       string Name[1000];//记录每次历史交易的账户姓名
       string record[1000];//记录存款或者取款的时间
       double MONEY[1000];//记录每次存入或者取出的金额
       int v;//记录存款和取款的次数
       double remainder[1000];//记录每次取钱和存钱之后的余额
   public:
       person(){//初始化
         record[1000]={""};
         memset(MONEY,0,sizeof(MONEY));
         memset(remainder,0,sizeof(remainder));
         v=0;
       }
       void read1();
       void save1();
    person(string a,string b,char *c,double d,string t,string s){
        number=a;
        name=b;
        strcpy(password,c);
        money=d;
        telephone=t;
        shenfenzheng=s;
    }
    string getnumber(){
       return number;
    }
    string getname(){
       return name;
    }
    char *getpassword(){
       return password;
    }
    string gettelephone(){
       return telephone;
    }
    string getshenfenzheng(){
       return shenfenzheng;
    }
    double Getmoney(){//返回账户里面的余额
       return money;
    }
    void setname(string newname){
       name=newname;
    }
    void settelephone(string newtelephone){
       telephone=newtelephone;
    }
    void setpassword(char *newpassword){
       strcpy(password,newpassword);
    }
    void setshenfenzheng(string news){
        shenfenzheng=news;
    }
    void setlost(double flag){
       lost=flag;
    }
    void show(){
        read1();
       cout<<"储户账号:"<<number<<endl;
       cout<<"储户姓名:"<<name<<endl;
       cout<<"储户余额:"<<money<<endl;
       cout<<"储户电话号码:"<<telephone<<endl;
       cout<<"历史交易记录:"<<endl;
       int g=10001;
       for(int i=0;i<v;i++){
            if(Name[i]==name){
        cout<<"--------------------------编号:"<<g++<<"---------------------------"<<endl;
        cout<<endl;
        cout<<record[i]<<" "<<MONEY[i]<<"        余额:"<<remainder[i]<<endl;
        cout<<endl;
        cout<<"----------------------------------------------------------------"<<endl;
            }
       }
      // save1();
    }
    void deposit(double n){//存款
      read1();
      money+=n;
      string a=__DATE__;//调用系统当前的年月日
      string b=__TIME__;//调用系统当前的时间
      Name[v]=name;
      record[v]=record[v]+zhuanhua(a)+"/"+b+"存入金额:";
      MONEY[v]=n;
      remainder[v]=money;
      v++;
      save1();
    }
    void getmoney(double n){//取款
       read1();
       if(money<n)cout<<"账户余额不足"<<endl;
       else{
        money-=n;
        string a=__DATE__;//调用系统当前的年月日
        string b=__TIME__;//调用系统当前的时间
        Name[v]=name;
        cout<<"当前卡内余额为:"<<money<<endl;
        record[v]=record[v]+zhuanhua(a)+"/"+b+"取出金额:";
        MONEY[v]=n;
        remainder[v]=money;
        v++;
        save1();
       }
    }
    bool getlost(){
       return lost;
    }
};
class bank{
   private:
      LL sum;//记录已经开过户的人数
      person *account[1000];
   public:
    bank(){
       sum=0;//初始化
    }
    void read();
    void save();
    void create(){//实现开户功能
        read();
        string number1,name1;
        char password1[10],password2[10];
        double yuan;
        cout<<"请输入您的银行卡账号:";
        while(cin>>number1){
                int flag=0;
        for(int i=0;i<sum;i++){
            if(account[i]->getnumber()==number1){
                cout<<"该账户已存在,请重新输入"<<endl;
                flag=1;
                break;
            }
        }
        if(flag==0)break;
     }
     cout<<"请输入您的用户名:";
     cin>>name1;
     int mima=0;
     int flag2=0;
     string s1;
     cout<<"请输入您的身份证号码:";
     cin>>s1;
     string telephone1;
     cout<<"请输入您的电话号码:";
     cin>>telephone1;
     do{
    cout<<"请您设置一个六位只含数字的密码:";
     cin>>password1;
     cout<<"确认密码:";
     cin>>password2;
     if(!judge(password1)||!judge(password2)){
        cout<<"输入的密码格式有错误,请重新输入!"<<endl;
     }
    else if(strcmp(password1,password2)!=0){
        cout<<"两次输入的密码不一致,请重新输入!"<<endl;
     }
     else{
        cout<<"密码设置成功!"<<endl;
        flag2=1;
     }
     }while(flag2==0);
     char choice;
     cout<<"您是否要预存款?(如果需要预存款则输入1,否则输入0)"<<endl;
     while(cin>>choice){
        if(choice=='1'){
        cout<<"      存入金额:";
        cin>>yuan;
        break;
     }else if(choice=='0'){
       yuan=0;
       break;
     }else{
        cout<<"输入有误,请重新输入!"<<endl;
     }
     }
     person *s=new person(number1,name1,password2,yuan,telephone1,s1);//存储用户信息
     s->setlost(false);
     account[sum++]=s;
     cout<<"当前已有账户:"<<sum<<endl;
     cout<<"====================创建成功!===================="<<endl;
     save();
    }
    void Delete(){//注销账户
        read();
       string n;
       char m[10];
       cout<<"请输入您的账号:";
       cin>>n;
       cout<<"请输入密码:";
       cin>>m;
       int a;
       cout<<"请问您是否确认销户?(确认销户请按1,否则请按0)";
       cout<<endl;
       cin>>a;
       if(a==0)return;
       int flag=0;
       for(int i=0;i<sum;i++){
             if(account[i]->getnumber()==n&&strcmp(account[i]->getpassword(),m)==0){//如果是开过户的账号则进行销户操作
                flag=1;
                person *temp=account[i];//将该账户与最后一个账户交换
                account[i]=account[sum-1];
                account[sum-1]=temp;
                delete account[--sum];//删除账户后,sum的值减一
                break;
             }
       }
       if(flag==0){
        cout<<"账号或者密码错误!"<<endl;
       }
       else cout<<"销户成功!"<<endl;
       save();
    }
    void losting(){//挂失
        read();
        string id;
        cout<<"请输入您的账号:";
        cin>>id;
        char mima[10];
        cout<<"请输入您的密码:";
        cin>>mima;
        menu2();
        char choice;
        cout<<"请输入您想要进行的操作:";
        while(cin>>choice){
        	if(choice=='1'){
        		int a;
                 cout<<"请问您是否确认挂失?(确认挂失请按1,否则请按0)";
                 cout<<endl;
                 cin>>a;
                if(a==0)return;
                for(int i=0;i<sum;i++){
                  if(account[i]->getnumber()==id&&strcmp(account[i]->getpassword(),mima)==0){
                   account[i]->setlost(true);
                   cout<<"====================挂失成功!===================="<<endl;
                   save();
                   return;
               }
             }
            cout<<"账号或者密码错误!"<<endl;
            break;
            save();
			}
		   else if(choice=='2'){
		   	   int a;
                 cout<<"请问您是否确认取消挂失?(确认挂失请按1,否则请按0)";
                 cout<<endl;
                 cin>>a;
                if(a==0)return;
                for(int i=0;i<sum;i++){
                  if(account[i]->getnumber()==id&&strcmp(account[i]->getpassword(),mima)==0){
                   account[i]->setlost(false);
                   cout<<"====================取消挂失成功!===================="<<endl;
                   save();
                   return;
               }
             }
            cout<<"账号或者密码错误!"<<endl;
            break;
            save();
		   }else{
		   	cout<<"输入有误,请重新输入!"<<endl;
		   }	
		}
    }
    void give_money(){//存钱
        read();
    	double treasure;
    	string id;
    	char m[10];
    	cout<<"请输入您要存入的账户:";
		cin>>id;
		cout<<"请输入您的密码:";
		cin>>m;
		cout<<endl;
		cout<<"请输入您要存入的金额:";
		cin>>treasure;
		for(int i=0;i<sum;i++){
			if(account[i]->getnumber()==id&&strcmp(account[i]->getpassword(),m)==0&&!account[i]->getlost()){
				account[i]->deposit(treasure);
				cout<<"====================存款成功!===================="<<endl;
				save();
				return;
			}
		}
		cout<<"很抱歉,存款失败!"<<endl;//如果账号或者密码错误,则存钱失败
	}
	void get_money(){//取款
	    read();
		string id;
		cout<<"请输入您的账户:";
		cin>>id;
		char m[10];
		cout<<"请输入您的密码:";
		cin>>m;
		cout<<endl;
		double qian;
		cout<<"请输入您要取款的金额:";
		cin>>qian;
		for(int i=0;i<sum;i++){
			if(account[i]->getnumber()==id&&strcmp(account[i]->getpassword(),m)==0&&!account[i]->getlost())
			{
				account[i]->getmoney(qian);
				cout<<"====================取款成功!===================="<<endl;
				save();
				return;
			}
		}
		cout<<"很抱歉,取款失败!"<<endl;
	}
	void check(){//查询余额
        read();
		string id;
		cout<<"请输入您的账号:";
		cin>>id;
		char m[10];
		cout<<"请输入您的密码:";
		cin>>m;
		for(int i=0;i<sum;i++){
			if(account[i]->getnumber()==id&&strcmp(account[i]->getpassword(),m)==0){
				cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
				cout<<"储户账号:"<<account[i]->getnumber()<<endl;
				cout<<"储户姓名:"<<account[i]->getname()<<endl;
				cout<<"储户余额:"<<account[i]->Getmoney()<<endl;
				cout<<endl;
				cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
				return;
			}
		}
		cout<<"抱歉,没有查询到您的相关信息,请确认账号密码是否输入正确!"<<endl;
	}
	void change(){//修改账户信息
	    read();
	    string id;
	    cout<<"请输入您的账号:";
	    cin>>id;
	    char m[10];
	    cout<<"请输入您的账户密码:";
	    cin>>m;
	    bool flag=false;
	    int x=0;
	    for(int i=0;i<sum;i++){
            if(account[i]->getnumber()==id&&strcmp(account[i]->getpassword(),m)==0){
                flag=true;
                x=i;
                break;
            }
	    }
	    if(flag==false){
            cout<<"账号或者密码输入错误!"<<endl;
            return;
	    }
	    menu1();
	   int n;
	   while(cin>>n){
          if(n==1){
            string new_name;
            cout<<"请输入新的用户名:";
            cin>>new_name;
            account[x]->setname(new_name);
            cout<<"***************修改姓名成功!***************"<<endl;
          }else if(n==2){ 
             char FLAG[10]; 
             int flag2=0;
             do{
			 char new_m1[10];
             cout<<"请输入新的密码:";
             cin>>new_m1;
             char new_m2[10];
             cout<<"请确认新密码:";
             cin>>new_m2;
             strcpy(FLAG,new_m2);
             if(!judge(new_m1)||!judge(new_m2)){
                 cout<<"输入的密码格式有错误,请重新输入!"<<endl;
              }
             else if(strcmp(new_m1,new_m2)!=0){
                  cout<<"两次输入的密码不一致,请重新输入!"<<endl;
              }
             else{
               cout<<"密码设置成功!"<<endl;
               flag2=1;
              }
            }while(flag2==0);
            account[x]->setpassword(FLAG);
            cout<<"***************修改密码成功!***************"<<endl;
          }else if(n==3){
             string new_s;
             cout<<"请输入新的身份证号码:";
             cin>>new_s;
             account[x]->setshenfenzheng(new_s);
             cout<<"***************修改身份证号码成功!***************"<<endl;
          }else if(n==4){
             string new_telephone;
             cout<<"请输入新的电话号码:";
             cin>>new_telephone;
             account[x]->settelephone(new_telephone);
             cout<<"***************修改电话号码成功!***************"<<endl;
          }else{
              cout<<"储户账号:"<<account[x]->getnumber()<<endl;
              cout<<"储户密码:"<<account[x]->getpassword()<<endl;
              cout<<"储户姓名:"<<account[x]->getname()<<endl;
              cout<<"储户身份证号码:"<<account[x]->getshenfenzheng()<<endl;
              cout<<"储户电话号码:"<<account[x]->gettelephone()<<endl;
              cout<<"账户余额:"<<account[x]->Getmoney()<<endl;
           break;
         }
	   }
	   save();
	}
	void carry(){//转账
	    read();
	    string id1;
	    cout<<"请输入您的账号:";
	    cin>>id1;
	    char m[10];
	    cout<<"请输入您的密码:";
	    cin>>m;
	    string id2;
	    cout<<"请输入您要转入的账户:";
	    cin>>id2;
	    int x=0;
	    bool flag=false;
	    for(int i=0;i<sum;i++){
            if(account[i]->getnumber()==id2){
                x=i;
                flag=true;
                break;
            }
	    }
	    if(flag==false){
            cout<<"没有找到您想要转入账户的账号,请检查账号是否输入正确!"<<endl;
            return;
	    }
	    double money1;
	    cout<<"请输入您要转出的金额:";
	    cin>>money1;
	    for(int i=0;i<sum;i++){
            if(account[i]->getnumber()==id1&&strcmp(account[i]->getpassword(),m)==0&&!account[i]->getlost()&&!account[x]->getlost())
			{   
			    int X;
				cout<<"请您确认是否给卡号为:"<<id2<<"的账户转账,若是请输入1,否则输入0"<<endl;
				cin>>X;
				if(X==0)return;
				else{
					account[i]->getmoney(money1);
                    account[x]->deposit(money1);
				    cout<<"====================转账成功!===================="<<endl;
				    save();
				    return;
				}	
			}
	    }
	    cout<<"转账失败!"<<endl;
	}
	void RECORD(){//查询历史交易记录
	    read();
	    string id;
	    cout<<"请输入您的账号:";
	    cin>>id;
	    char m[10];
	    cout<<"请输入您的密码:";
	    cin>>m;
	    string Name;
	    cout<<"请输入您的用户名:";
	    cin>>Name;
	    for(int i=0;i<sum;i++){
            if(account[i]->getnumber()==id&&strcmp(account[i]->getpassword(),m)==0&&account[i]->getname()==Name&&!account[i]->getlost())
            {
                account[i]->show();
                save();
                return;
            }
	    }
	    cout<<"很抱歉,查询失败!"<<endl;
	}
};
void bank::read(){
   ifstream in("D:\\账户信息管理.txt",ios::in);
   if (!in)
	{
		//cerr<<"打开失败!"<<endl;
		return ;
	}
	string num,na;
	char m[10];
	double qian;
	string tel,shen;
	bool lo;
	LL i=0;
	while(in>>num>>na>>m>>qian>>tel>>shen>>lo){
        person *s=new person(num,na,m,qian,tel,shen);
        account[i]=s;
        account[i]->setlost(lo);
        i++;
	}
	sum=i;
	in.close();
}
void bank::save(){
    ofstream out("D:\\账户信息管理.txt",ios::out);//将账户信息保存至D盘中去
     if (!out)
	{
		cerr<<" 保存失败!"<<endl;
		return;
	}
	for(int i=0;i<sum;i++){
    out<<account[i]->getnumber()<<"\t";
    out<<account[i]->getname()<<"\t";
    out<<account[i]->getpassword()<<"\t";
    out<<account[i]->Getmoney()<<"\t";
    out<<account[i]->gettelephone()<<"\t";
    out<<account[i]->getshenfenzheng()<<"\t";
    out<<account[i]->getlost()<<endl;
	}
   out.close();
}
void person::read1(){
    ifstream in("D:\\账户历史交易记录管理.txt",ios::in);
   if (!in)
	{
		//cerr<<"打开失败!"<<endl;
		return ;
	}
	string new_Name;
	string re;
	double M;
	double rem;
	LL i=0;
	while(in>>new_Name){
       Name[i]=new_Name;
       in>>re;
       record[i]=re;
       in>>M>>rem;
       MONEY[i]=M;
       remainder[i]=rem;
        i++;
	}
	v=i;
	in.close();
}
void person::save1(){
    ofstream out("D:\\账户历史交易记录管理.txt",ios::out);//将账户信息保存至D盘中去
     if (!out)
	{
		cerr<<" 保存失败!"<<endl;
		return;
	}
	for(int i=0;i<v;i++){
    out<<Name[i]<<"\n"<<record[i]<<"\n"<<MONEY[i]<<"\n"<<remainder[i]<<endl;
	}
   out.close();
}
int main(){
   system("color b");
   menu();
   int x;
   bank a;
   while(cin>>x){
   	  switch(x){
   	  	case 1:
   	  		a.create();
   	  		system("pause");
   	  		break;
   	  	case 2:
   	  		a.Delete();
   	  		system("pause");
   	  		break;
   	  	case 3:
   	  		a.give_money();
   	  		system("pause");
   	  		break;
   	  	case 4:
   	  		a.get_money();
   	  		system("pause");
   	  		break;
   	  	case 5:
   	  		a.check();
   	  		system("pause");
   	  		break;
   	  	case 6:
   	  		a.losting();
   	  		system("pause");
   	  		break;
        case 7:
            a.change();
            system("pause");
            break;
        case 8:
            a.carry();
            system("pause");
            break;
        case 9:
            a.RECORD();
            system("pause");
            break;
   	  	case 10:
   	  		cout<<"*****************感谢您的使用,再见!*****************"<<endl;
   	  		system("pause");
   	  		return 0;
   	  	default:
   	  		cout<<"输入有误,请重新输入!"<<endl;
   	  		system("pause");
   	  		break;
		 }
		 system("cls");//清屏操作
         menu();
   }

   return 0;
}
  • 7
    点赞
  • 37
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值