Transcribed TextTranscribed Text

Bank Account Class Preparation Work Class Mortgage is partially shown below. Complete items #1 to as instructed in each item. class MortgageClass { private: int AccountNum;// Account Number string FirstName;// First name of borrower string LastName; // Last name of the borrower /** * Fixed annual interest rate in percent only. */ double rate; /** * Cost of the house to be bought */ double cost; /** * Down payment made by the buyer. */ double downPymnt; /** * Number of years for which mortgage is taken. */ int year; /** Monthly payment */ double MonthlyPayment; public: /*Item # 1 Complete the body of default constructor where all strings are set to “…….. not set”, where …….. is the data variable name All double data are set to 0.0 All integers are set to 0. */ Mortgage( ) { } /* Item #2: Write an explicit constructor that takes arguments to initialize following class data members: AccountNum, FirstName, LastName, rate, cost, downPymnt, and year. Inside the constructor initialize the class member MonthlyPayment by calling a static member function GetMonthlyPayments( ). Assume that this function is already written and it functions correctly. Also do following validations inside the constructor: If variable to initialize AccountNum is negative, then user is informed that account number cannot be negative and account number is set to zero. If variable to initialize rate passed to constructor is 0 or negative, the user is given a message that rate is invalid and rate is set to 4.5. If variable to initialize cost of house passed to constructor is zero or negative, inform user that cost is invalid and set the cost of house to $200,000. If variable to initialize down payment is equal to or more than the cost of house then inform user that down payment data is invalid and set the down payment to 20% of the cost of house. If variable to initialize years passed to the constructor is 0 or negative, then inform user that years passed to constructor is invalid and set years = 30. Item #3 Write a static getInstance member function that reads the mortgage data from a file in same order in which class data members are declared. [See page 1]. GetInstance calls the explicit constructor and return by reference the empty Mortgage instance passed to it. No data validation of data read from file is done in this function as constructor does them anyhow. Item # 4 Write a function that returns amount of mortgage left. The function header is below. Function returns the MonthlyPayment*(year*12 - NumPaymentsMade). Explain why this expression will compute MortgageLeftToPay? Also function does following validations: 1. If parameter NumPaymentsMade is >= year*12 then inform user that Number of Payments Made is invalid. In that case add a throw statement below inside the if block in which validation code is done: throw “Invalid Number of Payments Made”; 2. else if NumPaymentsMade<0 then add a throw statement below inside as below throw “Invalid Number of Payments Made. It cannot be negative” 3. else return MonthlyPayment*(year*12 - NumPaymentsMade) double MortgageLeftToPay(int NumPaymentsMade) { //Instructor Signatures to witness that all these items have been completed and cleared. Description of Assignment 2 Detailed Description Class BankAccount models a customer account in a bank. It has data members and their types as follows: ActNum string type - Account number LastName string type - Last name of account holder FirstName string type - First name of account holder balance double type - amount of money in the account Class Invariant: Class has an invariant that balance class data member cannot be negative. What that means is that invariant is established as soon as constructor finishes constructing object (meaning that call to constructor has ended). Also invariant is established before a mutator or destructor is called and remains established after the mutator call is over. The UML diagram below shows the overall view of some class members. (Do not copy class function headers from the UML diagram. This diagram is supposed to be only schematic and need not follow strict C++ syntax). Additional members required are listed below the diagram. Additional functions that are required but not shown in UML are below: static void getInstance (BankAccount & BA); static void getInstance (Bank ccount & BA, ifstream & in); void print(ostream out = cout); Below we describe all members of the class and requirements from them that your code must establish. Member Data Documentation: Class must have following data members. Their access levels are noted inside square brackets. string ActNum [private] Account number for this account. double balance [private] Money in dollars in the account. string FirstName [private] First name of the account holder string LastName [private] Last name of the account holder All constructors and member function are public. Constructor Descriptions (Table below gives constructor descriptions) BankAccount () Default constructor sets balance to zero, all string data members to "not set value". For example the data member ActNum will be set to "Account Number not set". Data member LastName will be set to "Last Name not set". Follow the same pattern for setting the first name. BankAccount (string actN, string fname, string lname, double bal) Explicit constructor sets all class data members to user defined explicit values. Obeys invariant and if balance is negative then informs user and sets the balance to zero. Parameters: actN is the account number fname is the customer first name lname is the customer last name bal is the customer balance in the account Member Function Description (They are written alphabetically. However, you must code in the following order and do tests as you go along). toString then mutators, then accessors. See details at the end about main function. void deposit (double money) Deposits the money into the account. Ascertains that value passed to this mutator is not negative. Updates the balance if money being deposited is non-zero and positive. No balance update is done otherwise. User is informed accordingly. Parameters: money is the amount that customer is seeking to deposit. string getAccountNumber () Accessor member function getAccountNumber returns the account number. Returns: the account number. double getBalance () Accessor member function getBalance returns the current balance in the account. Returns: the current balance. string getFirstName () Accessor member function getFirstName returns the first name of account holder. Returns: the first name of the account holder. string getFullName () Accessor member function getFullName returns the full name of account holder. Returns: the full name of the account holder. string getLastName () Accessor member function getLastName returns the last name of account holder. Returns: the last name of the account holder. void setAccountNumber (string actN) Sets the account number to a new value. Parameters: actN is the new account number. void setLastName (string lname) Sets the customer last name to a new value. Parameters: lname is the new last name for the account holder. const string toString() Returns the string version of the BankAccount object such that apart from printing full name, account number, the toString function also contains current balance shown to 2 decimal places only and having the dollar sign before the balance. The comma separator for digits for currency is not required, though C++11 has a mechanism to show that. void withdraw (double money) Performs the withdrawal of the money from account so that invariant is obeyed. Therefore by the time action of member function withdrawal is complete the balance data member obeys the invariant. Gives proper message if the program attempts to violate the invariant. Parameters: money is the amount that customer is seeking to withdraw. void print(ostream out=cout) Prints all details of this one bank account to console or output file as the case may be. static void getInstance(BankAccount & BA) The static function getInstance above gets an unfilled BankAccount object BA passed by reference and is filled by this function from keyboard data entry by the user. For model of this function, look up the similar function in Employee class code given to you as a paper copy and also available in content area of D2L. static void getInstance (Bank ccount & BA, ifstream & in); The static function getInstance above gets an unfilled BankAccount object BA passed by reference and is filled by this function from the input file bonded to ifstream object in. The input file format is below: Account Number Last Name First Name Starting Balance Typical data for James Doe in the input file is shown below. 1234 Doe James 20.01 For model of this function, look up the similar function in Employee class code given to you as a paper copy and also available in content area of D2L. Main Function Description Two main functions are to be written. First main function makes calls to all constructors, mutators, and accessors so that all lines of code are executed. Verify from output that all member functions are working correctly. Then rename the first main function as main1. This is because at one time you can only have one function with name main in a C++ program. Now write the second main function, where you use a loop to present a menu to do followings (this will work similar to an ATM machine): 1. Create an account from keyboard data entry 2. Create an account from input file data entry 2. Print account balance to console. [Must have $ sign and 2 digits in output]. 3. Withdraw money 4. Deposit money 5. Print account details to console 6. Print account details to an output file. Account Number Opening balance 7. Print full name of account holder to console only. 8. Print account number only of the account holder to console. 9. Exit Each time menu is presented to the user, user can choose any of the menu items and after completion of that item the menu is presented again. If user tries to use menu items other than 1 and 2 before using 1 and 2, the program should tell them that an instance of BankAccount is yet to be created. This can be done using some Boolean flags.

Solution PreviewSolution Preview

This material may consist of step-by-step explanations on how to solve a problem or examples of proper writing, including the use of citations, references, bibliographies, and formatting. This material is made available for the sole purpose of studying and learning - misuse is strictly forbidden.

int main(int argc, char** argv) {
    BankAccount ba[2];
    int size = 2;
    int selection = 0;
    ifstream in;
    ofstream out;
    string file;
    int acc = -1;
    double amount;
    while (selection != 9) {
       cout << "-->";
       cin >> selection;
       switch (selection){
            case 0:
                cout << "us this format:\nAccount Number\nLast Name\nFirst Name\nStarting Balance\n";
                acc = 0;
            case 1:
                cout << "Enter file name: ";
                cin >> file;
      , ios::in);
                acc = 1;
$50.00 for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Visual Basic Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Upload a file
Continue without uploading

We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats