logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

This homework assignment gives you the opportunity to practice classes, member variables, member functions, static member variables, dynamic creation of objects, pointers to objects. The homework has an extra credit version worth an additional 15 bonus points.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

1.10 HW7

This homework assignment gives you the opportunity to practice classes, member variables, member functions, static member variables, dynamic creation of objects, pointers to objects. The homework has an extra credit version worth an additional 15 bonus points.

HW7 (Graded out of 100)

Design a bank account class named Account that has the following private member variables:

  • accountNumber of type int
  • numOwners of type int / number of account co-owners (account can have more than one owner)
  • ownerPtr of type Person * //, ownerPtr points to an array of Person, where Person is a The Person structure is defined below
  • balance of type double
  • accountCounter of type static int / initialized at 1000, incremented at each account creation, used to automate account number assignment

and the following public member functions:

  • Account(int numberOwners, double amount) constructor which sets the accountNumber using the value of accountCounter, sets numOwners, dynamically creates an array of Person of the right size, and sets balance to amount. The function then increments accountCounter
  • ~Account() destructor which releases the array of Person dynamically created in the constructor
  • withdraw(double amount) function to withdraw a specified amount from the The function should first check if the amount is > 0 and if there is suficient balance in the account (greater or equal to the withdrawal amount). If so, withdrawal is processed and the function returns 0. Otherwise the withdrawal is not made and the function returns 1 if the amount > balance, or 2 if the amount is <= 0

 

  • deposit(double amount) function to deposit a specified amount of money to the The function should first check if the deposit amount is > 0. If so, the deposit is processed and the function returns 0. Otherwise the deposit is not made and the function returns 1.
  • setOwner(int ind, Person p): A mutator function that assigns Person p to the co-owner at index ind of the ownerPtr array
  • getOwner(int ind): An accessor that returns the owner at index ind of the ownerPtr Return type is Person.
  • getAccountNumber(): An accessor function that returns the account
  • getBalance(): An accessor function that returns the account

  • getNumOwners(): An accessor function that returns numOwners. Define these structures in h

 

Demonstrate in a program.

1.   Additional Requirements – Make sure you meet all the requirements to avoid losing points

 

  1. What to turn in

 

Your code should be structured into the following files, but you should turn in only Account.cpp and main.cpp:

  • h which contains the class definition and the function prototypes of all the member functions (no in-line

 

member functions)

  • cpp which contains the function description of all the member functions
  • cpp file which contains the main function.

 

  1. Outline of program

 

Define a global array of pointers to Account, of size MAX_NUM_ACCOUNTS (set MAX_NUM_ACCOUNTS to 4)

Account * accountArray[MAX_NUM_ACCOUNTS];

In main, initialize all the elements of the above array with nullptr Loop on displaying the following menu of choices:

  1. Create account
  2. Deposit to account
  3. Withdraw from account
  4. Display information for all accounts
  5. Delete owner
  6. Add owner
  7. Delete account
  8. Quit

 

If the user selects “Create account” on the menu, the program will prompt the user to enter the number of owners and the amount, dynamically allocate an Account object, and store the address of the created object into the first available element of the array of pointers, starting with the one at index 0. Then, owner by owner, the program prompts the user to enter the owner’s info (name, DOB, address) and calls the setOwner mutator to set the owner’s info. If there is no

more available element (i.e. the array is full), no dynamic allocation of an Account object is done, and an error message is displayed. The account number is automatically generated from the static variable accountCounter.

If the user selects “Deposit”, or “Withdraw”, the program prompts the user to enter the account number and amount and checks that the account number exists. If so, it calls the appropriate member function(s). The appropriate error message is printed if an error indication is returned by the member function.

Choices 5, 6 and 7 are placeholders for the extra credit version. For the basic version, if the user selects 5, 6 or 7, the

 

program does nothing and displays the menu again.

If the user selects “Quit”, the main function should release the dynamically allocated Account objects and terminate.

 

  1. Input validation and error messages by main function

 

  • The main function should check the account number exists when the user tries to deposit or If the account does not exist, the main function prints the appropriate specific error message (“No such account”), and no further action is taken. In order to do the checking, your program should perform a search on the account number.
  • The main function should print the appropriate specific error message (“Deposit amount cannot be negative”) if any of the withdraw, deposit member functions returns an error The program does not exit.
  • The main function should check the maximum number of accounts has not been reached (MAX/NUM/ACCOUNTS) when the user attempts to create an If the maximum has been reached, it should display the appropriate

specific error message (“Maximum number of accounts reached”)

 

2.   Extra Credit (15 points)

 

The extra credit is a superset of the basic version.

 

  • Requirements for extra credit

 

Define a global array of pointers to Account, of size MAX_NUM_ACCOUNTS (set MAXNUMACCOUNTS to 4) Account * accountArray[MAXNUMACCOUNTS];

In main, initialize all the elements of the above array with nullptr Loop on displaying the following menu of choices:

  1. Create account
  2. Deposit to account
  3. Withdraw from account
  4. Display information for all accounts
  5. Delete owner
  6. Add owner
  7. Delete account
  8. Quit

 

If the user chooses 1, 2, 3, 4, or 8, the program should behave like in the basic version. If the user chooses 5, the user will be prompted for the account number and the Person to delete. Delete is not performed if there is only one owner in the account. If the user chooses 6, the user will be prompted for the account number and the Person to add. You are

not required to check that Person is already an owner of the account. If the user chooses 7, the user will be prompted for the account to delete. The program prints an error message if the account is not found.

Implement these additional public member functions:

  • addOwner(Person): mutator which takes a Person as an argument and adds that Person as an owner of the

A new array of the right size should be dynamically allocated, all the owner’s info from the current array should be

copied to the new array and the current array released. You are not required to check that Person is already an owner of the account. The relative order of the owners should be preserved, and the newly added owner should be last in the

new array.

  • delOwner(Person): mutator which takes a Person as an argument and deletes that Person from the owner(s) of the account. The function should return an int with value 0, 1 or 2, for the cases of “no error”, “Person not found among the owners” and “delete cannot be performed because there is only one owner left” A new array of the right

size should be dynamically allocated, all the owner’s info from the current array should be copied to the new array and the current array released. The relative order of the owners should be preserved in the new array.

In addition, when the user chooses “Delete account”, the main function should print an error message if the account is not found. Otherwise, delete is performed and all the relevant data should be updated. The Account object should be released. The "Delete account" operation should not result in any gap in the accountArray array, and should preserve the relative order of the elements in the array.

 

3.   Grading Criteria

 

  1. Source code inspection (grader)

 

Style: 10 points (refer to the “Homework Notes” for the style requirements)

Required: Dynamic allocation of Account and assignment to the proper element of the accountArray when an account is created: Deduct 10 points if the requirement is not met

Required: Dynamic allocation of Person array of the right size in Account constructor: Deduct 10 points if the requirement is not met

Required: Use of static variable for accountCounter: Deduct 5 points if the requirement is not met

 

  1. Program compilation and execution (zylabs)

 

Test-1 – Basic case, no error – Output matches output-1: 42 points

Test-2 – withdraw and deposit, Account does not exist – Output matches output-2: 9 points Test-3 – Max number of accounts reached – Output matches output-3: 9 points

Test-4 – withdraw, invalid amounts – Output matches output-4: 9 points Test-5 – deposit, invalid amount - Output matches output-5: 9 points

Test-6 – delete account (Extra credit) – Output matches output-6: 5 points Test-7 – Account-set-getOwners unit tests: 12 points

Test-8 – addOwner unit test (Extra credit): 5 points Test-9 – delOwner unit test (Extra credit): 5 points

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Atharva PatilComputer science

938 Answers

Hire Me
expert
Chrisantus MakokhaComputer science

872 Answers

Hire Me
expert
AyooluwaEducation

628 Answers

Hire Me
expert
RIZWANAMathematics

926 Answers

Hire Me

Get Free Quote!

319 Experts Online