❶ 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(); //主程序调用开始
}
不知道能不能满足你的要求