❶ C語言或C++ 銀行卡管理系統
#include<iostream>
#include<cstring>
using namespace std;
class count
{
public:
friend class ATM;
count (char Name[],char Num[],float Money,char Password[]); //初始化
protected:
char * get_name(); //返回姓名
char * get_num(); //返回卡號
char * get_password(); //返回密碼
float get_money(); //返回金額
void set_password(char pwd[]); //設置密碼
void set_money(float m); //取錢
private:
char password[6]; //用戶密碼
char name[20]; //用戶姓名
char num[20];
float money;
};
class ATM
{
public:
ATM(count & cn):ctm(cn){}
void welcome(); //登陸界面
bool check_password(char p[],char pwd[]); //核對密碼
void change_password(); //修改密碼
void get_money(); //取錢
void get_information(); //查詢信息
void exit_ATM(); //退出ATM
void show_function(); //功能界面
void push_card(); //吞卡
private:
int times; //記錄輸入密碼的次數
count & ctm;
};
//構造ATM的函數
void ATM::welcome() //構造welcome
{
times=0;
cout<<"歡迎使用ATM模擬自動取款機"<<endl;
cout<<"-------------------------"<<endl;
cout<<"請選擇:\n1.新開帳戶\t2.客戶服務\t3.退出系統"<<endl; //輸出主菜單
char pwd[7],num[20]; //6位密碼19位卡號
int i=0;
do
{
cout<<"請輸入卡號";
cin>>num;
cout<<"請輸入密碼:";
cin>>pwd;
if(!check_password(num,pwd))
{
cout<<"你輸入的密碼有錯誤,請重新輸入"<<endl;
times++;
}
else
{
show_function();
}
}while(times<3);
push_card();
}
bool ATM::check_password(char num[],char pwd[]) //構造核對密碼
{
if(strcmp(num,ctm.get_num())==0&&strcmp(pwd,ctm.get_password())==0)
return true;
else
return false;
exit(0);
}
void ATM::show_function() //構造功能界面
{
int n;
do
{
cout<<"1)修改密碼"<<endl;
cout<<"2)取款"<<endl;
cout<<"3)查詢余額"<<endl;
cout<<"4)退出系統"<<endl;
cout<<"請選擇相關功能的代號:";
cin>>n;
while(n<1&&n>>4)
{
cout<<"請輸入正確的操作序號!"<<endl;
cout<<"請選擇相關功能的代號:";
cin>>n;
}
switch(n)
{
case 1:change_password(); break;
case 2:get_money(); break;
case 3:get_information(); break;
case 4:exit_ATM(); break;
}
}while(true);
}
void ATM::change_password() //構造修改密碼
{
char pwd[7],repwd[7];
times=0;
do
{
cout<<"請輸入原密碼:";
cin>>pwd;
//if(!check_password(ctm.get_password(),pwd))
if(!check_password(ctm.get_num(),pwd))
times++;
else
break;
}while(times<2);
if(times==2)
push_card();
int m=0;
do
{
cout<<"請輸入新密碼:";
cin>>pwd;
cout<<"請再輸入一次新密碼:";
cin>>repwd;
if((m=strcmp(pwd,repwd))!=0)
cout<<"你輸入的兩次密碼不一樣,請重新輸入!";
}while(m!=0);
ctm.set_password(pwd);
cout<<"密碼修改成功,請牢記新密碼!"<<endl;
}
void ATM::get_money() //構造取錢
{
float m;
char ch;
do
{
cout<<"請輸入所取金額:";
cin>>m;
while(m<=0)
{
cout<<"請輸入正確的數字!"<<endl;
cin>>m;
}
if(ctm.get_money()-m<0)
{
cout<<"對不起,你的余額不足!"<<endl;
}
else
{
ctm.set_money(m);
cout<<"是否要繼續(Y/N):";
cin>>ch;
while(ch!='n'&&ch!='N'&&ch!='y'&&ch!='Y')
{
cout<<"請根據提示輸入正確命令!"<<endl;
cout<<"是否要取出所選金額(Y/N)";
cin>>ch;
}
}
}while(ch=='y'||ch=='Y');
}
void ATM::get_information() //構造查詢信息
{
cout<<"********************"<<endl;
cout<<"用戶姓名:"<<ctm.get_name()<<endl;
cout<<"卡號:"<<ctm.get_num()<<endl;
cout<<"余額:"<<ctm.get_money()<<endl;
cout<<"********************"<<endl;
}
void ATM::push_card() //構造吞卡
{
cout<<"由於你的不當操作,你的的卡已經被沒收。"<<endl;
cout<<"請您持相關證件到當地營業廳辦理相關手續。"<<endl;
exit(1);
}
void ATM::exit_ATM() //構造退出ATM
{
cout<<"歡迎下次光臨!"<<endl;
cout<<"請取卡... ..."<<endl;
exit(0);
}
count ::count (char Name[],char Num[],float Money,char Password[]) //構造初始化
{
strcpy(name,Name);
strcpy(num,Num);
money=Money;
strcpy(password,Password);
}
float count ::get_money() //構造返回金額
{
return money;
}
char *count ::get_name() //構造返回用戶名
{
return name;
}
char *count ::get_num() //構造返回卡號
{
return num;
}
char *count ::get_password() //構造返密碼
{
return password;
}
void count ::set_password(char pwd[]) //構造修改密碼
{
strcpy(password,pwd);
}
void count ::set_money(float m)
{
money-=m;
}
int main() //主函數
{
count ctm("mianchuang","0001",1000000,"123"); //創建對象 調用初始化
ATM atm(ctm);
atm.welcome(); //主程序調用開始
}
不知道能不能滿足你的要求