Question: Pointers and Dynamic Memory Chapter 11 Write code using heap allocation based pointers and use the Accounts class from week 1 assignment as follows create

Pointers and Dynamic Memory Chapter 11

Write code using heap allocation based pointers and use the Accounts class from week 1 assignment as follows create a program in which you

Using operator new create a function that allocates 10 account objects on the heap using an array with indexes 0 to 9 and refer to each account using pointer notation.

Access the Account objects above using pointer notation and add an initial balance of $100 to each account.

Write an interactive program (function if you prefer) in which the program should prompt the user enter a user id and password. If the id and password are not entered incorrectly, ask the user to do it again. Once id and password is correctly accepted display a menu which gives the user the ability to

(i) view the fifth accounts balance in the heap array you created,

(ii) withdraw money from the fifth account in the array,

(iii) deposit money in the fifth account, and

(iv) exit the menu.

Make sure to access the fifth account using pointer notation only.

After menu exit, prompt for a new user id and password and start again.

Deallocate the Accounts array that is heap allocate using an appropriate operator delete before exiting the program.

ACCOUNT.H FILE:

#pragma once

//Account.h

#ifndef ACCOUNT_H

#define ACCOUNT_H

#include

using namespace std;

class Account

{

public:

//constructor

Account(string fName, string lName);

//methods

void debitFrom(double amt);

void creditTo(double amt);

double currentBalance();

private:

string firstName;

string lastName;

double balance;

};

//Constructor to set first name and last name

Account::Account(string fName, string lName)

{

firstName = fName;

lastName = lName;

balance = 0;

}

//Method to debit the amount from balance

void Account::debitFrom(double amt)

{

balance-=amt;

}

//Method to credit the amount to balance

void Account::creditTo(double amt)

{

balance += amt;

}

//Return balance

double Account::currentBalance()

{

return balance;

}

#endif ACCOUNT_H

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!