Question

Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only....

Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only. Thank you.

Pointers and Dynamic Memory – Chapter 11 1.

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

a. Create 10 accounts using an array with id’s 0 to 9 and refer to each account using pointer notation

b. Add an initial balance of $100 to each account.

c. Fill in different names of your choosing for each account

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

(i) view their accounts balance,

(ii) withdraw money,

(iii) deposit money, and

(iv) exit the menu.

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

0 0
Add a comment Improve this question Transcribed image text
Answer #1

thanks for the question, here is the code in C++

=====================================================================================

#ifndef ACCOUNT_H

#define ACCOUNT_H

#include<string>

using std::string;

class Account

{

                public:

                               

                                Account();

                                Account(string, int,double);

                                void displayBalance() const;

                                void withdraw(double amount);

                                void deposit(double amount);

                               

                               

                private:

                                string name;

                                int account_id;

                                double balance;

                               

};

#endif

=====================================================================================

#include "Account.h"

#include<iostream>

using std::count;

suing std::endl;

Account::Account(){

}

Account::Account(string name, int id, double balance):name{name},account_id{id},balance{balance}{}

void Account::displayBalance() const{

cout<<"Name: "<<name<<", Account ID: "<<account_id<<", Account Balance: $"<<balance<<endl;

}

void Account::withdraw(double amount){

if ((amount>0 ) && amount<=(this->balance)){

this->balance -=amount;

}else{

cout<<"You dont have sufficient balance. Operation aborted"<<endl;

}

}

void Account::deposit(double amount){

if(amount>0){

this->balance+=amount;

}

}

=====================================================================================

#include <iostream>

#include "Account.h"

#include <string>

#include<vector>

using namespace std;

int printMenutGetUserChoice(){

               

                cout<<"[1] View thier accounts balance"<<endl;

                cout<<"[2] Withdraw Money"<<endl;

                cout<<"[3] Deposit Money"<<endl;

                cout<<"[4] Exit"<<endl;

                int choice;

                while(true){

                                cout<<"Enter choice -> ";

                                cin>>choice;

                                if(1<=choice && choice<=4)return choice;

                                else cout<<"Invalid selection"<<endl;

                }

}

int getUserID(int &id){

               

                while(true){

                                cout<<"Enter User ID: "; cin>>id;

                                if(id<0 || id>9){

                                                cout<<"Invalid user id, Please enter an id between 0-9"<<endl;

                                }else{

                                                break;

                                }

                               

                }

                return id;

}

void getAmount(double &balance){

                cout<<"Enter Amount : $";cin>>balance;

}

int main(){

               

               

               

                vector<Account *> v_accounts;

                v_accounts.push_back(new Account("Alice",0,100));

                v_accounts.push_back(new Account("John",0,100));

                v_accounts.push_back(new Account("Jacob",0,100));

                v_accounts.push_back(new Account("Marsha",0,100));

                v_accounts.push_back(new Account("Peter",0,100));

                v_accounts.push_back(new Account("Ron",0,100));

                v_accounts.push_back(new Account("Dora",0,100));

                v_accounts.push_back(new Account("Dan",0,100));

                v_accounts.push_back(new Account("Walsh",0,100));

                v_accounts.push_back(new Account("Julie",0,100));

               

               

                while(true){

               

                int user_Id=-1;

                getUserID(user_Id);

                int choice=0;

                double balance=0.0;

                while(true){

                                choice=printMenutGetUserChoice();

                                switch(choice){

                                                case 1:

                                                                (v_accounts.at(user_Id))->displayBalance();break;

                                                case 2:

                                                                getAmount(balance);

                                                                (v_accounts.at(user_Id))->withdraw(balance);break;

                                                case 3:

                                                                getAmount(balance);

                                                                (v_accounts.at(user_Id))->deposit(balance);break;

                                               case 4:

                                                                cout<<"Bye!"<<endl;

                                                                               

                                                                                               

                                }

                                if(choice==4){

                                                break;

                                }

                }

                char again;

                cout<<"Do you want to continue (y/n)? ";cin>>again;

                if( again!='y'){

                                cout<<"Thanks for using the program. Good Bye !"<<endl;                           

                                break;

                }

               

}

               

               

               

}

=====================================================================================

