Question

Description 1. This project will create a base account class that has the members: std::string account_code;...

Description

1. This project will create a base account class that has the members:

std::string account_code;

std::string first_name;

std::string last_name;

double balance;

Provide a constructor that initializes ALL members in its initialization list with data passed in as arguments to the constructor. Provide any accessor functions you may need (e.g. to get the account code and balance and to set the balance). In addition, include two pure virtual functions that look like the following:

virtual void monthly_update() = 0;

virtual char type() const = 0;

2. Design and implement the following derived classes that will inherit from account and implement the monthly_update function in the following manner:

Class Name Implementation

simple_account balance *= 1.05

bonus_account balance = balance * (balance > 5000 ? 1.06 : 1.04)

service_account balance = (balance - 5.0) * 1.04

balanced_account balance = balance > 500.0 ? balance * 1.05 : (balance - 5.0) * 1.03

Each derived class will also override the type function to return a single character that describes the type as indicated in (3) below instead of storing the character.

3. Create a factory function or class that reads data in the following fixed format:

account code : 10 characters

first name : 15 characters

last name : 25 characters

type: 1 character balance : numeric 8 digits, decimal place, 2 digits

and uses that data to dynamically allocate and construct one of the derived objects based on the value of type as indicated in the following table:

Type Class to Dynamically Instantiate

‘A’ simple_account

‘B’ bonus_account

‘C’ service_account

‘D’ balanced_account

If the type is an ‘X’, skip the account record. In other words, the account should not be processed by the rest of the program and should not appear in the result.

If the type is anything else, log the error to a file named “account.log”, but DO NOT stop processing the rest of the accounts.

Trim spaces from the right of the first_name and last_name members using the trim library you constructed in assignment 5.

4. Write a manager class that has a std::map> member. Note the use of std::unique_ptr for the “ownership” of the accounts added to the map. This will automatically clean up the accounts when the map goes out of scope.

5. The manager class will have a member function that performs the processing of the accounts.

This processing is laid out as follows:

a) Open a std::ifstream on the file, "account2.dat", which will be supplied to you. If the file does not exist, log this to the "account.log" file and exit the program (presumably using an exception).

b) For each account in the input file, invoke the factory function/class written in part 3. Each object returned from the factory function will then be inserted into the map, using the account as the key. If the account is to be ignored, or if the factory function throws a fatal exception, no account should be inserted into the map (let alone even created). At the end of the stream, proceed with the next step.

c) Open another std::ifstream on the transaction file, “transact.dat”, which has the following format:

account : 10 characters

amount : numeric 8 digits, decimal place, 2 digits

For each record in the transaction file, find the account in the map and apply the transaction amount (which could be negative) to the balance for that account. Output an error to the “account.log” file if he account is not found in the map, but do NOT stop processing the transaction file.

d) When all transactions are processed, iterate through the map and invoke the monthly_update function for each account in the map.

e) Using a std::ofstream, output each account in the map to a new file named "update.dat" in the SAME format as "account2.dat". f) Output the accounts in a "human readable format" to a file, "report.txt". The output format is of your choice, but please include all the members of each account per line (including the type).

6. In your program's main function, instantiate your manager class from part 4, and invoke the member function in (5) to process the records. Remember to take care of any exceptions that could possibly "leak" out.

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

public class Account

{

String account_code;

String first_name;

String last_name;

double balance;

Account(String code, String fname, String lname, double bal)

account_code=code;

first_name=fname;

last_name=lname;

balance=bal;

}

virtual void monthly_update()=0;

virtual char type() const=0;

