Expert answer:Hello, I finished coding my program which is 3 financial calculators, however i got a request to add a fourth one, everything is done in the code the only thing that you need to do is adding the fourth calculator. I attached a file that explains what you have to do and also attached the .cpp file for the project. if you want me to send you anything you need just hit me up.
homework_3__finanical_calculators__additional_user_requirement.pdf
source_code.txt
Unformatted Attachment Preview
Homework #3—Financial Calculators (Additional User Requirement)
Instructor: Michael D. Falkow, PMP
CPSC 120
Fall 2017
Now that you have (almost) completed your Financial Calculators program, it is time to realize
what often happens in the real world of software development. Many times you will do exactly
what the detailed design documents specify, your program will work perfectly in every way, and
your life will seem like a bed of roses. Then, at the last minute, just when you are about to
deliver the final product in the proverbial eleventh hour, the user will make additional demands
necessitating that you change your program. Sometimes, these changes will be minor. Other
times, they will be very significant.
For this assignment, you have been given a new requirement. The user has decided that your
amortization table output is wonderful (or will be wonderful), but you need to build in another
function that reads the 15- and 30-year mortgage files you create and performs a checksum
operation on the principle paid and interest paid columns.
To accomplish this, you need to add a new option to your menu. This new option will call a
function you create asking the user if they would like to verify and validate either the 15-year
amortization schedule or the 30-year amortization schedule. Based upon this response, the
function should then request the appropriate file name and read in all the data into a two
dimensional array (Hint: Read in the header information first). Once you have populated the 2D array with all the data (or while you are performing this operation), you need to sum all the
values in the Principle Paid and Interest Paid columns and compare them to the running totals
you calculated (e.g., the ending values in your table for the running totals). The user wants you
to output the difference to the screen (e.g., your running totals minus the sums you calculate).
Once this operation is complete, your program should return to the main menu leaving the output
file untouched.
If you used a partner for Homework #2, you are to use the same one. If you did Homework #2
solo, you must do Homework #3 solo also.
You are to upload your updated .cpp file only (e.g., no report, screenshots, pseudocode, etc.).
This additional user requirement is worth 100 points.
Page 1 of 1
#include
#include
#include
#include
#include
using namespace std;
// Calculates and displays the new amount after a period
void compound_interest(string user_name) {
float principal, rate, result, time;
cout << "Enter the amount to invest/save: ";
cin >> principal;
cout << "Enter the time period (in years): ";
cin >> time;
cout << "Enter the expected annual rate of return: ";
cin >> rate;
result = (principal*(exp(rate * time)));
std::cout.imbue(std::locale(“”));
std::cout << endl << user_name << " you will save " << std::fixed << std::setprecision(2) << result << " in " << time << " years." << endl << endl;
char table = 'n';
cout << "Do you want to see a table of each year? (y/n) ";
cin >> table;
float previous = principal;
// Generate a table?
if (table == ‘y’) {
cout << setw(7) << "Year" << setw(30) << "Beginning Investment" << setw(30) << "New Investment Value" << setw(20) << "Amount Earned" << setw(20) << "Total Earnings" << endl;
for (int i = 1; i <= time; i++) {
result = (principal*(exp(rate * i)));
std::cout << setw(7) << i << setw(30) << std::fixed << std::setprecision(2) << principal << setw(30) << std::fixed << std::setprecision(2) << result << setw(20) << std::fixed << std::setprecision(2) << result - previous << setw(20) << std::fixed << std::setprecision(2) << result - principal << endl;
previous = result;
}
}
char file = 'n';
cout << "Do you want to save it in a file? (y/n) ";
cin >> file;
// Generate a file?
if (file == ‘y’) {
string filename;
cout << "Enter the filename: ";
cin >> filename;
ofstream myfile;
myfile.open(filename);
float previous = principal;
myfile << setw(7) << "Year" << setw(30) << "Beginning Investment" << setw(30) << "New Investment Value" << setw(20) << "Amount Earned" << setw(20) << "Total Earnings" << endl;
for (int i = 1; i <= time; i++) {
result = (principal*(exp(rate * i)));
myfile << setw(7) << i << setw(30) << std::fixed << std::setprecision(2) << principal << setw(30) << std::fixed << std::setprecision(2) << result << setw(20) << std::fixed << std::setprecision(2) << result - previous << setw(20) << std::fixed << std::setprecision(2) << result - principal << endl;
previous = result;
}
myfile.close();
}
}
// Calculates the payments and interest for a loan
void fixed_rate_mortgage(string user_name) {
float principal, rate, result, time, month_payment;
cout << "Enter the loan amount: ";
cin >> principal;
cout << "Enter the time period (in years): ";
cin >> time;
cout << "Enter the annual rate: ";
cin >> rate;
float month_rate = rate / 12;
time = time * 12;
month_payment = principal*month_rate*pow((1+month_rate),time)/(pow((1 + month_rate), time)-1);
result = month_payment;
std::cout.imbue(std::locale(“”));
std::cout << endl << user_name << " the monthly payment amount is " << std::fixed << std::setprecision(2) << result << " in " << time << " months." << endl << endl;
char table = 'n';
cout << "Do you want to see a table of each year? (y/n) ";
cin >> table;
float balance = principal;
float interest_amount;
float principle_amount = 0;
float new_balance = principal;
// Generate a table?
if (table == ‘y’) {
cout << setw(7) << "Pmt No." << setw(20) << "Loan Balance" << setw(20) << "Monthly Payment" << setw(20) << "Interest Amount" << setw(20) << "Principle Amount" << setw(20) << "New Balance" << endl;
for (int i = 1; i <= time; i++) {
interest_amount = new_balance * month_rate;
principle_amount = month_payment - interest_amount;
new_balance = balance - principle_amount;
if (new_balance < 0) {
new_balance = 0;
}
std::cout << setw(7) << i << setw(20) << std::fixed << std::setprecision(2) << balance << setw(20) << std::fixed << std::setprecision(2) << month_payment << setw(20) << std::fixed << std::setprecision(2) << interest_amount << setw(20) << std::fixed << std::setprecision(2) << principle_amount << setw(20) << std::fixed << std::setprecision(2) << new_balance << endl;
balance = new_balance;
}
}
char file = 'n';
cout << "Do you want to save it in a file? (y/n) ";
cin >> file;
// Generate a file?
if (file == ‘y’) {
string filename;
cout << "Enter the filename: ";
cin >> filename;
ofstream myfile;
myfile.open(filename);
myfile << setw(7) << "Pmt No." << setw(20) << "Loan Balance" << setw(20) << "Monthly Payment" << setw(20) << "Interest Amount" << setw(20) << "Principle Amount" << setw(20) << "New Balance" << endl;
for (int i = 1; i <= time; i++) {
interest_amount = new_balance * month_rate;
principle_amount = month_payment - interest_amount;
new_balance = balance - principle_amount;
if (new_balance < 0) {
new_balance = 0;
}
myfile << setw(7) << i << setw(20) << std::fixed << std::setprecision(2) << balance << setw(20) << std::fixed << std::setprecision(2) << month_payment << setw(20) << std::fixed << std::setprecision(2) << interest_amount << setw(20) << std::fixed << std::setprecision(2) << principle_amount << setw(20) << std::fixed << std::setprecision(2) << new_balance << endl;
balance = new_balance;
}
myfile.close();
}
}
// Calculates the payments and interest for a loan
void auto_loan(string name) {
float principal, rate, result, time, month_payment;
cout << "Enter the loan amount: ";
cin >> principal;
cout << "Enter the time period (in years): ";
cin >> time;
cout << "Enter the annual rate: ";
cin >> rate;
float month_rate = rate / 12;
time = time * 12;
month_payment = principal*month_rate*pow((1 + month_rate), time) / (pow((1 + month_rate), time) – 1);
result = month_payment;
std::cout.imbue(std::locale(“”));
std::cout << endl << name << " the monthly payment amount is " << std::fixed << std::setprecision(2) << result << " in " << time << " months." << endl << endl;
char table = 'n';
cout << "Do you want to see a table of each year? (y/n) ";
cin >> table;
float balance = principal;
float interest_amount;
float principle_amount = 0;
float new_balance = principal;
// Wants to generate a table?
if (table == ‘y’) {
cout << setw(7) << "Pmt No." << setw(20) << "Interest Amount" << setw(20) << "Principle Amount" << setw(20) << "Balance" << endl;
// Prints each line for each payment
for (int i = 1; i <= time; i++) {
interest_amount = new_balance * month_rate;
principle_amount = month_payment - interest_amount;
new_balance = balance - principle_amount;
if (new_balance < 0) {
new_balance = 0;
}
std::cout << setw(7) << i << setw(20) << std::fixed << std::setprecision(2) << interest_amount << setw(20) << std::fixed << std::setprecision(2) << principle_amount << setw(20) << std::fixed << std::setprecision(2) << new_balance << endl;
balance = new_balance;
}
}
char file = 'n';
cout << "Do you want to save it in a file? (y/n) ";
cin >> file;
// Wants to generate a file?
if (file == ‘y’) {
string filename;
cout << "Enter the filename: ";
cin >> filename;
ofstream myfile;
myfile.open(filename);
myfile << setw(7) << "Pmt No." << setw(20) << "Interest Amount" << setw(20) << "Principle Amount" << setw(20) << "Balance" << endl;
// Save each line in the file
for (int i = 1; i <= time; i++) {
interest_amount = new_balance * month_rate;
principle_amount = month_payment - interest_amount;
new_balance = balance - principle_amount;
if (new_balance < 0) {
new_balance = 0;
}
myfile << setw(7) << i << setw(20) << std::fixed << std::setprecision(2) << interest_amount << setw(20) << std::fixed << std::setprecision(2) << principle_amount << setw(20) << std::fixed << std::setprecision(2) << new_balance << endl;
balance = new_balance;
}
myfile.close();
}
}
// Displays the menu and returns the option entered by the user
int menu() {
int opt = 0;
cout << endl << "----------------------------------------------------------" << endl;
cout << " Financial Calculator " << endl;
cout << "----------------------------------------------------------" << endl << endl;
cout << "1. Compound Interest Calculator with Breakdown" << endl << endl;
cout << "2. Mortage Calculator with Amortization Schedule" << endl << endl;
cout << "3. Auto Loan Calculator with Amortization Schedule" << endl << endl;
cout << "4. Exit" << endl << endl;
cout << "Enter an option: ";
cin >> opt;
return opt;
}
int main() {
int opt = 0;
string name;
while (true) {
// Calls the menu
opt = menu();
// First option
if (opt == 1) {
cout << "Enter your name: ";
cin.ignore();
getline(cin, name);
compound_interest(name);
}
// Second option
else if (opt == 2) {
cout << "Enter your name: ";
cin.ignore();
getline(cin, name);
fixed_rate_mortgage(name);
}
// Third option
else if (opt == 3) {
cout << "Enter your name: ";
cin.ignore();
getline(cin, name);
auto_loan(name);
}
// Exit
else if (opt == 4) {
break;
}
// Invalid option
else {
cout << "Invalid option";
}
}
return 0;
} ...
Purchase answer to see full
attachment
You will get a plagiarism-free paper and you can get an originality report upon request.
All the personal information is confidential and we have 100% safe payment methods. We also guarantee good grades
Delivering a high-quality product at a reasonable price is not enough anymore.
That’s why we have developed 5 beneficial guarantees that will make your experience with our service enjoyable, easy, and safe.
You have to be 100% sure of the quality of your product to give a money-back guarantee. This describes us perfectly. Make sure that this guarantee is totally transparent.
Read moreEach paper is composed from scratch, according to your instructions. It is then checked by our plagiarism-detection software. There is no gap where plagiarism could squeeze in.
Read moreThanks to our free revisions, there is no way for you to be unsatisfied. We will work on your paper until you are completely happy with the result.
Read moreYour email is safe, as we store it according to international data protection rules. Your bank details are secure, as we use only reliable payment systems.
Read moreBy sending us your money, you buy the service we provide. Check out our terms and conditions if you prefer business talks to be laid out in official language.
Read more