Correct the code by using the global variable to move the calculations such as (downPayment = sellingPrice * DOWN_PAYMENT_RATE / 100.0) out of the output function. In fact, those calculations have been done in calcMortgagePayment(). Use the reference parameter when needed.in calcMortgagePayment().

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

#define PROPERTY_TAX_RATE_PER_YEAR 1.25
#define COST_OF_UTILITIES_PER_MONTH 300.00
#define COST_OF_INSURANCE_PER_YEAR 550.00

void inputData(double& sellingPrice, double& interestRate, int& durationOfLoan);

void handleAllComputations(double sellingPrice,
double interestRate,
int durationOfLoan,
double downPaymentRate,
double& downPayment,
double& amountOfLoan,
double& mortgagePayment,
double& propertyTax,
double& costOfInsurance,
double& totalMonthlyHouseCost);

double calculateDownPayment(double sellingPrice, double downPaymentRate);
double calculateAmountOfLoan(double sellingPrice, double downPayment);
double calculateMortgagePayment(double amountOfLoan,
double interestRate,
int durationOfLoan);

void outputResults(double sellingPrice,
double downPayment,
double amountOfLoan,
double interestRate,
int durationOfLoan,
double mortgagePayment,
double propertyTax,
double costOfInsurance,
double totalMonthlyHouseCost);

int main()
{
const double DOWN_PAYMENT_RATE = 20.00;

double sellingPrice = 0.0;
double interestRate = 0.0;
int durationOfLoan = 0;
double downPayment = 0.0;
double amountOfLoan = 0.0;
double mortgagePayment = 0.0;
double propertyTax = 0.0;
double costOfInsurance = 0.0;
double totalMonthlyHouseCost = 0.0;

inputData(sellingPrice, interestRate, durationOfLoan);
handleAllComputations(sellingPrice, interestRate, durationOfLoan,
DOWN_PAYMENT_RATE, downPayment, amountOfLoan,
mortgagePayment, propertyTax, costOfInsurance,
totalMonthlyHouseCost);
outputResults(sellingPrice, downPayment, amountOfLoan, interestRate,
durationOfLoan, mortgagePayment, propertyTax, costOfInsurance,
totalMonthlyHouseCost);

return 0;

void inputData(double& sellingPrice,
double& interestRate,
int& durationOfLoan)
{
    cout << "Enter the selling price: $";
    cin >> sellingPrice;
    cout << "Enter the rate of interest: ";
    cin >> interestRate;
    cout << "Enter the number of years for the loan: ";
    cin >> durationOfLoan;

void handleAllComputations(double sellingPrice,
double interestRate,
int durationOfLoan,
double downPaymentRate,
double& downPayment,
double& amountOfLoan,
double& mortgagePayment,
double& propertyTax,
double& costOfInsurance,
double& totalMonthlyHouseCost)
{
    downPayment = calculateDownPayment(sellingPrice, downPaymentRate);
    amountOfLoan = calculateAmountOfLoan(sellingPrice, downPayment);
    mortgagePayment = calculateMortgagePayment(amountOfLoan, interestRate, durationOfLoan);
    propertyTax = sellingPrice * (PROPERTY_TAX_RATE_PER_YEAR / 100) / 12;
    costOfInsurance = COST_OF_INSURANCE_PER_YEAR / 12;
    totalMonthlyHouseCost = mortgagePayment + COST_OF_UTILITIES_PER_MONTH + propertyTax + costOfInsurance;

double calculateDownPayment(double sellingPrice, double downPaymentRate)
{
    return sellingPrice * downPaymentRate / 100.0;
}

double calculateAmountOfLoan(double sellingPrice, double downPayment)
{
    return sellingPrice - downPayment;

double calculateMortgagePayment(double amountOfLoan,
double interestRate,
int durationOfLoan)
{
    double a = amountOfLoan;
    double i = (interestRate / 100) / 12;
    int n = durationOfLoan * 12;

    double mortgagePayment = (a * i * pow(1 + i, n)) / (pow(1 + i, n) - 1);

    return mortgagePayment;

void outputResults(double sellingPrice,
double downPayment,
double amountOfLoan,
double interestRate,
int durationOfLoan,
double mortgagePayment,
double propertyTax,
double costOfInsurance,
double totalMonthlyHouseCost)
{
    cout << fixed << setprecision(2);
    cout << endl
    << "MONTHLY COST OF HOUSE" << endl
    << endl;
    cout << left << setw(30) << "SELLING PRICE"
    << "$" << right << setw(9) << sellingPrice << endl;
    cout << left << setw(30) << "DOWN PAYMENT" << right << setw(10) << downPayment
    << endl;
    cout << left << setw(30) << "AMOUNT OF LOAN" << right << setw(10)
    << amountOfLoan << endl;
    cout << left << setw(30) << "INTEREST RATE" << right << setw(10)
    << interestRate << "%" << endl;
    cout << left << setw(30) << "TAX RATE" << right << setw(10)
    << PROPERTY_TAX_RATE_PER_YEAR << "%" << endl;
    cout << left << setw(30) << "DURATION OF LOAN (YEARS)" << right << setw(10)
    << durationOfLoan << endl;

    cout << endl
    << "MONTHLY PAYMENT" << endl;
    cout << setw(5) << "" << left << setw(25) << "MORTGAGE" << right << setw(10)
    << mortgagePayment << endl;
    cout << setw(5) << "" << left << setw(25) << "UTILITIES" << right << setw(10)
    << COST_OF_UTILITIES_PER_MONTH << endl;
    cout << setw(5) << "" << left << setw(25) << "PROPERTY TAXES" << right
    << setw(10) << propertyTax << endl;
    cout << setw(5) << "" << left << setw(25) << "INSURANCE" << right << setw(10)
    << costOfInsurance << endl;
    cout << left << setw(30) << ""
    << "__________" << endl;

    cout << setw(30) << ""
    << "$" << right << setw(9) << setprecision(2) << totalMonthlyHouseCost
    << endl;

 

Correct the code by using the global variable to move the calculations such
as (downPayment = sellingPrice * DOWN_PAYMENT_RATE / 100.0) out of
the output function. In fact, those calculations have been done in
calcMortgagePayment().
Use the reference parameter when needed.in calcMortgagePayment(-
Transcribed Image Text:Correct the code by using the global variable to move the calculations such as (downPayment = sellingPrice * DOWN_PAYMENT_RATE / 100.0) out of the output function. In fact, those calculations have been done in calcMortgagePayment(). Use the reference parameter when needed.in calcMortgagePayment(-
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Mathematical functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education