Add a comment
Know the answer?
Add Answer to:
Description 1. This project will create a base account class that has the members: std::string account_code;...
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
  • please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class...

    please write the code in C++ 2 Base class File 3 Derived class PDF 3.1 Class declaration • The class PDF inherits from File and is a non-abstract class 1. Hence objects of the class PDF can be instantiated. 2. To do so, we must override the pure virtual function clone) in the base class • The class declaration is given below. • The complete class declaration is given below, copy and paste it into your file. . It is...

  • Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type...

    Java Code: 2. Define a class ACCOUNT with the following members: Private members Acno of type int Name of type String Balance of type float Public members void Init) method to enter the values of data members void Show) method to display the values of data members void Deposit(int Amt) method to increase Balance by Amt void Withdraw(int Amt) method to reduce Balance by Amt (only if required balance exists in account) float RBalance() member function that returns the value...

  • he class definition for a Hank Account class, contains the following private data nembers: the name,...

    he class definition for a Hank Account class, contains the following private data nembers: the name, account number (both are character arrays of 30 elements each) alance, and interest rate Cbolth are double). It also have the following public member unctions Bank AccountO: This function is the default constructor. deposito: subsequently adjusts the balance. (balance- balance + amt) withdrawo: This function is passed an amount to withdraw and subsequently adjusts the balance. (balance balance- amt). cale interestO: This function calculates...

  • MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture...

    MAIN OBJECTIVE       Develop a polymorphic banking program using the Account hierarchy created (below). C++ Capture an output. polymorphism. Write an application that creates a vector of Account pointers to two SavingsAccount and two CheckingAccountobjects. For each Account in the vector, allow the user to specify an amount of money to withdraw from the Account using member function debit and an amount of money to deposit into the Account using member function credit. As you process each Account, determine its...

  • Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class...

    Please show it in C++. Thank you! Problem Definition Create an inheritance hierarchy containing base class Account and derived class Savings-Account. Base class Account should include one data member of type double to represent the account balance. The class should provide a constructor that receives an initial baiance and uses it to initialize the data member. The class should provide three member functions. Member function credit should add an amount to the current balance. Member function debit should withdraw money...

  • please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits...

    please write in c++. 4 Derived class JPG 4.1 Class declaration • The class JPG inherits from File and is a non-abstract class. 1. Hence objects of the class JPG can be instantiated. 2. To do so, we must override the pure virtual function clone() in the base class. • The class declaration is given below. class JPG : public File { public: JPG(const std::string& n, int n, int w, const double rgb()) : File(...) { // ... } *JPG()...

  • Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes....

    Introduction Extend the inheritance hierarchy from the previous project by changing the classes to template classes. Do not worry about rounding in classes that are instantiated as integer classes, you may just use the default rounding. You will add an additional data member, method, and bank account type that inherits SavingsAc-count ("CD", or certicate of deposit). Deliverables A driver program (driver.cpp) An implementation of Account class (account.h) An implementation of SavingsAccount (savingsaccount.h) An implementation of CheckingAccount (checkingaccount.h) An implementation of...

  • Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment...

    Purpose: Demonstrate the ability to create and manipulate classes, data members, and member functions. This assignment also aims at creating a C++ project to handle multiple files (one header file and two .cpp files) at the same time. Remember to follow documentation and variable name guidelines. Create a C++ project to implement a simplified banking system. Your bank is small, so it can have a maximum of 100 accounts. Use an array of pointers to objects for this. However, your...

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

    Need help please!.. C++ programDesign a bank account class named Account that has the following private member variables: accountNumber of type int ownerName of type string balance of type double transactionHistory of type pointer to Transaction structure (structure is defined below) numberTransactions of type int totalNetDeposits of type static double.The totalNetDeposits is the cumulative sum of all deposits (at account creation and at deposits) minus the cumulative sum of all withdrawals. numberAccounts of type static intand the following public member...

  • Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;   ...

    Time.cpp: #include "Time.h" #include <iostream> using namespace std; Time::Time(string time) {    hours = 0;    minutes = 0;    isAfternoon = false;    //check to make sure there are 5 characters    if (//condition to check if length of string is wrong)    {        cout << "You must enter a valid military time in the format 00:00" << endl;    }    else    {        //check to make sure the colon is in the correct...

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