Your Ad Here

Posted By

dblandin on 11/10/10


Tagged


Versions (?)

CSC 261 HW6 - Part I


 / Published in: C++
 

  1. // filename: Loan.cpp
  2. // name: Devon Blandin
  3. // CSC 261 - Homework #6
  4. // Description: Loan calculations
  5.  
  6. #include <iostream>
  7. using namespace std;
  8.  
  9. class Loan {
  10. public:
  11. Loan();
  12. double getAmountBorrowed();
  13. double getYearlyRate();
  14. double getMonthlyPayment();
  15. int getYears;
  16. void setAmountBorrowed( double a );
  17. void setYearlyRate( double r );
  18. void setYears( int y );
  19. private:
  20. double amountBorrowed, yearlyRate;
  21. int years;
  22. };
  23.  
  24. int main() {
  25. // Declare constants for two pre-set interest rates.
  26. const double RATE15 = 5.25;
  27. const double RATE30 = 5.75;
  28. double amountBorrowed;
  29.  
  30. cout.setf(ios::fixed);
  31. cout.setf(ios::showpoint);
  32. cout.precision(2);
  33.  
  34. Loan loan;
  35.  
  36. cout << "***** Welcome to the Loan analyzer! *****\n\n";
  37. cout << "Enter the principle amount to borrow: ";
  38. cin >> amountBorrowed;
  39. loan.setAmountBorrowed( amountBorrowed );
  40.  
  41. cout << "============ ANALYSES ============";
  42.  
  43. loan.setYearlyRate( RATE15 );
  44. loan.setYears( 15 );
  45. cout << "Loan: $" << loan.getAmountBorrowed() << " at " << loan.getYearlyRate() << " for " << loan.getYears << " years.\n";
  46. cout << "Monthly payment is $" << loan.getMonthlyPayment() << endl;
  47.  
  48. loan.setYearlyRate( RATE30 );
  49. loan.setYears( 30 );
  50. cout << "Loan: $" << loan.getAmountBorrowed() << " at " << loan.getYearlyRate() << " for " << loan.getYears << " years.\n";
  51. cout << "Monthly payment is $" << loan.getMonthlyPayment() << endl;
  52.  
  53. cout << "\n********** Thank you. Come again! **********";
  54.  
  55. system("pause");
  56. return 0;
  57. }
  58. void Loan::setAmountBorrowed( double a ) {
  59. amountBorrowed = a;
  60. }
  61. void Loan::setYearlyRate( double r ) {
  62. yearlyRate = r;
  63. }
  64. void Loan::setYears( int y ) {
  65. years = y;
  66. }
  67. double Loan::getAmountBorrowed() {
  68. return amountBorrowed;
  69. }
  70. double Loan::getYearlyRate() {
  71. return yearlyRate;
  72. }
  73. double Loan::getMonthlyPayment() {
  74. double monthlyPayment = getAmountBorrowed();
  75. for (int i = 0; i < getYears; i++) {
  76. monthlyPayment *= (1 + ( yearlyRate * 100));
  77. }
  78. monthlyPayment = (monthlyPayment / getYears) / 12;
  79. return monthlyPayment;
  80. }

Report this snippet  

You need to login to post a comment.