Assignment - http://condor.depaul.edu/~ntomuro/courses/262/assign/hw2.html

Write a class called Loan, which simulates the money you borrow from a financial institution, and a main function (i.e., an application program) which tests the class. 
You write ONE file, which should be named "myLoan.cpp".
1. Class Loan

The class Loan should have the following members:

    * Member variables -- all of below should be private.
         1. double amountBorrowed -- the principal amount of the loan.
         2. double yearlyRate -- the annual interest rate of the loan. A rate of 7.25% would be entered as 7.25 and stored in yearlyRate as 7.25.
         3. int years -- the number of years on the loan.
    * Member functions/methods -- all of below should be public.

       1. double getAmountBorrowed()
       2. double getYearlyRate()
       3. int getYears()
       4. void setAmountBorrowed( double a )
       5. void setYearlyRate( double r )
       6. void setYears( int y )
       7. double monthlyPayment() -- This method should return the monthly payment. Use the following formula to compute this amount.

          In the formula P is the amount borrowed, i is the monthly rate (= (yearlyRate / 100) / 12) and n is the number of payments (= years * 12).
       8. void printLoan() -- This method prints the information of this loan in the following way to the terminal/cout.

          Loan: $100000.00 at 6.25% for 30 years. 

2. Main

    *

      Main should contain the procedures to do the following.
      This application simulates a loan specialist. The specialist has two pre-set interest rates: one for 15 years and another for 30 years. They should be declared as constants RATE15 and RATE30 in the application (as shown below). The application/specialist asks the user/customer for the principal amount to borrow, and displays the monthly payment for both 15 and 30 years (i.e., what-if scenarios). 

      Below is the sample output of a session. The part where the user entered is indicated in bold.  You don't have to repeat the session.

          ***** Welcome to the Loan analyzer! *****

          Enter the principle amount to borrow: 200000

          ============ ANALYSES ============
          Loan: $200000.00 at 5.25% for 15 years.
          Monthly payment is $1607.76

          Loan: $200000.00 at 5.75% for 30 years.
          Monthly payment is $1167.15

          ********** Thank you. Come again! **********

    *

      As a hint, the source file and main would have something like below.

          #include <iostream>
          using namespace std;

          // ---
          // Definition of class Loan and all of its member functions
          // come here.

          // ---
          // Application part
          int main()
          {
            // Declare constants for two pre-set interest rates.
            const double RATE15 = 5.25;
            const double RATE30 = 5.75;

            ...

    * REQUIREMENTS:
         1. Create two Loan objects -- one for the 15 year loan, and another for the 30 year loan.
            Print the first line of the analysis for each loan by calling the printLoan() method.
         2. To print the monthly payment in the second line of the analysis, be sure to print two digits only.  As a reminder, the "magic formula" to do so is:

              cout.setf(ios::fixed);
              cout.setf(ios::showpoint);
              cout.precision(2);

Here is what I've done so far. I realize that there are a few errors that I've made. Could you please point out where my errors are located and the best way to fix these. Thanks.

// Homework Assignment 2
// Due: Wednesday, April 16, 11:59pm
// The program # Create two Loan objects -- one for the 15 year loan, and another for the 30 year loan. Prints the first line of the analysis for each loan by calling the printLoan() method. Prints the monthly payment in the second line of the analysis, be sure to print two digits only

#include <iostream>
#include<cmath>

using namespace std;

// prototypes
class Loan
{		// members are private by default.
    double amountBorrowed; //-- the principal amount of the loan.
	double yearlyRate; //-- the annual interest rate of the loan. A rate of 7.25% would be entered as 7.25 and stored in yearlyRate as 7.25.
	int years; //-- the number of years on the loan.

public:				//public means members are accessible from the outside world.
	double getAmountBorrowed();
	double getYearlyRate();
	int getYears();
	void setAmountBorrowed( double a );
	void setYearlyRate( double r );
	void setYears( int y );
	double monthlyPayment(); //-- This method should return the monthly payment. Use the following formula to compute this amount.	
							// P*(i*pow( (1+i), n ) )/(pow( (1+i), n ) - 1); 
							//In the formula P is the amount borrowed, i is the monthly rate (= (yearlyRate / 100) / 12) and n is the number of payments (= years * 12).
	void printLoan(); //-- This method prints the information of this loan in the following way to the terminal/cout.
};

// Application part
int main()
{
  // Declare constants for two pre-set interest rates.
	const double RATE15 = 5.25;
	const double RATE30 = 5.75;
	int P;

	// prompts the user
	cout << "***** Welcome to the Loan analyzer! *****" << endl << endl;
	cout << "Enter the principle amount to borrow: ";

	cin >> P;

// display result
	cout << endl;
	cout << "============ ANALYSES ============ " << endl;
	
	Loan L1, L2;

	L1.printLoan();
	L2.printLoan();

	cout << "********** Thank you. Come again! **********" << endl;
	/*
	============ ANALYSES ============
Loan: $200000.00 at 5.25% for 15 years.
Monthly payment is $1607.76

Loan: $200000.00 at 5.75% for 30 years.
Monthly payment is $1167.15

********** Thank you. Come again! **********
*/


	system ("pause");

	return 0;
}
double Loan::getAmountBorrowed()
{
	return amountBorrowed;
}
double Loan::getYearlyRate()
{
	return yearlyRate;
}
int Loan::getYears()
{
	return years;
}
void Loan::setAmountBorrowed( double a )
{
	amountBorrowed = a;
}
void Loan::setYearlyRate( double r )
{
	yearlyRate = r;
}
void Loan::setYears( int y )
{
	years = y;
}
double Loan::monthlyPayment(double p, double i, double n)
{
	double monthPay = P*(i*pow( (1+i), n ) )/(pow( (1+i), n ) - 1)
	return P;
 }
void Loan::printLoan()
{
	cout << "Loan: " << P << ".00 at " << RATE15 << "% for " << years << "years." << endl;
	cout << "Monthly payment is $" << L1.monthlyPayment << endl << endl;
}

// return P*(i*pow( (1+i), n ) )/(pow( (1+i), n ) - 1);

it would be nice if you tried compiling it and then let us know which lines are throwing errors and then we look into it. Also you done need to put everything in code tags, just the code will do.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.