Here is an example of how to archive your files with the tar command. If you hav
ID: 3624777 • Letter: H
Question
Here is an example of how to archive your files with the tar command. If you
have additional files, include them in the archive.
tar –czvf pa6.tgz pa6.cpp loan.h loan.cpp amortized_loan.h amortized_loan.cpp simple_loan.h simple_loan.cpp pa6functions.h pa6functions.cpp
PROGRAM OBJETIVES:
The objectives of this assignment are as follows.
1. Test your ability to design software and/or hardware to meet desired needs (measurable
outcome (d)).
2. Test your ability to identify, formulate, and solve computer science and engineering
problems (measurable outcome (f)).
Value
This program is worth 15 points. The distribution of points will be as follows.
Criterion Value
Global functions 1
Loan hierarchy 5
Output file 2
Program style 2
Correct output with annotation 4
Greeting 1
Problem
Input
A text file containing data for one or more loans. Each line of the file contains data for a single
loan. The data is space delimited and includes the principal, annual interest, and length of loan in years in that order. For example,
35000 7.5 6
Notice that interest as a percent is a number in the range [0, 100]. It must be normalized for the computations by dividing by 100.
Output
Compute monthly payment for each type of loan (amortized and simple), then do the following.
1. Display the loan data including type and monthly payment in the following format.
Loan type: Amortized
Principal: $35000
Interest rate: 7.5%
Length in years: 6
Monthly payment: $605.15
2. Write to a text file the loan data for each type in the following format.
LOAN TYPE PRINCIPAL INTEREST LENGTH MONTHLY PAYMENT
Amortized 35000.00 7.5 6 605.15
Executable requirements
Your program must do the following.
1. Present a greeting.
2. Read the data from the input file and store it in a darray of type principals, where principals is a
struct. The name of the file that contains the data is listed in positional parameter argv[1].
3. Create a darray of type pointer to loan, where each element points to a loan (amortized and
simple for each line of data). Notice the type of the darray is a base class pointer.
4. Compute the monthly payments for the loans.
5. Display all the loan parameters using a polymorphic display function from the loan hierarchy.
Make sure your display is annotated as above.
6. Write the loan data per the above format to a file listed in positional parameter argv[2].
Minimum class requirements
1. Your loan class must be an abstract base class. A good candidate for at least one pure virtual function is the one that computes monthly payments.
2. The loan class must maintain protected data members, principal, yearly rate, loan length in years, monthly payment and type. Use std::string to represent the type of the loan.
3. The base class must include public members to get each of the protected data.
Explanation / Answer
#include "stdafx.h" #include #include #include using namespace std; struct principals { double amount; double rate; int years; }; class loan { protected: double principle; double interest_rate; int lengthin_years; double monthly_pay; public: loan(double p,double i,int y) { principle=p; interest_rate=i/100; lengthin_years=y; } double getp() { return principle; } double geti() { return interest_rate; } int getl() { return lengthin_years; } double getm() { return monthly_pay; } virtual void calcmonthlypay(); virtual void display(); }; class simple_loan :public loan { private: string type; public: simple_loan(){} simple_loan(struct principals p):loan(p.amount,p.rate,p.years) { type="simple"; } string gettype() { return type; } void calcmonthlypay() { monthly_pay=(principle*(interest_rate*lengthin_years+1))/lengthin_years; } void display() { coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.