/ Published in: C++
Expand |
Embed | Plain Text
// filename: Loan.cpp // name: Devon Blandin // CSC 261 - Homework #6 // Description: Loan calculations #include <iostream> using namespace std; class Loan { public: Loan(); double getAmountBorrowed(); double getYearlyRate(); double getMonthlyPayment(); int getYears; void setAmountBorrowed( double a ); void setYearlyRate( double r ); void setYears( int y ); private: double amountBorrowed, yearlyRate; int years; }; int main() { // Declare constants for two pre-set interest rates. const double RATE15 = 5.25; const double RATE30 = 5.75; double amountBorrowed; cout.setf(ios::fixed); cout.setf(ios::showpoint); cout.precision(2); Loan loan; cout << "***** Welcome to the Loan analyzer! *****\n\n"; cout << "Enter the principle amount to borrow: "; cin >> amountBorrowed; loan.setAmountBorrowed( amountBorrowed ); cout << "============ ANALYSES ============"; loan.setYearlyRate( RATE15 ); loan.setYears( 15 ); cout << "Loan: $" << loan.getAmountBorrowed() << " at " << loan.getYearlyRate() << " for " << loan.getYears << " years.\n"; cout << "Monthly payment is $" << loan.getMonthlyPayment() << endl; loan.setYearlyRate( RATE30 ); loan.setYears( 30 ); cout << "Loan: $" << loan.getAmountBorrowed() << " at " << loan.getYearlyRate() << " for " << loan.getYears << " years.\n"; cout << "Monthly payment is $" << loan.getMonthlyPayment() << endl; cout << "\n********** Thank you. Come again! **********"; system("pause"); return 0; } void Loan::setAmountBorrowed( double a ) { amountBorrowed = a; } void Loan::setYearlyRate( double r ) { yearlyRate = r; } void Loan::setYears( int y ) { years = y; } double Loan::getAmountBorrowed() { return amountBorrowed; } double Loan::getYearlyRate() { return yearlyRate; } double Loan::getMonthlyPayment() { double monthlyPayment = getAmountBorrowed(); for (int i = 0; i < getYears; i++) { monthlyPayment *= (1 + ( yearlyRate * 100)); } monthlyPayment = (monthlyPayment / getYears) / 12; return monthlyPayment; }
You need to login to post a comment.
