码迷,mamicode.com
首页 > 其他好文 > 详细

定义一个类来表示银行账户

时间:2015-01-19 20:31:02      阅读:406      评论:0      收藏:0      [点我收藏+]

标签:

#include<iostream>
using namespace std;
class BankAccount
{
    string m_name;
    string m_num;
    unsigned int m_balance;
    public:
            BankAccount(string name,string num,unsigned balance)
            {
                m_name = name;
                m_num = num;
                m_balance = balance;
            }
            void show() const
            {
                cout << m_name << endl;
                cout << m_num << endl;
                cout << m_balance << endl;
            }
            void inDeposit(unsigned amount)
            {
                m_balance = m_balance + amount;
            }
            void deDeposit(unsigned amount)
            {
                if(m_balance < amount)
                    m_balance = 0;
                else
                    m_balance = m_balance - amount;
            }
            
};
int main()
{
    BankAccount bank("Jack","123",10000);
    bank.show();
    bank.inDeposit(1000);
    bank.show();
    bank.deDeposit(1500);
    bank.show();
}

C++ Prime Plus第十章的练习。

定义一个类来表示银行账户

标签:

原文地址:http://www.cnblogs.com/fudianheg/p/4234479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!