/******************************************************************************
Name: Maria Logan
File Name: main.cpp
*******************************************************************************/
#include<iostream>
#include <iomanip>
#include <string>
#include "checkingAccount.h"
#include "savingsAccount.h"
using namespace std;
int main() {
bankAccount *accountsList[6];
accountsList[0] = new checkingAccount("Bill", 10200, 25000, 100, 0.012, 10.00, 5.00);
accountsList[1] = new checkingAccount("Bob", 10210, 10000, 100, 0.0099, 15.00, 5.00);
accountsList[2] = new savingsAccount("Susan", 90001, 20000, 0.031);
accountsList[3] = new savingsAccount("Steve", 90002, 50000, 0.041);
accountsList[4] = new checkingAccount("Sally", 10220, 4999, 100, 0.0079, 20.00, 5.00);
accountsList[5] = new savingsAccount("Fred", 90003, 2000, 0.011);
cout << "January:\n$$$$$$$$$$$$$$$\n ---------------" << endl;
for(int i = 0; i < 6; i++) {
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
cout << "February:\n$$$$$$$$$$$$$$$\n ---------------" << endl;
for(int i = 0; i < 6; i++) {
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
for(int i = 0; i<6; i++) {
accountsList[i]->withdraw(500);
}
cout << "March:\n$$$$$$$$$$$$$$$\n ---------------" << endl;
for(int i = 0; i < 6; i++) {
accountsList[i]->createMonthlyStatement();
accountsList[i]->print();
cout << endl;
}
return 0;
}
/******************************************************************************
Name: Maria Logan
File Name: bankAccount.h
*******************************************************************************/
#ifndef BANK_ACCOUNT_H
#define BANK_ACCOUNT_H
#include <iostream>
#include <string>
using namespace std;
class bankAccount {
private:
int accountNumber;
double balance;
string name;
public:
bankAccount(string name, double balance, int accountNumber);
double deposit(double transaction);
int getAccountNumber();
void setAccountNumber(int accountNumber);
double getBalance();
double getInterestRate();
string getName();
virtual double withdraw(double transaction);
virtual void print();
virtual void createMonthlyStatement();
};
#endif
/******************************************************************************
Name: Maria Logan
File Name: bankAccount.cpp
*******************************************************************************/
#include <iostream>
#include <string>
#include "bankAccount.h"
using namespace std;
//define method definitions
bankAccount::bankAccount(string name, double balance, int accountNumber) {
this->name = name;
this->balance = balance;
this->accountNumber = accountNumber;
}
double bankAccount::deposit(double transaction) {
balance += transaction;
return balance;
}
double bankAccount::withdraw(double transaction) {
balance -= transaction;
return balance;
}
void bankAccount::print() {
cout << "Name: " << name << "\tAccount number: " << accountNumber << "\tBalance: " << balance;
}
void bankAccount::setAccountNumber(int accountNumber){
accountNumber = accountNumber++;
}
//void bankAccount::setName(string name){
// name = name
//}
int bankAccount::getAccountNumber() {
return accountNumber;
}
double bankAccount::getBalance() {
return balance;
}
string bankAccount::getName(){
return name;
}
void bankAccount::createMonthlyStatement(){
}
/******************************************************************************
Name: Maria Logan
File Name: checkingAccount.h
*******************************************************************************/
#ifndef CHECKING_ACCOUNT_H
#define CHECKING_ACCOUNT_H
#include<iostream>
#include<string>
#include "bankAccount.h" //header file from week 1 included
using namespace std;
class checkingAccount : public bankAccount {
private:
double interestRate;
double minimumBalance;
double serviceCharge;
double fee;
double transaction;
public:
checkingAccount(string name, int accountNumber, double balance, double minimumBalance, double interestRate, double serviceCharge, double fee);
double getMinimumBalance();
void setMinimumBalance(double newMinimum);
double getInterestRate();
void setInterestRate(double newRate);
double getServiceCharge();
void setServiceCharge(double newCharge);
double postInterest();
double writeCheck(double transaction);
virtual double withdraw(double transaction);
void print();
virtual void createMonthlyStatement();
};
#endif
/******************************************************************************
Name: Maria Logan
File Name: checkingAccount.cpp
*******************************************************************************/
#include <iostream>
#include "bankAccount.h"
#include "checkingAccount.h"
#include <string>
using namespace std;
checkingAccount::checkingAccount(string name, int accountNumber, double balance, double minimumBalance, double interestRate, double serviceCharge, double fee):bankAccount(name, balance, accountNumber) {
//this->balance = balance;
this->minimumBalance = minimumBalance;
this->interestRate = interestRate;
this->serviceCharge = serviceCharge;
this->fee = fee;
}
double checkingAccount::getMinimumBalance() {
return minimumBalance;
}
void checkingAccount::setMinimumBalance(double newMinimum){
minimumBalance = newMinimum;
//return minimumBalance;
}
double checkingAccount::getInterestRate() {
return interestRate;
}
void checkingAccount::setInterestRate(double newRate) {
interestRate = newRate;
//return interestRate;
}
void checkingAccount::setServiceCharge(double newCharge) {
serviceCharge = newCharge;
//return serviceCharge;
}
double checkingAccount::getServiceCharge() {
return serviceCharge;
}
double checkingAccount::postInterest() {
double newBalance;
newBalance = getBalance() * interestRate / 100;
bankAccount::deposit(newBalance);
return 0;
}
double checkingAccount::writeCheck(double transaction) {
withdraw(transaction);
return 0;
}
double checkingAccount::withdraw(double transaction)
{
// Create a local variable, newBalance, equal to the current balance minus the transaction.
double newBalance = getBalance() - transaction;
if(newBalance < minimumBalance){
newBalance = newBalance - serviceCharge;
}
if(newBalance < 0){
cout << "Error not enough money" << endl;
}
else {
bankAccount::withdraw(getBalance() - newBalance);
}
return 0;
}
void checkingAccount::print() {
bankAccount::print();
cout << "\tInterest Rate: " << interestRate << endl;
}
void checkingAccount::createMonthlyStatement(){
//code to creat monthly statement
postInterest();
withdraw(fee);
}
/******************************************************************************
Name: Maria Logan
File Name: savingsAccount.cpp
*******************************************************************************/
#include <iostream>
#include <string>
#include "bankAccount.h"
#include "savingsAccount.h"
using namespace std;
savingsAccount::savingsAccount(string name, int accountNumber, double balance, double interestRate):bankAccount(name, balance, accountNumber){
//this->balance = balance;
this->interestRate = interestRate;
//this->accountNumber = accountNumber;
}
void savingsAccount::setInterestRate(double newRate){
interestRate = newRate;
}
double savingsAccount::getInterestRate(){
return interestRate;
}
double savingsAccount::withdraw(double transaction)
{
double newBal;
if (getBalance() >= transaction) {
bankAccount::withdraw(transaction);
}
if (getBalance() < transaction) {
cout << "Not enough funds to complete this transaction" << endl;
}
return 0;
}
void savingsAccount::postInterest() {
int newInterest, newBalance;
newInterest = getBalance() * interestRate / 100;
newBalance = getBalance() + newInterest;
bankAccount::deposit(newBalance);
}
void savingsAccount::createMonthlyStatement(){
//code to creat monthly statement
postInterest();
}
void savingsAccount::print() {
bankAccount::print();
cout << "\tInterest Rate: " << interestRate << endl;
}
/******************************************************************************
Name: Maria Logan
File Name: savingsAccount.h
*******************************************************************************/
#ifndef SAVINGS_ACCOUNT_H
#define SAVINGS_ACCOUNT_H
#include<iostream>
#include<string>
#include "bankAccount.h"
using namespace std;
class savingsAccount : public bankAccount {
private:
double transaction;
double interestRate;
public:
savingsAccount(string name, int accountNumber, double balance, double interestRate);
double getInterestRate();
void setInterestRate(double newRate);
virtual double withdraw(double transaction);
void postInterest();
void print();
virtual void createMonthlyStatement();
};
#endif