Purchase Solution

C++ OOP Problem

Not what you're looking for?

Ask Custom Question

I need help, I can't seem to get my program right. I have a tendency to do it in Java and not C++. Thanks

Write the program as an object-oriented C++ program that allows the user to input the amount of a mortgage and then select from a menu of mortgage loans:

- 7 year at 5.35%
- 15 year at 5.5%
- 30 year at 5.75%.

Use an array for the different loans. Display the mortgage payment amount. Then, list the loan balance and interest paid for each payment over the term of the loan. On longer term loans, the list will scroll off the screen. Do not allow the list to scroll off the screen, but rather display a partial list and then allow the user to continue the list. Allow the user to loop back and enter a new amount and make a new selection, or quit. Insert comments in the program to document the program.

- Make sure to use inheritance.
- Make sure you use public and private members in the class definitions.
- Your program should validate all user input (simple value range validation). If value is invalid, an appropriate message should be displayed and the user is asked to re-enter the value. This continues until the user enters a valid input.
- Include a design flow chart or psuedocode algorithm.
- Don't over engineer the program.
#include <iostream>
#include "math.h"

using namespace std;

double calcPayment(double principle, double rate, double term) {

// Calculating the monthly payment: M = P [ i(1 + i)n ] / [ (1 + i)n - 1]
double monthlyRate = rate/12.0;
double t = pow((1 + monthlyRate),term);
double payment = (principle * monthlyRate * t) / (t-1);
return(payment);
}

void cont() {
char junk;
cout << "Press a key and enter to continue";
cin >> junk;
}

void displayAmort(double principle, double rate, double term, double payment) {

double monthlyRate = rate/12.0;

for (int i=1;i<=term;i++) {
principle = principle + (principle * monthlyRate);
principle = principle - payment;

cout << i << "t" << principle << endl;

if (i%24==0) {
cont();
}
}
}

int main() {

// Declaring and initializing the variables
double principle = 0;
double interestRate = 0;
int term = 0;
double payment = 0;
bool done = false;
char ch;

while (!done) {

// Prompt and get values from the user
cout << "Enter principle: ";
cin >> principle;
cout << "Enter rate: ";
cin >> interestRate;
cout << "Enter term: ";
cin >> term;

// Calculate the payment by calling a function
payment = calcPayment(principle,interestRate,term);

//Display the results on computer screen
cout << "Calculating the monthly payment of a 30 year $200,000 loan at 5.75% interest." << endl;
cout << "The monthly payment is " << payment << endl;

displayAmort(principle, interestRate, term, payment);

cout << "Again? (y/n):";
cin >> ch;
if (ch != 'y') {
done = true;
}
}
}

Purchase this Solution

Solution Summary

This solution is provided in a .zip file which is attached. A flow chart has been completed for this response in a Word document which can be found when opening the .zip file.

Purchase this Solution


Free BrainMass Quizzes
C# variables and classes

This quiz contains questions about C# classes and variables.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Basic UNIX commands

Use this quiz to check your knowledge of a few common UNIX commands. The quiz covers some of the most essential UNIX commands and their basic usage. If you can pass this quiz then you are clearly on your way to becoming an effective UNIX command line user.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

Java loops

This quiz checks your knowledge of for and while loops in Java. For and while loops are essential building blocks for all Java programs. Having a solid understanding of these constructs is critical for success in programming Java.