Add a comment
Know the answer?
Add Answer to:
Please i need the .H, .cpp and main.cpp files. Please use vector. its for my midterm so correct code that can run only....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I need to write a java program call atm machine. Simulate An Atm Machine. create 10...

    I need to write a java program call atm machine. Simulate An Atm Machine. create 10 accounts in an array with id,…,9 and an initial balance of $100. The Systems Prompts the user to enter an id. If the id is entered incorrectly it will ask the user to enter a correct id. Once an id is accepted, the main menu is displayed as shown in the sample run. You can choice 1 for viewing the current balance, 2 for...

  • LAB 13 Please use correct division of code into .h and .cpp files and Comments in...

    LAB 13 Please use correct division of code into .h and .cpp files and Comments in code explain what's being done. Thanks you very much for your help Create an STL vector of 10 integers and store initial values (0 to 9 is fine). Use the std::random_shuffle algorithm to shuffle the list. Print the list. (use an iterator in a regular for loop) Use the std::sort algorithm to sort the list. Print the list again. (use a range-based for loop)...

  • In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and...

    In C++ please! Please include .cpp and .hpp files! Thank you! Recursive Functions Goals Create and use recursive functions In this lab, we will write a program that uses three recursive functions. Requirements: Important: You must use the array for this lab, no vectors allowed. First Recursive Function Write a function that recursively prints a string in reverse. The function has ONLY one parameter of type string. It prints the reversed character to the screen followed by a newline character....

  • C++ Read and do as instructed on please (C++Program *** use only condition statements, loops, functions,...

    C++ Read and do as instructed on please (C++Program *** use only condition statements, loops, functions, files, and arrays. Do NOT use material such as classes. Make sure to add comments** You are to write an ATM Program. The ATM should allow the user to do the following: 1. Create account 2. Log in 3. Exit When they press 1, they are asked for first name (capital first letter). Then it should ask for password. The computer should give the...

  • this is for java programming Please use comments Use the Account class created in homework 8_2...

    this is for java programming Please use comments Use the Account class created in homework 8_2 to simulate an ATM machine. Create ten checking accounts in an array with id 0, 1, …, 9, initial balance of $100, and annualInterestRate of 0. The system prompts the user to enter an id between 0 and 9, or 999 to exit the program. If the id is invalid (not an integer between 0 and 9), ask the user to enter a valid...

  • Java Inventory Management Code Question

    Inventory ManagementObjectives:Use inheritance to create base and child classesUtilize multiple classes in the same programPerform standard input validationImplement a solution that uses polymorphismProblem:A small electronics company has hired you to write an application to manage their inventory. The company requested a role-based access control (RBAC) to increase the security around using the new application. The company also requested that the application menu must be flexible enough to allow adding new menu items to the menu with minimal changes. This includes...

  • answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a cl...

    answer in c++ code. use comments when writing the code to know what's your thinking. there is three pictures with information Write a C++ console program that defines and utilizes a class named ATM. This program will demonstrate a composition relationship among classes because an ATM can contain many Accounts. You will need to reuse/modify the Account class you created in Assignment 10. The default constructor for the ATM class should initialize a private vector of 10 accounts, each with...

  • C++ program: can you help create a autocorrect code using the cpp code provided and the...

    C++ program: can you help create a autocorrect code using the cpp code provided and the words below using pairs, vectors and unordered map: Objectives To practice using C++ std::pair, std::vector, and std::unordered_map To tie together what we've learned into the context of a real-world application used by millions of people every day Instructions For Full Credit You're given a short list of words in known_words_short.txt that contains a handful of very different words. Assume this short list of words...

  • Please code in c 1. Write a program which does the following: Declare and initialize three...

    Please code in c 1. Write a program which does the following: Declare and initialize three pointers. One points to an integer, one points to a float and one points to a character variable Ask the user to enter appropriate values for these variables. Output the values to the screen by accessing the variables directly and then by using pointer references. Print the address of each variable. Modify the variables by performing any arithmetic operation only using pointer refer- ences...

  • Create a class named UserAccounts that defines an array of 8 accounts as an instance variable....

    Create a class named UserAccounts that defines an array of 8 accounts as an instance variable. In the default constructor of this class, write a loop that creates 8 accounts with ids 1 through 7 and initial balance of $50 for each account. Store these accounts in the array. When the program runs, it asks the use to enter a specific id. When the user enters a correct id, the system displays a menu as shown in the sample run...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT