#include
#include
#include
#include
#include
#include
#include
#include
#define account0 7116620100000254000 //第一个开户的卡号
#define random(a,b) (rand()%(b-a+1)+a)
using namespace std;
int number=0;
class ATM;
class depositcard;
class creditcard;
class account
{
public:
account()
{
id="0",name="0",sex="0",address="0",tele="0",shenfen="0",password="0",money=0; //默认构造函数
}
account(string i,string n,string se,string a,string t,string s,string p,double m) //带参数构造函数
{
id=i,name=n,sex=se,address=a,tele=t,shenfen=s,password=p,money=m;
}
string getid()
{
return id;
}
void display(); //用户信息界面
void querymoney(); //余额查询
protected:
string id,name,address,tele,shenfen,password,sex;
double money;
};
class ATM
{
public:
void setdeposit(); //储存卡开户
void setcredit(); //信用卡开户
void enterdeposit(); //储存卡登录
void entercredit(); //信用卡登录
void delaccount(); //销户
void exitatm(); //退出
void dsave(); //储蓄卡类导入磁盘文件
void csave(); //信用卡类导入磁盘文件
void dread(); //储蓄卡信息从磁盘文件导出
void cread(); //信用卡信息从磁盘文件导出
string inputpassword(); //设置账户的密码
bool checkshen(string str); //检查身份证是否合格
void menu(); //功能菜单
protected:
depositcard *deposit[50]; //定义多个储存卡对象
creditcard *credit[50]; //定义多个信用卡对象
static int depositcount,creditcount;
};
class depositcard:public account ,public ATM //账户派生类:储蓄卡
{
public:
friend class ATM;
depositcard(string i,string n,string se,string a,string t,string s,string p,double m):account(i,n,se,a,t,s,p,m) {}
void save(); //存钱功能
void fetch(); //取钱功能
void lixi(); //利息计算
string getp()
{
return password;
}
};
class creditcard:public account ,public ATM //账户派生类:信用卡
{
public:
friend class ATM;
creditcard(string i,string n,string se,string a,string t,string s,string p,double m,double tou,double tm):
account(i,n,se,a,t,s,p,m),touzhi(tou),tmax(tm) {}
void save(); //存钱功能
void fetch(); //取钱功能
void lixi(); //利息计算
void toumoney(); //每月要透支的钱
void show();
string getp()
{
return password;
}
string getid()
{
return id;
}
double gettouzhi();
double gettmax();
void add(double x);
private:
double touzhi; //透支额度
double tmax;
};
void creditcard::show()
{
cout<<"透支余额:"<id<<" ";//把信息写入磁盘文件bankdat.dat
outfile<money<<" ";
outfile<name<<" ";
outfile<password<<" ";
outfile<shenfen<<" ";
outfile<tele<<" ";
outfile<address<<" ";
outfile<sex<<" ";
}
outfile.close();
}
void ATM::dread()
{
int n;
string id,sex;
string nam,passw,tele;
double money;
string shenfen;
string address;
ifstream infile("deposit.txt",ios::in); //以输入方式打开文件
infile>>depositcount;
if(!infile)
{
cerr<<"Error reading, no data!"<>id;
infile>>money;
infile>>nam;
infile>>passw;
infile>>shenfen;
infile>>tele;
infile>>address;
infile>>sex;
depositcard * acc = new depositcard(id,nam,sex,address,tele,shenfen,passw,money); //每读入一个n开辟一段内存
deposit[n] = acc; //赋值首地址
}
infile.close();
cout<<"Normal reading !"<id<<" ";//把信息写入磁盘文件bankdat.dat
outfile<money<<" ";
outfile<name<<" ";
outfile<password<<" ";
outfile<shenfen<<" ";
outfile<tele<<" ";
outfile<address<<" ";
outfile<sex<<" ";
outfile<touzhi<<" ";
outfile<tmax<<" ";
}
outfile.close();
}
void ATM::cread()
{
int n;
string id,sex;
string nam,passw,tele;
double money,touzhi,tmax;
string shenfen;
string address;
ifstream infile("deposit.txt",ios::in); //以输入方式打开文件
infile>>depositcount;
if(!infile)
{
cerr<<"Error reading, no data!"<>id;
infile>>money;
infile>>nam;
infile>>passw;
infile>>shenfen;
infile>>tele;
infile>>address;
infile>>sex;
infile>>touzhi;
infile>>tmax;
creditcard * acc = new creditcard(id,nam,sex,address,tele,shenfen,passw,money,touzhi,tmax); //每读入一个n开辟一段内存
credit[n] = acc; //赋值首地址
}
infile.close();
cout<<"Normal reading !"< '9')
{
if (i == 17 && str[i] != 'x' && str[i] != 'X')
{
return false;
}
else if (i != 17)
{
return false;
}
else
return false;
}
}
}
return true;
}
void ATM::exitatm()
{
cout<<"感谢您使用ATM存取一体机,欢迎再来!"<>u;
while(u<1||u>7)
{
cout<<"请合法输入!"<>u;
}
system("cls");
switch(u)
{
case 1:
setdeposit();
//创建储蓄卡账户
break;
case 2:
enterdeposit();
break; //储蓄卡登录
case 3:
setcredit();
break; //创建信用卡账户
case 4:
entercredit();
break; //信用卡登录
case 5:
delaccount();
break; //账户注销*/
case 6:
exitatm();
break; //退出
}
}
while(1);
system("cls");
}
void ATM::setdeposit() //创建账户
{
srand((unsigned)time(NULL));
string i,n,a,t,s,se,p;
double m;
int find=1;
cin.get();
cout<<"请输入姓名:"<>se;
cin.get();
cout<<"请输入地址:"<>t;
while(1)
{
cout<<"请输入身份证号:"<>s;
if(!checkshen(s))
{
cout<<"不合法输入!"<>m;
while(m<=0)
{
cout<<"请合法输入金额:"<>m;
}
cin.get();
unsigned long long acc = account0 + random(1,100)+number;
number++;
cout<<"开户成功!"<> i;
deposit[depositcount]=new depositcard(i,n,se,a,t,s,p,m); //把新建账户对象地址传过去
++depositcount;
dsave();
cout<<"请按任意键继续!"<>se;
cin.get();
cout<<"请输入地址:"<>t;
while(1)
{
cout<<"请输入身份证号:"<>s;
if(!checkshen(s))
{
cout<<"不合法输入!"<>m;
while(m<=0)
{
cout<<"请合法输入金额:"<>m;
}
cout<<"请输入透支金额!(大于2000,小于10000)"<>tou;
while(tou<=2000||tou>10000)
{
cout<<"请合法输入!"<>tou;
}
tmax=tou;
cin.get();
unsigned long long acc = account0 + random(1,100)+number;
number++;
cout<<"开户成功!"<> i;
creditcard * pt=new creditcard(i,n,se,a,t,s,p,m,tou,tmax); //动态建立一个账户对象
credit[creditcount]=pt; //把新建账户对象地址传过去
creditcount++;
csave();
cout<<"请按任意键继续!"<>id;
while(flag&&x!=0)
{
for(int i=0; igetid())
{
flag=0;
j=i;
break;
}
}
if(flag==1)
{
cout<<"账号不存在,请重新输入!("<>id;
x--;
}
if(x==0)
cout<<"返回上一界面!"<getp())
{
cout<>n;
while(n<1||n>6)
{
cout<<"请合法输入!"<>n;
}
switch(n)
{
case 1:
deposit[j]->display(); //用户信息界面
break;
case 2:
deposit[j]->save();
dsave();
break; //储蓄卡存钱
case 3:
deposit[j]->fetch();
dsave();
break; //储蓄卡取钱
case 4:
deposit[j]->querymoney();
dsave();
break; //储蓄卡余额查询
case 5:
deposit[j]->lixi(); //利息计算
dsave();
break;
case 6:
return ;
}
cin.get();
}
while(1);
}
void ATM::entercredit() //信用卡登录
{
cread();
string id,p;
int f1=1;
int flag=1,j,i=0;int x=2,y=2;
cout<<"请输入卡号:"<>id;
while(flag)
{
for(int i=0; igetid())
{
flag=0;
j=i;
break;
}
}
if(flag==1)
{
cout<<"账号不存在,请重新输入!"<>id;
}
}
while(1)
{
cout<<"请输入密码:"<getp())
{
cout<>n;
while(n<1||n>6)
{
cout<<"请合法输入!"<>n;
}
switch(n)
{
case 1:
credit[j]->display(); //用户信息界面
credit[j]->show();
break;
case 2:
credit[j]->save();
csave();
break; //信用卡存钱
case 3:
credit[j]->fetch();
csave();
break; //信用卡取钱
case 4:
credit[j]->querymoney();
credit[j]->show();
csave();
break; //信用卡余额查询
case 5:
return ;
}
cin.get();
}
while(1);
}
void creditcard::save() //信用卡存钱或还钱
{
double a;
int find=1;
if(touzhi>a;
while(a<0)
{
cout<<"请合法输入!"<>a;
}
if(a=tmax-touzhi)
{
a-=(tmax-touzhi);
cout<<"您已经完成还款!"<>a;
while(a<0)
{
cout<<"请合法输入!"<>a;
}
money+=a;
cout<<"当前余额为:"<>a;
while(a<0||a>b)
{
if(a<0)
{
cout<<"请合法输入!"<>a;
}
else
{
cout<<"取款金额不足,请重新输入!"<>a;
}
}
if(a<=money)
{
money-=a;
cout<<"取款成功,请按任意键继续!"<>a;
while(a<=0)
{
cout<<"请合法输入!"<>a;
}
cout<<"存款成功!"<>a;
while(a<0)
{
cout<<"请合法输入!"<>a;
}
if(money>b;
while(b!=0&&b!=1)//选择错误时判定
{
cout<<"请合法输入!"<>b;
}
}
while(b==0);
cout<<"请按任意键继续!"<>month;
while(month<=0)
{
cout<<"请合法输入!"<>month;
}
if(month<=4)
{
lixi=money*0.001*month;
}
else if(month<=8)
{
lixi=money*0.0014*month;
}
else if(month<=12)
{
lixi=money*0.0018*month;
}
else if(month>12)
{
lixi=money*0.002*month;
}
money+=lixi;
cout<<"请按任意键继续!"<>n;
while(n!=0&&n!=1)
{
cout<<"请合法输入!"<>n;
}
if(n==0)
{
while(flag)
{
cout<<"请输入你要销户的卡号:"<>id;
for(i=0; igetid())
{
j=i;
flag=0;
break;
}
}
if(flag==1)
{
cout<<"账号不存在,请重新输入!"<>id;
}
}
while(1)
{
cout<<"请输入密码:"<getp())
{
cout<<"密码错误,请重新输入!"<>id;
for(i=0; igetid())
{
j=i;
flag=0;
break;
}
}
if(flag==1)
{
cout<<"账号不存在,请重新输入!"<>id;
}
}
while(1)
{
cout<<"请输入密码:"<getp())
{
cout<<"密码错误,请重新输入!"<gettouzhi()gettmax())
{
cout<<"请先还款,您所欠透支金额为:"<gettmax()-credit[j]->gettouzhi()<>a;
credit[j]->add(a);
}
delete credit[j];
for(int j=i; j
需要自己亲自动手敲一下,才能发现自己的问题,针对自己的问题再从百度上搜取,这样做一道大作业能收获很多。
简单介绍一下我写的程序
该程序的结构:account账户为基类,depositcard储蓄卡和creditcard信用卡为account的派生类,创建ATM类,在ATM的私有数据中创建储蓄卡类的对象数组和信用卡类的对象数组。
进入界面,有五项功能,1.储蓄卡账户创建,2.储蓄卡账户登录,3.信用卡账户创建,4.信用卡账户登录,5.账户注销 ,6.退出。
在储蓄卡账户创建时,输入姓名,性别,地址,手机号,身份证号,密码,初始存入金额,最后系统自动生成卡号,记得复制。
在信用卡账户创建时,输入姓名,性别,地址,手机号,身份证号,密码,初始存入金额,此卡能透支的金额,最后系统自动生成卡号,记得复制。
储蓄卡账户登录后,1.用户信息,2.存款,3.取款,4.余额查询,5.利息计算,6.返回上一界面。利息计算是死期的。
信用卡账户登录后,1.用户信息,2.存款或还款,3.取款,4.余额查询,5.返回上一界面。信用卡可以进行透支,也可以存钱,但是还款时需要先把透支的前还上。
账户卡注销时,分为储蓄卡注销和信用卡注销,但是在信用卡注销时需要把透支的金额先还上。