\ CS 238 Exploration 2
| Tweet |
|
Hey guys… Here’s my code so far. Let me know if you have any questions about it.
Display Results
Displays all the numbers in the proper format
void Amortize::displayResults() {
cout << endl <<
"##############################################" << endl << endl;
cout.precision(2);
cout << setiosflags(ios::fixed) <<
" Principal: " << mPrincipal << endl <<
" Term: " << mTermInMonths << " months" << endl;
cout.precision(3);
cout <<
" Annual Rate " << mRate << "%" << endl;
cout.precision(7);
cout <<
" Periodic Rate " << mPeriodicRate << endl << endl;
cout.precision(2);
cout << setiosflags(ios::fixed) <<
"Monthly Payment: " << mMonthlyPayment << endl <<
" Extra Payment: " << mExtraMonthlyPayment << endl << endl;
cout << " Reduced Term: "
<< reducedTerm << " months (shorter by "
<< shorterBy << " month(s) = " << (int)(shorterBy/12)
<< " year(s) " << shorterBy - ((int)(shorterBy/12) * 12)
<< " month(s))" << endl;
cout << setiosflags(ios::fixed) <<
" Total Payments: " << totalPayments << endl <<
" Extra Payments: " << extraPayments << endl <<
" Total Interest: " << totalInterest << endl <<
" Total Savings: " << totalSavings << endl <<
" Intrst/Prncpl: " << interest << "%" << endl;
}
Find Monthly Payments
Um… finds the monthly payments…
/**
* c = (rP)/(1-(1+r)^-n)
* r = monthly rate
* P = principal
* n = term (monthly payments)
*/
void Amortize::findMonthlyPayment()
{
mMonthlyPayment = (mPeriodicRate * mPrincipal)
/ (1 - pow((1 + mPeriodicRate), -mTermInMonths));
}
Zero to Bool
A subtle wrapper that converts a string (if the string can be coerced into an int) to bool
bool Amortize::zeroToBool(int val)
{
return val != 0;
}
Find Periodic Rate
Breaks the APR into the monthly rate
void Amortize::findPeriodicRate()
{
// returns true if mRate is not zero
if (zeroToBool(mRate))
{
mPeriodicRate = mRate / 1200;
mHavePeriodicRate = true;
}
}
Leave a Reply
\ Social Media
\ Recent Posts
\ Categories
\ Popular Tags
3D
Artificial Intelligence
BYU-I
C++
C++ to Javascript port
Chromium WebGL
Debugging
demos
Discrete Math
Eclipse
Firebug
Free Download
Google Web Toolkit
GWT
HTML5 Demo
Java
Javascript Games
jQuery
Math & Programming
OBJ File
OpenGL
Papers
Parser
Plug-in
plugins
quick tip
Recurrence Relations
RokkoCode
School Projects
Screen Cast
Screencast
Sudoku
Sudoku Algorithm
The Matrix
WebGL
Web Sockets
wegbl
Writing
writting 3D (5)
Algorithms (1)
Articles (5)
BYU-I (6)
C++ (9)
Fun Projects (3)
GWT (2)
HTML5 (3)
Java (1)
Javascript (7)
PHP (1)
Web 2.0 (2)
WP Cumulus Flash tag cloud by Roy Tanck requires Flash Player 9 or better.
