(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.
//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;
}
}
I made this for you. I have not corrected all the errors, but I did put in a few comments on your code and minor mistakes.
OBS!!!
This is not a sulotion nor is it my work! This is simply the same code as the one posted above, but I did put it inside codetags to make it readable!
.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
usingnamespace 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
};
Giving him most of the program solves nothing and will hurt him in the long run. If he isn't even going to try and accept help to work through it on his own and just keeps asking for the answer ignore him because programming is probably not for him. Programming is not a copy and paste profession and if he can't take the time to research his problems and correct them himself (With guidance of others) he is going to fail plain and simple. Because 90% of the time you won't be programming you will be researching, debugging, and a whole bunch of other things so might as well learn to do it now.
Zereo
All I did was taking his code and put it inside codetags to make it more readable. Did not do any work on it exept putting in a few comments. I will not solve the problem for him, but someone might be able to give him a hint if they can read what he has done.
Ahh my mistake then (Should have taken the time and looked through the code ;P) and sorry for that, it was more meant for the OP and it still stands. You are going to need to be able to walk through your code and find the bugs in it. Other people will help you by pushing you in the right direction like Hashimatsu did but they won't just fix it for you.