The two major modifications are the instruction of pointers and the calculation of mortgage interest rates.
Requirements for Project:
1. When developing this project in a Win32 Console Applications that includes the precompiled headers, enter in the Name: box, PRJ2[Your Full Last Name][Your First Initial] with no spaces. An example using the your project assignment where the PRJ is for Project, the 2 for the second project, and the name is from your name would be PRJ2SmithX for a student named Xavier Smith. This convention is used as the file name for this assignment. You will name it with your name in place of the "SmithX" in PRJ2SmithX.
2. Change the various identifiers that are of the data type struct from arrays into pointers. [Review information at end of document about the use of pointers.]
3. Add to the menu two items: calculate a mortgage rate and add a mortgage account to a bank client.
4. Create a method that will offer the user multiple possibilities for principal amount, rate, and length of time for a mortgage. [See development at end of document for determining monthly mortgage payment.]
5. Develop an interactive section to accept the various parameters used to calculating the mortgage payment.
6. In the section on the mortgage loan, after calculating the mortgage payment display all the elements related to the mortgage payment in a formatted line.
7. After a decision is made for a monthly mortgage payment, place the payment into the new add mortgage account method making the payment a monthly withdrawal. [Will a new field be required to distinguish one time withdrawals and recurring monthly withdrawals?]
8. End the program with a message indicating the end of the program and the name of the financial institution used.
9. Once the assignment works correctly for all parts, create an image of the results from the Output window and name the file PRJ2SmithXDisplay for the displays of various sets of parameters for a mortgage payment. [Highlight the text from the beginning to the end of the process the copy and paste it into the above named file.]
10. The completed project consists of the C++ file (PRJ2SmithX.cpp) and the image file (PRJ2SmithXDisplay). Submit each of these files to your WebTycho Project 2 assignment area no later than the due date listed in the syllabus schedule.
Pointers
When declaring a variable of data type pointer, use the * in front of the variable name. These variables hold a memory location (like B45CDF), not an actual value like 30 or A:
int * Years;
char * Grade;
This tells the program that the value contained in the variable will be a memory address that points to the value at that memory address.
To obtain an actual memory address to use with this variable, the & or reference operator is used.
In the following example, a regular variable is declared. Whenever a variable is declared in a program, the operating system sets aside a memory location in the computer to hold whatever value of a given data type is placed in that memory location. So placing the & in front of a regular variable, tells the operating system that the program wants the memory location address and not the value contained in that memory location.
int LoanYears;
int * Years;
The following code assigns the memory location for the LoanYears variable to the pointer variable.
Years = &LoanYears;
Note: If the assignment was "Years = LoanYears;" a compiler error would occur since the LoanYears is of the wrong data type that Years. Years only accepts memory locations, not actual values.
To assign a value or change the value of LoanYears using the pointer instead of the actual variable, the following code is used:
*Years = 30;
equivalent to
LoanYears = 30;
NOTE: Among the symbols expected in the code are -> and the use of ++ with the pointer variable for the pointer to the struct.
Examples of pointers
// Basic pointer code
#include "stdafx.h"
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int FirstNumber, SecondNumber;
int * ptrNumber;
ptrNumber = &FirstNumber;
*ptrNumber = 10;
ptrNumber = &SecondNumber;
*ptrNumber = 20;
cout << "FirstNumber is " << FirstNumber << endl;
cout << "SecondNumber is " << SecondNumber << endl;
return 0;
}
Output:
FirstNumber is 10
SecondNumber is 20
// Pointers with an array
#include "stdafx.h"
#include
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int NumbHold[5];
int * ptrNumb;
ptrNumb= NumbHold;
*ptrNumb= 10;
ptrNumb++;
*ptrNumb= 20;
ptrNumb= &NumbHold[2];
*ptrNumb= 30;
ptrNumb= NumbHold + 3;
*ptrNumb= 40;
ptrNumb= NumbHold;
*(ptrNumb+4) = 50;
for (int n=0; n<5; n++)
cout << NumbHold[n] << ", ";
cout << endl;
return 0;
}
Output:
10, 20, 30, 40, 50,
Return to text in document
Determining the monthly payment on a mortgage loan:
The following is the formula that can be used to complete that calculation:
Monthly Payment =
Monthly Interest Rate / (1 - (1 + Monthly Interest Rate) -Payment Interval)) * Principal
Where
Monthly Interest Rate expressed as: Interest Rate / 100 / 12.
Payment Interval expressed as: Number of Years * Months of Year.
Principal is total amount of mortgage expressed without any comma separators or $ prefixing it.
An example for the above formula:
Rate: 7.75
Period: 360
Principal: $100,000
(7.75 / 100 /12) / (1 - (1 + 7.75 /100 / 12) ^ -(30 * 12) ) * 100000
The result of the above formula generates a value of 682.18. (Note that there is no formatting of the value.) The ^ is the symbol for an exponent that replaces the superscript in an actual formula.
In C++ you must declare variables for the rate, period, principal, and monthly payment. Each of these variables is prefixed with a data type. In this case the data types are limited to float for decimal-based numbers (interest rate and monthly payment) and int for whole numbers (payment interval and principal). NOTE: C++ in case sensitive so be sure the variable is the same in every instance.
Some of the Code:
Payment = ?? / (1 - pow((1 + ??), - ?? * 12)) * ??;
cout << "Your monthly mortgage payment is tiny_mce_markerquot; << ?? << endl << endl;
[Remember to have #include
Test:
Rate Period Principal Monthly Payment
3.50% 30 years $350,000.00 1571.656
6.25% 15 years $275,000.00 2357.913
7.325% 30 years $468,000.00 3216.427*
5.50% 40 years $725,000.00 3739.335
8.125% 30 years $645,000.00 4789.107*
*Possible rounding error
Return to text in document