#include
using namespace std;
/*
继承
封装
多态
类的访问权限
*/
class bank_account
{
public:
//函数名与类名相同,就是构造函数,不能与有返回值(void返回值是空)
//用于初始化,由系统调用
bank_account(int acc_num, double amount);
void open(int acc_num,double amount);//开户
void deposite(double amount);//存钱
void withdraw(double amount);//取钱
void display_balance();//显示私有的内容,接口
private:
int account_number;//账号
double balance;//余额
};
bank_account::bank_account(int acc_num, double amount)
{
account_number = acc_num;
balance = amount;
}
void bank_account::open(int acc_num, double amount)
{
account_number = acc_num;
balance = amount;
}
void bank_account::display_balance()
{
cout << "account_number : " << account_number << endl;
cout << "balance : " << balance << endl;
}
void bank_account::deposite(double amount)
{
balance -= amount;
}
void bank_account::withdraw(double amount)
{
balance += amount;
}
/*
//这种定义只是全局的,不是类里面的函数
void open(int acc_num, double amount)
{
}
*/
int main()
{
bank_account account(1,100.00);
account.display_balance();
account.open(1, 200);
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)