You are to write a C++ program to calculated five monthly car payment options fo
ID: 3769316 • Letter: Y
Question
You are to write a C++ program to calculated five monthly car payment options for customers of Honest Dave’s Used Cars. By now you should have a good idea about functional decomposition and constructing programs in a building block fashion. Thus you are to develop the code as independent modules. You should have a small “driver” main module with a series of calls that invokes the various functions. You are to USE NO GLOBAL VARIABLES in your work. You should manually (by hand with pencil and paper) calculate some values to ensure that your program is working correctly. It is important that you demonstrate a working knowledge in the use of for loops, do/while loops, return by value and void functions, and one-dimensional arrays. Stick to the specifications!
In the following sequence, you are to prompt the user for:
Price of the vehicle.
Trade-in value.
Down-payment.
Annual interest rate.
Variable
Description
Data Type
price
Price of vehicle (input)
float
downPayment
Down Payment (input)
float
tradeIn
Trade In (input)
float
loanAmt
Loan Amount (calculated)
float
annualIntRate
Annual Interest Rate (input-fraction)
float
annualIntPercent
Annual Interest Rate (calculated-percent)
float
monIntRate
Monthly Interest Rate (calculated-fraction)
float
noMonths
Number of Monthly Payments (12, 24, 36, 48 & 60)
int
monPayment[5]
Monthly Payment (calculated array)
float
monIntRate = annualIntRate / 12.0
annualIntPercent = annualIntRate * 100.0
loanAmt = price – downPayment – tradeIn
monPayment = (loanAmt * monIntRate)/(1.0 –(1+monIntRate) –noMonths ) where noMonths = 12, 24, 36, 48, & 60. Note that the exponent in the above equation is negative.
FUNCTIONS
getPrice
Get price of vehicle
getDownPayment
Get down payment from keyboard in dollars and cents.
getTradeIn
Get trade in from keyboard in dollars and cents
getInterestRate
Get the annual interest rate from the keyboard as a decimal fraction.
calcMonPayment
Calculate the monthly payments using the supplied equation
displayLoanSchedule
Display the pertinent loan data and calculation results
Your programming manager has directed you to produce “small” independent functions to perform important software requirements. All of the get (input) functions must keep the user in the do/while loop until the input is a “legal” value.
1. Get price function.
getPrice
You are to use a do/while loop to get the value from the keyboard. You are to edit the input value to ensure that the price value is greater than $50.00 and less than or equal to $44,500.00. You are to use a return by value function.
2. Get trade in function.
getTradeIn
You are to use a do/while loop to get the value from the keyboard. You are to edit the input value to ensure that the tradeIn value is greater than or equal to zero and less than the price. The getTradeIn function should be a return by value.
3. Get down payment function.
getDownPayment
You are to use a do/while loop to get the value from the keyboard. You are to edit the input value to ensure that the downPayment value is greater than or equal to zero and less than the price minus the trade in. The downPayment is to be return to the calling program via a return by value
4. Get interest rate function
getInterestRate
You are to use a do/while loop to get the value from the keyboard. The interest rate is to be entered as a decimal fraction. For example .06 would be entered rather than 6%. The annual interest rate must be greater than zero and be less than or equal to .16 (16%). This function is to use return by value.
5. Calculate monthly loan payment
calcMonPayment
You are to use the monPayment equation as the basis of a function to calculate the monthly payment amount. You are to calculate a monthly payment based upon 12, 24, 36, 48, and 60 months. The five monthly payments are to be stored in a one-dimensional array. This is a return by value function.
6. Display the loan schedule
displayLoanSchedule
You are to display the pertinent loan information. The report format and contents are shown below. A for loop is to be used to display the five monthly payments. The displayLoanSchedule is to be a void function.
You are to align your columns (this example may not be aligned correctly) and display two places to the right of the decimal. You are given the following report example.
Honest Dave’s Used Cars
Vehicle price 99999.99
Trade in value 99999.99
Down payment 99999.99
--------------
Loan amount 99999.99
Annual interest rate 99.99%
Monthly payment options
12 months 9999.99
24 9999.99
36 9999.99
48 9999.99
60 9999.99
Variable
Description
Data Type
price
Price of vehicle (input)
float
downPayment
Down Payment (input)
float
tradeIn
Trade In (input)
float
loanAmt
Loan Amount (calculated)
float
annualIntRate
Annual Interest Rate (input-fraction)
float
annualIntPercent
Annual Interest Rate (calculated-percent)
float
monIntRate
Monthly Interest Rate (calculated-fraction)
float
noMonths
Number of Monthly Payments (12, 24, 36, 48 & 60)
int
monPayment[5]
Monthly Payment (calculated array)
float
Explanation / Answer
ANSWER:
/*** C++ PROGRAM TO CALCULATED FIVE MONTHLY CAR PAYMENT OPTIONS FOR CUSTOMERS OF HONEST DAVE’S USED CARS */
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
//FUNCTION RETURN THE PRICE OF THE VEHICLE
float getPrice()
{
float price;
do
{
cout << "ENTER VEHICLE PRICE: ";
cin >> price;
if (price > 44500.00 || price < 50.0)
cout << "INVALID PRICE." << endl;
}
while (price > 44500.00 || price < 50.0);
return price;
}
//RETURN THE TRADE IN VALUE OF THE VEHICLE
float getTradeIn(float price)
{
float tradeIn;
do
{
cout << "ENTER TRADE-IN VALUE: ";
cin >> tradeIn;
if (tradeIn < 0 || tradeIn >= price)
{
cout << "INVALID TRADEIN" << endl;
}
}
while (tradeIn <0 || tradeIn >= price);
return tradeIn;
}
//RETURN THE DOWN PAYMENT OF THE VEHICLE
float getDownPayment(float price, float tradeIn)
{
float downPayment;
do
{
cout << "ENTER DOWN PAYMENT: ";
cin >> downPayment;
if (downPayment < 0 || downPayment > (price - tradeIn))
{
cout << "INVALID DOWN PAYMENT" << endl;
}
}
while (downPayment < 0 || downPayment > (price - tradeIn));
return downPayment;
}
//RETURN THE INTEREST RATE
double getInterestRate()
{
double annualIntRate;
do
{
cout << "ENTER INTEREST RATE (EG. 6% SHOULD BE ENTERED AS .06):";
cin >> annualIntRate;
if (annualIntRate < 0 || annualIntRate >= 0.16)
cout << "INVALID INTEREST RATE";
}
while (annualIntRate < 0 || annualIntRate >= 0.16);
return annualIntRate;
}
//CALCULATES THE PAYMENT FOR THE GIVEN MONTHS
float calcMonPayament(float loanAmt,float monIntRate,int noMonths)
{
float pay= (loanAmt * monIntRate)/(1.0 -pow((1+monIntRate),-noMonths));
return pay;
}
//DISPLAY THE MONTHLY LOAN AMOUNTS
void DisplayLoanSchedule(float monPayment[5])
{
int noMonths = 12;
int k1;
for (k1 = 0; k1 <5; k1 ++)
{
cout << setw (30) << noMonths << " Months" << fixed << setprecision(2) << setw(20) << monPayment[k1] << endl;
noMonths += 12;
}
}
//MAIN METHOD
int main()
{
//DECLARE VAIABLES
float price;
float downPayment;
float tradeIn;
float loanAmt;
float annualIntRate;
float annualIntPercent;
float monIntRate;
int noMonths;
float monPayment[5];
price=getPrice();
tradeIn=getTradeIn( price);
downPayment=getDownPayment(price, tradeIn);
loanAmt = price-downPayment-tradeIn;
annualIntRate=getInterestRate();
annualIntPercent=annualIntRate * 100.0;
monIntRate=annualIntRate / 12.0;
noMonths=12;
for(int k1=0;k1<5;k1++)
{
monPayment[k1]=calcMonPayament(loanAmt,monIntRate,noMonths);
noMonths+=12;
}
cout << setw(50) << "***** Honest Dave's Used Cars *****";
cout << endl;
cout << endl;
cout << setw (30) << "VEHICLE PRICE" << fixed << setprecision(2) << setw(20) << price << endl;
cout << setw (30) << "TRADE IN VALUE" << fixed << setprecision(2) << setw(20) << tradeIn << endl;
cout << setw (30) << "DOWN PAYMENT" << fixed << setprecision(2) << setw(20) << downPayment << endl;
cout << setw (30) << "LOAN AMOUNT" << fixed << setprecision(2) << setw (20) << loanAmt << endl << endl;
cout << setw (30) << "ANNUAL INTEREST RATE" << fixed << setprecision(2) << setw(20) << annualIntPercent << "%" << endl << endl;
cout << setw (50) << "MONTHLY PAYMENT OPTIONS ";
DisplayLoanSchedule(monPayment);
return 0;
}
OUTPUT:
ENTER VEHICLE PRICE: 40000
ENTER TRADE-IN VALUE: 10000
ENTER DOWN PAYMENT: 15000
ENTER INTEREST RATE (EG. 6% SHOULD BE ENTERED AS .06):0.06
***** Honest Dave's Used Cars *****
VEHICLE PRICE 40000.00
TRADE IN VALUE 10000.00
DOWN PAYMENT 15000.00
LOAN AMOUNT 15000.00
ANNUAL INTEREST RATE 6.00%
MONTHLY PAYMENT OPTIONS
12 Months 1291.00
24 Months 664.81
36 Months 456.33
48 Months 352.28
60 Months 289.99
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.