Can someone please advise me as to why my assignment is not working? I am doing the exact same thing I did on another assignment and for some reason it wont work.
Assignment
1. You are a programmer that works for a local bank. You are creating classes to be used in the class library for this bank for all of its programs. You will also create a main() to test your new classes.
Talking to the bank manager you find out that your bank keeps track of Accounts and that there are more than one type of Account. There are CheckingAccounts, SavingsAccounts, and CreditCardAccounts.
(Credit card accounts are actually called line of credit accounts in the real world. But, let’s call them this here to make it clearer.)
You learn that all of the accounts are often grouped together and treated the same in many reports. So, they all need to inherit from the account class.
Account Class:
Attributes/data members
number (an integer)
balance (a double)
rate (a double)
Behaviors/member functions:
1) accessor (get) and mutator (set) functions for all attributes.
2) ApplyInterest()
Note: The ApplyInterest() function needs to be a virtual function. It is going to be overridden in the subclasses.
Constructor(s):
This class must have a constructor that accepts all of the data to create an Account and initializes its data members.
Validation in member functions/ Business Rules:
1) Rates should be between .01 and .18 (it is an interest rate as a decimal)
2) Balances should never be allowed to be set to a negative value.
CheckingAccount Class:
This class inherits from the Account class
Attributes/data members
checknumber (an integer) [representing the last check number written/processed.]
pin (an integer)
Behaviors/member functions:
1) accessor (get) and mutator (set) functions for all attributes.
2) ApplyInterest(), this function should take the balance and multiply it by the rate to find the interest this period…then add it to the existing balance. Print a message to the user with the amount in this format “2.35 has been added to checking”
Constructor(s):
This class must have a constructor that accepts all of the data to create a CheckingAccount and initializes its data members. (This includes all of the data it needs to pass to the Account class constructor or set directly for the account class from this constructor.)
SavingsAccount Class:
This class inherits from the Account class
Attributes/data members
Behaviors/member functions:
1) accessor (get) and mutator (set) functions for all attributes.
2) ApplyInterest(), this function should take the balance and multiply it by the rate to find the interest this period…then add it to the existing balance. Print a message to the user with the amount in this format “5.01 has been added to savings”
Constructor(s):
This class must have a constructor that accepts all of the data to create a SavingsAccount and initializes its data members. (This includes all of the data it needs to pass to the Account class constructor or set directly for the account class from this constructor.)
CreditCardAccount Class:
This class inherits from the Account class
Attributes/data members
cardnumber (a string)
Behaviors/member functions:
1) accessor (get) and mutator (set) functions for all attributes.
2) ApplyInterest(), this function should take the balance and multiply it by the rate to find the interest this period…then add it to the existing balance. Print a message to the user with the amount in this format “5.23 interest has been charged to this credit card on its unpaid balance”
Constructor(s):
This class must have a constructor that accepts all of the data to create a CreditCardAccount and initializes its data members. (This includes all of the data it needs to pass to the Account class constructor or set directly for the account class from this constructor.)
Main()
1) In main for this program create a checking account, savings account, and credit card account for a customer with test data as follows and place them in an array:
(type) account # balance rate checknumber pin cardnumber
(checking) 832443 560.10 .02 5854 123
(savings) 832443 1020.58 .04
(credit card) 832443 78.00 .16 1238201293731133
2) Print out all of the data for the accounts for the user.
3) Use a loop and call the ApplyInterest() method to add interest to the balance and print appropriate messages to the user.
4) Print out all of the data for the accounts for the user.
Account Class
#ifndef ACCOUNT_H
#define ACCOUNT_H
#include <iostream>
#include <fstream>
#include <iomanip>
#include <functional>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <sstream>
using namespace std;
//Account Class
class Account {
private:
int number;
double balance;
double rate;
double interest;
double NewBalance;
public:
Account(); // Constructor
Account(int, double, double) ;
void setBalance(double);
void setRate(double);
void setNumber(int);
int getNumber();
double getBalance();
double getRate();
void valid_rate(double);
virtual void ApplyInterest();
void operator +=( double );
void operator -=( double );
void operator ++ ();
};
//-----------------------------------------------------------------------------
//class definition
Account::Account() {
number = 0;
balance = 0;
rate = 0;
}
Account::Account(int number, double balance, double rate) {
Account::number = number;
Account::balance = balance;
valid_rate(rate);
}
void Account::setNumber(int number) {
Account::number = number;
}
void Account::setBalance(double balance) {
Account::balance = balance;
}
void Account::setRate(double rate) {
valid_rate(rate);
}
int Account::getNumber() {
return number;
}
double Account::getBalance() {
return balance;
}
double Account::getRate() {
return rate;
}
void Account::valid_rate(double rate) {
if (rate >=.01 && rate <= .18)
Account::rate=rate;
else {
Account::rate=0;
cout << "WARNING! You have entered an invalid rate!\n";
}
}
void Account::operator += ( double dValue ) {
setBalance( getBalance()+ dValue );
//return this;
}
void Account::operator -= ( double dValue ) {
setBalance( getBalance() - dValue );
//return this;
}
#endif
Checking Classk
#ifndef CHECKING_H
#define CHECKING_H
#include "Account.h"
//Checking Class
class Checking {
private:
Checking myChecking[1];
int CheckNumber;
int CheckingPin;
public:
Checking(); // Constructor
Checking(int, int) ;
void setCheckNumber(int);
void setCheckingPin(int);
int getCheckNumber();
int getCheckingPin();
};
//-----------------------------------------------------------------------------
//class definition
Checking::Checking() {
CheckNumber = 0;
CheckingPin = 0;
}
Checking::Checking(int CheckNumber, int CheckingPin) {
Checking::CheckNumber = CheckNumber;
Checking::CheckingPin = CheckingPin;
}
void Checking::setCheckNumber(int CheckNumber) {
Checking::CheckNumber = CheckNumber;
}
void Checking::CheckingPin(int CheckingPin) {
Checking::CheckingPin = CheckingPin;
}
int Checking::getCheckNumber() {
return CheckNumber;
}
int Checking::getCheckingPin() {
return CheckingPin;
}
void Account::ApplyInterest() {
interest = rate * balance;
NewBalance = interest + balance;
cout << interest << " has been added to checking.\n\n";
}
#endif
Credit Class
#ifndef CHECKING_H
#define CHECKING_H
#include "Account.h"
//Checking Class
class Credit {
private:
Credit myCredit[1];
string CardNumber;
public:
Credit(); // Constructor
Credit(string) ;
void setCardNumber(string);
string getCardNumber();
};
//-----------------------------------------------------------------------------
//class definition
Credit::Credit() {
CardNumber = " ";
}
Credit::Credit(string CardNumber) {
Credit::CardNumber = CardNumber;
}
void Credit::setCardNumber(string CardNumber) {
Credit::CardNumber = CardNumber;
}
string Credit::getCardNumber() {
return CardNumber;
}
void Account::ApplyInterest() {
interest = rate * balance;
NewBalance = interest + balance;
cout << interest << " 23 interest has been charged to this credit card on its unpaid balance.\n\n";
}
#endif
Saving Class
#ifndef SAVING_H
#define SAVING_H
//Customer Class
class Saving {
private:
Saving mySaving[1];
public:
};
void Account::ApplyInterest() {
interest = rate * balance;
NewBalance = interest + balance;
cout << interest << " has been added to checking.\n\n";
}
#endif
Main
#include "Account.h"
#include "Checking.h"
#include "Saving.h"
#include "Credit.h"
using namespace std;
int main() {
int current_cust=0;
Checking *myChecking[1];
Saving *mySaving[1];
Credit *myCredit[1];
Checking myRate;
myChecking[0] = new Checking(832443, 560.10, .02, 5);
mySaving[0] = new Saving(832243, 1020.58, .04);
myCredit[0] = new Credit(832443, 78.00, .16, 1238201293731133);
cout << "__________________________________________________________\n"<< endl;
for (int c=0; c<1; c++)
myChecking[c]->ApplyInterest();
cout << "__________________________________________________________\n"<< endl;
for (int s=0; s<1; s++)
mySaving[s]->ApplyInterest();
cout << "__________________________________________________________\n"<< endl;
for (int x=0; x<1; x++)
myCredit[x]->ApplyInterest();
cout << "__________________________________________________________\n"<< endl;
return 0;
}