题目描述

Create an Account class that a bank might use to represent customers’ bank accounts. Include a data member of type int to represent the account balance. [Note: In subsequent chapters, we’ll use numbers that contain decimal points (e.g., 2.75)—called floating-point values—to represent dollar amounts.]
Provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it’s greater than or equal to 0. If not, set the balance to 0 and display an error message indicating that the initial balance was invalid.
Provide three member functions.
Member function credit should add an amount to the current balance.
Member function debit should withdraw money from the Account and ensure that the debit amount does not exceed the Account’s balance. If it does, the balance should be left unchanged and the function should print a message indicating "Debit amount exceeded account balance."
Member function getBalance should return the current balance. Create a program that creates two Account objects and tests the member functions of class Account.


输入格式

Four integers:
1) Initial balance of Account object 1
2) Initial balance of Account object 2
3) Withdraw money of Account object 1
4) Withdraw money of Account object 2


输出格式

The main function have been given, please implement the Account class.


样例数据

输入

100 75 16 84

输出

account1 balance: $84
Debit amount exceeded account balance.
account2 balance: $75

备注


操作

评测记录

优秀代码

信息

时间限制: 1s
内存限制: 128MB
评测模式: Normal

题解