write a C++ program to calculated four monthly car payment options for customers
ID: 3635564 • Letter: W
Question
write a C++ program to calculated four 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 routines. 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 functions, and one-dimensional arrays.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 float
downPayment Down Payment float
tradeIn Trade in for vehicle float
loanAmt Loan Amount (calculated) float
annualIntRate Annual Interest Rate (fraction) float
annualIntPercent Annual Interest Rate (percent) float
monIntRate Monthly Interest Rate (fraction) float
noMonths Number of Monthly Payments (24, 36, 48 & 60) int
monPayment Monthly Payment float
monIntRate = annualIntRate / 12.0
annualIntPercent = annualIntRate * 100.0
loanAmt = price – downPayment – tradeIn
monPayment = (loanAmt * monIntRate)/(1.0 –(1+monIntRate) –noMonths ) where noMonths = 24, 36, 48, & 60. Note that the exponent in the above equation is negative.
FUNCTIONS
getPrice Get price of vehicle
getInterestRate Get the annual interest rate from the keyboard as a fraction.
getDownPayment Get down payment from keyboard in dollars and cents.
getTradeIn Get trade in from keyboard in dollars and cents
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 routines to perform different functions in the software.
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 $50,000.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 .50. 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 24, 36, 48, and 60 months. The four monthly payments are to be stored in a one-dimensional array. This function is to use return by value.
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 four 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
24 months 9999.99
36 9999.99
48 9999.99
60 9999.99
Explanation / Answer
001 #include 002 #include 003 #include 004 005 using namespace std; 006 007 struct input 008 { 009 float price; 010 float downPayment; 011 float tradeIn; 012 float loanAmt; 013 float annualIntRate; 014 float annualIntPercent; 015 float monIntRate; 016 int noMonths; 017 float monPayment; 018 }; 019 // Functions 020 double CalcMonPayment(input inputdata, double[]); 021 void DisplayLoanSchedule(int&, double[]); 022 float getPrice(); 023 double getInterestRate(); 024 float getDownPayment(float, float); 025 float getTradeIn(float); 026 027 int main() 028 { 029 //declare variables 030 float price; //vehicle price 031 float tradeIn; //trade-in value float downPayment; //down-payment 032 double annualIntRate; //Annual interest rate 033 double monIntRate; //Monthly interest rate double annualIntPercent; //Annual interest percentage 034 float loanAmt; //Loan Amount 035 double monPayment[60]; //Monthly Payment 1-d array 036 int noMonths; //where no Months - 24, 36, 48, 60 037 struct input inputdata; //create an instance of "input" named "inputdata" 038 039 040 inputdata.price = getPrice(); 041 042 inputdata.tradeIn = getTradeIn(inputdata.price); 043 044 inputdata.downPayment = getDownPayment(inputdata.price, inputdata.tradeIn); 045 046 inputdata.annualIntRate = getInterestRate(); 047 048 CalcMonPayment(inputdata, monPayment); 049 050 float annualIntPercent = inputdata.annualIntRate * 100.0; 051 052 loanAmt = inputdata.price - inputdata.tradeIn - inputdata.downPayment; 053 054 coutRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.