The Account Class

1 minute read

The code has been modified slightly and now uploaded to the site.

A UML diagram is not provided.

Question

Question

<— Return Home

93.cpp

#include <iostream>
#include "Account93.h"
using namespace std;

int main() {
  Account93 account1122(1122, 20000, 4.5);
  account1122.withdraw(2500);
  account1122.deposit(3000);
  std::cout << account1122.getBalance() << "\n";
  std::cout << account1122.getMonthlyInterestRate() << "\n";
} 

<— Return Home

Account93.h

#ifndef Account93_H
#define Account93_H

class Account93{
  public:
    Account93();
    Account93(int identify, double bal, double annualIRate);
    int getId();
    double getBalance();
    double getAnnualInterestRate();
    double getMonthlyInterestRate();
    void withdraw(double amount);
    void deposit(double amount);


  private:
    int id;
    double balance;
    double annualInterestRate;

};

#endif

<— Return Home

Account93.cpp

#include "Account93.h"

Account93::Account93(){
  id = 0;
  balance = 0;
  annualInterestRate = 0;
}

Account93::Account93(int identify, double bal, double annualIRate){
  id = identify;
  balance = bal;
  annualInterestRate = annualIRate;
}

int Account93::getId(){
  return id;
}

double Account93::getBalance(){
  return balance;
}

double Account93::getAnnualInterestRate(){
  return annualInterestRate;
}

double Account93::getMonthlyInterestRate(){
  return annualInterestRate / 12;
}

void Account93::withdraw(double amount){
  balance -= amount;
}

void Account93::deposit(double amount){
  balance += amount;
}

<— Return Home

Here is a 2nd version of the same homework question.

93V2.cpp

#include <iostream>
#include "Account93V2.h"

int main(){
    Account acc1(1122, 20000, 4.5);
    acc1.withdraw(2500);
    acc1.deposit(3000);
    std::cout << "$" << acc1.getBalance() << std::endl;
    std::cout << acc1.getMonthlyInterestRate() << "%" << std::endl;
    return 0;
}

<— Return Home

Account93V2.h

#ifndef ACCOUNT93V2_H
#define ACCOUNT93V2_H

class Account{
    public:
        Account();
        Account(int identify, double bal, double aIR);
        int getId();
        void setId(int identify);
        double getBalance();
        void setBalance(double bal);
        double getAnnualInterestRate();
        void setAnnualInterestRate(double aIR);
        double getMonthlyInterestRate();
        void withdraw(double amount);
        void deposit(double amount);
    private:
        int id;
        double balance;
        double annualInterestRate;

};

Account::Account(){
    id = 0;
    balance = 0;
    annualInterestRate = 0;
}

Account::Account(int identify, double bal, double aIR){
    id = identify;
    balance = bal;
    annualInterestRate = aIR;
}

int Account::getId(){
    return id;
}

void Account::setId(int identify){
    id = identify;
}

double Account::getBalance(){
    return balance;
}

void Account::setBalance(double bal){
    balance = bal;
}

double Account::getAnnualInterestRate(){
    return annualInterestRate;
}

void Account::setAnnualInterestRate(double aIR){
    annualInterestRate = aIR;
}

double Account::getMonthlyInterestRate(){
    return annualInterestRate / 12;
}

void Account::withdraw(double amount){
    balance -= amount;
}

void Account::deposit(double amount){
    balance += amount;
}

#endif

<— Return Home