Hey guys, im tryig to finish a homework project so i can study it for an upcomin
ID: 3706087 • Letter: H
Question
Hey guys, im tryig to finish a homework project so i can study it for an upcoming test, but ive come across this problem that im not sure how to write a code for. i need a copy of code, and output in C++. below ive attached what the program needs to do. thanks so much!
You must use Constructors and Destructors with messages.
You must code “Object Oriented Programming” with class specification (.h) class implementation (.cpp), and main () function..
a. For instances - Car Loan:
Example (1) 5 years, $45000 car loan including tax and fee,
And annual interest rate: 6%
Example (2) 6 years, $30000 car loan including tax and fee,
And annual interest rate: 5%
If you have a car loan or mortgage loan, check this out to see if your payment is correct.
(No need to do the following: Your actual monthly payment will include Insurance premium and property tax escrow if it is for mortgage.)
b. Use menu options to input data or display the various output and monthly payment month by month.
You need to display monthly payment, monthly interest, monthly principle payment, and monthly balance for all months during the loan period.
Explanation / Answer
Solution:
code:
#include <iostream>
#include <math.h>
using namespace std;
class LoanPay
{
public:
void setloanamount(double);
void setrate(double);
void setyears(double);
double PayCal(void);
double totalpayment(double);
private:
double rate, loan, years;
};
int main()
{
LoanPay x;
double value,payment,totalpaid,y,loan;
cout.setf(ios::fixed,ios::floatfield);
cout.precision(2);
cout<<"How much is the loan for? ";
cin>>loan;
x.setloanamount(loan);
cout<<"What is the interest rate (as a % ie: 5.2)?";
cin>>value;
x.setrate(value);
cout<<"How many years is the loan for ";
cin>>y;
x.setyears(y);
payment=x.PayCal();
cout<<"Your monthly payment is:"<<payment<<endl;
totalpaid=x.totalpayment(payment);
cout<<"The total amount of interest payed to the bankis: $"<<totalpaid<<endl;
cout<<"The total amount payed back to the bank(principal+interest) is: $"<<totalpaid+loan<<endl;
system("pause");
return 0;
}
void LoanPay::setrate(double n)
{
rate=n/100.;
}
void LoanPay::setloanamount(double n)
{loan=n;
}
void LoanPay::setyears(double n)
{years=n;
}
double LoanPay::PayCal()
{double term,payment;
term=(1.+pow((rate/12.),12*years));
payment=(loan*rate/12.*term)/term-1.;
return payment;
}
double LoanPay::totalpayment(double p)
{return p*(12.*years);
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)