头文件
#ifndef BANKACCOUNT_H_
#define BANKACCOUNT_H_
#include<string>
using namespace std;
class bankaccount{
string name;
string account;
double money;
public:
bankaccount(string name,string account,double money);//初始化对象
void show();//显示储户的姓名,账户和存款
void save(double n);//存钱
void get(double n);//取钱
// ~bankaccount();
};
#endif
#include<iostream>
#include<string>
#include "bankaccount.h"
using namespace std;
bankaccount::bankaccount(string nam,string acc,double mon)
{
name=nam;
account=acc;
money=mon;
}
void bankaccount::show()
{
cout<<"储户姓名:"<<name<<endl;
cout<<"账户:"<<account<<endl;
cout<<"存款:"<<money<<endl;
}
void bankaccount::save(double n)
{
money=money+n;
}
void bankaccount::get(double n)
{
money=money-n;
}
#include<iostream>
#include<string>
#include "bankaccount.h"
using namespace std;
void main()
{
bankaccount a("sun","6222",1000);
a.show();
char name[50]="Richard";
char account[50]="518000";
double m=50000;
bankaccount b(name,account,m);
b.show();
}