标签:
10.2题
定义一个类来表示银行账户
1 #include<iostream> 2 using namespace std; 3 class BankAccount 4 { 5 string m_name; 6 string m_num; 7 unsigned int m_balance; 8 public: 9 BankAccount(string name,string num,unsigned balance) 10 { 11 m_name = name; 12 m_num = num; 13 m_balance = balance; 14 } 15 void show() const 16 { 17 cout << m_name << endl; 18 cout << m_num << endl; 19 cout << m_balance << endl; 20 } 21 void inDeposit(unsigned amount) 22 { 23 m_balance = m_balance + amount; 24 } 25 void deDeposit(unsigned amount) 26 { 27 if(m_balance < amount) 28 m_balance = 0; 29 else 30 m_balance = m_balance - amount; 31 } 32 33 }; 34 int main() 35 { 36 BankAccount bank("Jack","123",10000); 37 bank.show(); 38 bank.inDeposit(1000); 39 bank.show(); 40 bank.deDeposit(1500); 41 bank.show(); 42 }
标签:
原文地址:http://www.cnblogs.com/fudianheg/p/4237522.html