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 trying having trouble with creating this Account Class code which includes the header

Account Class C++

Any help is greatly appreciated, thank you

I am trying having trouble with creating this Account Class code which includes the header and the two .cpp files ( one with the function definitions and other with the int main () ). I think my header file Account.h is corrected and I'm not entirely sure if the Account.cpp file with the functions fully correct. I mostly need help with the AccountMain.cpp file with the int main because I don't know how to even start it and if I'm creating the objects correctly. I have posted what I done so far 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 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;

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

: id(newID),balance(newBalance)

{

const int id = newID;

double balance = newBalance;

}

Account::~Account() // destructor

{

cout

}

double Account::setBalance(double Newbalance)

{

balance = Newbalance;

}

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 completely lost and unsure what im doing is correct)

#include

#include

#include

#include "Account.h"

using namespace std;

Account account[1]{ { 1000,1000 } };

Account static account[2] { { 2000,2000} };

int main()

{

int i = 0;

Account account[3] = { { 3000,3000 } };

Account account[4] = { { 4000,4000 } };

Account account[5] = { { 5000,5000 } };

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

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions