Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / As you write your program code, you will separate your code into different files

As you write your program code, you will separate your code into different files

Computer Science

As you write your program code, you will separate your code into different files. You will create header files and cpp source files for each class. You will place the class declaration in a header file, and your class method implementations will go in a cpp source file. Your main function will go in yet another cpp source file. All of your cpp source files will include your header files as needed.

**Each task should at least have 3 or more files, 2 cpp files and 1 header file. You may reuse your code to accomplish each task. i.e., the code in task 1 can be reused in task 2 and 3.

Standard Template Library and Iterators

Task#1: Upgrade the bank system to handle more than one account.

 

  1. Add the ability to store more than one account to your bank program. You should use one of the Standard Template Library containers to hold the accounts. You may select which type of container to use. The list container type is recommended. Your program should no longer automatically create an account when it starts. You will only create a new account when the user selects this as an option. You should create a new menu option that will enable the user to create a new account. Once the new account is added, store the new account in your container.
  2. Change the "Display account information" menu option to show all account information instead of just one account. When this option is selected, all of the stored accounts are shown. Use iterators to implement this option.
  3. Add the ability to search through the container of accounts for a specific account and display the information associated with the account. Use iterators to find the account. If the account doesn't exist in the list, then display an appropriate error message. You may want to create a function that finds the desired account because you can reuse it later.
  4. Fix the add deposit and withdrawal options by reusing the code that searches for an account, then apply the desired operation to that account.

 

Example Output.

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
Your choice: 4
Enter the name: George
Enter the balance: 100

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
Your choice: 4
Enter the name: Harry
Enter the balance: 200

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
Your choice: 2
Enter the ID of the account to find: 0
Found account: Account ID: 0 Name: George Balance: $100.00
Amount to deposit: 15

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
Your choice: 3
Enter the ID of the account to find: 1
Found account: Account ID: 1 Name: Harry Balance: $200.00
Amount to withdraw: 25

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
Your choice: 1
Account ID: 0 Name: George Balance: $115.00
Account ID: 1 Name: Harry Balance: $175.00

 

 

Algorithms

Task#2: Upgrade the bank system to include additional operations: remove an account, show total bank deposits, and pay dividends.

 

  1. Rewrite the menu option to display account information to use for_each instead of iterators.
  2. Add a menu option to remove an account from the system. Use remove_if to perform this operation. After calling remove_if, erase the removed elements permanently from the container. NOTE: some containers are not compatible with remove_if. For these containers, you should use erase_if instead.
  3. Add a menu option to determine the total amount of deposits in the system. Use accumulate to accomplish this part of the task.
  4. Add a menu option to add a dividend to all of the accounts. The dividend is calculated as a simple percentage of the current balance. Have the user enter the amount of the dividend as a percentage. Use transform to accomplish this task. You could add a new operator *= to your account class to make this task easier. NOTE: some containers are not compatible with transform. For these containers, use for_each instead.

 

Example Output

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
Your choice: 4
Enter the name: George
Enter the balance: 100

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
Your choice: 4
Enter the name: Harry
Enter the balance: 200

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
Your choice: 8
Enter the dividend as a percentage: 5

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
Your choice: 1
Account ID: 0 Name: George Balance: $105.00
Account ID: 1 Name: Harry Balance: $210.00

 

 

Smart Pointers

Task#3: Upgrade the bank system to include contact information.

  1. We now want to add contact information to each account. We'll do this with an additional class. This new contact class will have the following data members:
  • street address (string)
  • city (string)
  • state (string)
  • zip code (string)
  • phone number (string)

This contact class will have a constructor that takes no parameters. In this constructor, all of the data values will be given blank values or empty strings.

This contact class will have a copy constructor that copies all of the data members from one instance to another. The source instance should be passed by reference.

This contact class will have a destructor. This destructor will have an empty body. We'll add more code here later.

This contact class will have a method to ask the user for the values to store in the data members.

This contact class will also have a method to show the data members. This method will take an output stream reference as a parameter and return the same stream reference as the return value.

The account class will contain an additional data member: a smart pointer that contains the contact information. In the constructors for the account class, initialize this smart pointer to nullptr.

Add a method to the account class that is used to add the contact info. This must be done as a method in the account class because we are modifying a data member of the class.

Add a menu item to attach contact information to an account. This menu option will find an account to modify, and call the method to add the contact information.

  1. In the output method of the account class, call the output for the contact information, if it's been attached.
  2. Add cout messages to the destructors for the account class and the contact class. Verify that when an account is removed from the system, any attached contact information is also removed. This can be verified by watching for the destructor messages. If smart pointers have been used properly, no further coding will be needed for this part. NOTE: you might see more messages from the account destructor than you expect. These extra messages come from the creation and destruction of temporary variables used as a normal side effect of using containers. The important thing to watch for is that messages from the contact destructor are only seen when the associated account is removed entirely from the system.

 

Example Output

 

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
9. Add contact information to an account
Your choice: 4
Enter the name: George
Enter the balance: 100
In Account destructor (name is George)

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
9. Add contact information to an account
Your choice: 4
Enter the name: Harry
Enter the balance: 200
In Account destructor (name is Harry)

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
9. Add contact information to an account
Your choice: 9
Enter the ID of the account to find: 1
Found account: Account ID: 1 Name: Harry Balance: $200.00
Enter Address: 123 Main St
Enter City: Nowhere
Enter State: UT
Enter Zip Code: 84000
Enter Phone Number: 123-456-7890

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
9. Add contact information to an account
Your choice: 1
Account ID: 0 Name: George Balance: $100.00
Account ID: 1 Name: Harry Balance: $200.00
+ Contact Information: Address: 123 Main St City: Nowhere State: UT Zip: 84000 Phone: 123-456-7890

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
9. Add contact information to an account
Your choice: 6
Enter account ID to remove: 1
In Account destructor (name is Harry)
In Contact destructor (address is 123 Main St)

Account Menu:
0. Quit Program
1. Display Account Information
2. Add a deposit to an account
3. Withdraw from an account
4. Add new account
5. Find account by ID
6. Remove account
7. Show total balance for all accounts
8. Add a dividend to all accounts
9. Add contact information to an account
Your choice: 1
Account ID: 0 Name: George Balance: $100.00

 

Option 1

Low Cost Option
Download this past answer in few clicks

28.99 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE

Related Questions