类实现信用卡程序
#include<iostream>
#include<string.h>
using namespace std;
class Bank
{
private:
int num;
char *name;
float money;
public:
Bank(int i,char* na ,float j)
{
num=i;
name=new char[20]; //开辟name的空间,而不是形参na的空间
// name=na; //不能直接复制,要用strcpy函数。
strcpy(name,na);
money=j;
}
void InMoney(float n)
{
money+=n;
cout<<"存入"<<n<<endl;
cout<<"余额"<<money<<endl;
}
void OutMoney(float n)
{
money-=n;
cout<<"取出"<<n<<endl;
cout<<"余额"<<money<<endl;
}
void ZhuanZhang()
{
int num;
float n;
cout<<"输入要转的目标信用卡号和金额"<<endl;
cin>>num>>n;
money-=n;
cout<<"转到"<<num<<'\t'<<n<<"成功"<<endl;
cout<<"余额"<<money<<endl;
}
void Show()
{
cout<<"信用卡ID是"<<num<<endl;
cout<<"用户姓名是"<<name<<endl;
cout<<"卡上余额"<<money<<endl;
}
~Bank()
{
// delete name;
}
};
int main()
{
Bank bk(123,"aaaa",5214.25);
bk.Show();
cout<<"输入要存入的金额"<<endl;
float n;
cin>>n;
bk.InMoney(n);
cout<<"输入要取出的金额"<<endl;
float m;
cin>>m;
bk.OutMoney(m);
bk.ZhuanZhang();
return 0;
}