Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Account Class C++ Any help is greatly appreciated, thank you I am having trouble getting my code to print out correctly. As you can see

Account Class C++

Any help is greatly appreciated, thank you

I am having trouble getting my code to print out correctly. As you can see in the Sample output and my own output I can't get the numbers within "Number of Account object's 1" after the create() function and so on to match the correct output. I also can't get the numbers of the "account id","Monthly Interest" and "account balance" to show up either. I know the issue is within my Account.cpp file under the Constructor and the Destructor & within my AccountMain.cpp file int main() & create() function. I have tried multiple things and I keep getting errors or incorrect outputs. I have posted what I have done so far in my code below.

Write a test program that creates the following Account objects in order:

1.One global object before main with Account ID 1111, initial balance $1000 2.One static object before main with Account ID 2222, initial balance $2000 3.One local automatic object in main with Account ID 3333, initial balance $3000 4.One local static object in main with Account ID 4444, initial balance $4000 5.One local automatic object in main with Account ID 5555, initial balance $5000 6.One local automatic object in create() function with Account ID 6666, initial balance $6000 7.One local static object in create() function with Account ID 7777, initial balance $7000 8.One local automatic object in create() function with Account ID 8888, initial balance $8000 9.One local automatic object in main with Account ID 9999, initial balance $9000

Use the withdraw method to withdraw $500, use the deposit method to deposit $1000, and print the account ID, the monthly interest, and the balance for each account.

Hints for Header file and CPP file:

1.Set Account ID as a const variable, and use member initializer syntax to set the value. The default values of Account ID = 0 and initial balance =0. 2.Modify AnnualInterestRateas a static variable, the getAnnualInterestRate() and setAnnualInterestRate() methods as static, and set the initial value as 5%. 3.Add NumberOfObjectsvariable as static to keep tracking how many Account objects created. You need to make the necessary changes in the constructor and destructor functions, and add static getNumberOfObjects() function. 4.Make the setBalancefunction as a utility function (for internal use), change from the public access to the private access. 5.Use this pointer in the setBalancefunction, and the class name followed by the scope resolution operator (::) in the setAnnualInterestRatefunction. 6.Print out Account ID and NumberOfObjectsinfo whenever one Account object is created or destroyed. (Make the corresponding changes in the constructor and destructor functions.

UML Diagram:image text in transcribed

image text in transcribedMy Output :

image text in transcribed

Here is my code so far:

Account.h

#ifndef Account_h

#define Account_h

class Account

{

const int id;

double balance;

double static annualInterestRate;

int static NumberOfObjects;

double setBalance(double ); // utility function

public:

Account(const int = 0, double = 0.0); // Constructor

~Account(); // Destructor

// set functions

void static setAnnualInterestRate(double); // set the initial value as 5% ??

// get functions

unsigned int getID() const;

double getBalance() const;

double static getAnnualInterestRate();

int static getNumberofObjects();

double getMonthlyInterestRate() const;

double getMonthlyInterest() const;

void withdraw(double);

void deposit(double);

};

#endif // Account_h

-------------------------------

Account.cpp ( need help checking if I did this correctly)

#include

#include

#include

#include "Account.h"

using namespace std;

double Account::annualInterestRate = 0.05;

int Account::NumberOfObjects = 1;

Account::Account(const int newID, double newBalance) // constructor initialises each data member

: id(newID), balance(newBalance)

{

const int id = newID;

balance = newBalance;

cout

cout

NumberOfObjects++;

}

Account::~Account() // destructor

{

cout

cout

NumberOfObjects--;

}

double Account::setBalance(double Newbalance)

{

this->balance = Newbalance;

return 0;

}

void Account::setAnnualInterestRate(double newannualInterestRate)

{

annualInterestRate = newannualInterestRate;

}

unsigned int Account::getID() const

{

return id;

}

double Account::getBalance() const

{

return balance;

}

double Account::getAnnualInterestRate()

{

return annualInterestRate;

}

int Account::getNumberofObjects()

{

return NumberOfObjects;

}

double Account::getMonthlyInterestRate() const

{

return (annualInterestRate / 12);

}

double Account::getMonthlyInterest() const

{

return balance*(annualInterestRate / 12);

}

void Account::withdraw(double withdrawAmount)

{

if (balance >= withdrawAmount)

{

balance -= withdrawAmount; //balance = balance - withdrawAmount

}

else

throw invalid_argument("No sufficient balance");

}

void Account::deposit(double depositAmount)

{

balance += depositAmount; //balance = balance + depositAmount

}

-------------------------------

AccountMain.cpp (Where I am unsure what im doing is correct)

#include

#include

#include

#include "Account.h"

using namespace std;

Account account1 (1111, 1000);

static Account account2 (2222, 2000);

int main()

{

Account account3 (3333, 3000);

static Account account4 (4444, 4000);

Account account5 (5555, 5000);

cout

cout

cout

void create();

{

cout

Account account6 (6666, 6000);

static Account account7 (7777, 7000);

Account account8 (8888, 8000);

cout

cout

cout

cout

cout

}

Account account9 (9999, 9000);

cout

cout

cout

return 0;

}

Account id: int const balance: double annuallnterestRate: double NumberOfObjects: int + >Account(id: int=0, balance: double-0) + >Account) + setlDd: int) + getID( : int const setBalance(balance: double) + getBalance(): double const + setAnnuallnterestRate( annuallnterestRate: double) + getAnnuallnterestRate: double + getNumberfObjects: int + getMonthlylnterestRate0 + getMonthlylnterest(): double + withdraw(amount: double) + deposit(amount: double) : double const const

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimizing Data Collection In Warzones

Authors: Aaget Aamber

1st Edition

B0CQRRFP5F, 979-8869065902

Students also viewed these Databases questions

Question

1. Describe the factors that lead to productive conflict

Answered: 1 week ago