Access over 35 million academic & study documents

3 12 (Account Class) Create an Account class that a bank might use t

Content type
User Generated
Rating
Showing Page:
1/4
3.12 (Account Class) 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, well use numbers
that contain decimal points (e.g., 2.75)called floating-
point valuesto 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 its 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
Accounts 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.
Solution
Answer
#include <iostream>
using namespace std;
class Account

Sign up to view the full document!

lock_open Sign Up
Showing Page:
2/4
{
public:
int account_balance;
Account(int acc_bal)
{
if(acc_bal>=0)
{
account_balance=acc_bal;
}
else
{
account_balance=0;
cout<<\"\ \ initial balance was invalid!!\ \";
}
}
void credit()
{
int credit_amount;
cout<<\"\ Enter amount to credit in a/c : \";
cin>>credit_amount;
account_balance+=credit_amount;
}
void debit()
{
int debit_amount;

Sign up to view the full document!

lock_open Sign Up
Showing Page:
3/4

Sign up to view the full document!

lock_open Sign Up
End of Preview - Want to read all 4 pages?
Access Now
Unformatted Attachment Preview
3.12 (Account Class) 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 floatingpoint 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. Solution Answer #inc ...
Purchase document to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Anonymous
Really helped me to better understand my coursework. Super recommended.

Studypool
4.7
Indeed
4.5
Sitejabber
4.4