(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 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.
solving: i did but make error i do not know!!
#include <iostream>
using namespace std;
//creating account class
class Account
{
public:
Account ( int );
void setBalance( int );
int getBalance();
void debitBalance( int );
void creditBalance( int );
private:
int balance; // bank account balance name
};
#include <iostream>
using namespace std;
#include "Account.h"
//initialization with constructor, with supplied args
Account::Account ( int initialBalance )
{
if (initialBalance >= 0)
setBalance ( initialBalance );
cout << "Account balance set without any problem" << endl;
if (initialBalance < 0)
{
balance = 0;
cout << "Account balance cannot be negative. Account amount set as 0" << endl;
}
}
well first get rid of the extra #include <iostream>'s and the extra using namespace std;'s and #include "Account.h"'s. Then post the Account.h file using code tages, and repost the original file with code tags. Hint its the <> button on the right side of the screen.
For warning to everyone the OP is unwilling to take any advice that is given him and seems to be looking for someone to do his homework for him. I believe this is his 3rd topic he posted about this question (All totally ignoring advice to use codetags) and Hashimatsu and others have tried to help him correct it but he just ignores their advice.
So please do not give this guy a fixed version of his code so he can copy and paste ;P
Signed Zereo ~ Stopping all homework fraud from his couch while eating pizza.