Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ 1. Add a manual selection that interfaces with the user to your program.

ID: 3903352 • Letter: I

Question

In C++

1. Add a manual selection that interfaces with the user to your program. Add a user selection

menu at the beginning of your program. You can use either switch or if else if statement to

do so.

2. The user interface:

Enter your name: Tom Waits (example)

Hello Tom Waits, please select the service:

A: Investment projection

B: Retirement planning

C: Mortgage

D: College fund

E: Exit

If user select A or a, execute your lab A program.

If the user select B or b, run Lab B

If D or d, output “ service coming soon.”

If the user select E or e, output “Thank you.”

If the user select anything else, output “Invalid selection.”

3. Check to make sure that the user is input ONLY ABCDE or abcde, when invalid selection is

made, bring the user back to selection.

4. When the user finish transaction, prompt the user for another transaction, if the user enter N,

end with “Have a nice day.”

5. Under (C), load a text file called “

load.txt

” which has the following info

Principle:

Interest rate: (make sure you divide this number by 100)

Loan term: (in years)

Calculated and output the following information to a file called

out.txt

:

Hello Tom Waits:

Principle: 33.00(etc)

Interest rate: 33.00

Loan term: 5.00

Monthly mortgage is: 22.00

---------------------------------------------------------

Would you like to go back to Menu? (Y/N)

(both Y or y, N or n are accepted.)

6. Under C, design a function called

mort():

After taking the inputs, call the function mort() to

process the calculations.

7. Go to the following linked for math calculation, and design your program based on these

information. Make sure you understand the information before you proceed.

https://www.nerdwallet.co

m/blog/finance

/mortgage/faq/calculate-monthly-mortgage-

payment/

http://www.wikihow.com/Calculate-Mortgage-Pay

ments

Explanation / Answer

#include<iostream>
#include<math.h>
#include<fstream>

using namespace std;


double mort(double p, double r, int n){
           r/1200;
           return p *((r*pow((1+r),n))/(pow((1+r),n)-1));
}

int main(){

   cout << "Enter your name:";
   string name;
   getline(cin,name);
   //cin.ignore();
   while(true){
       cout << "A.Investment projection ";
       cout << "B.Retirement planning ";
       cout << "C.Mortgage ";
       cout << "D.College Fund ";
       cout << "E.Rxit ";
       cout << "Enter choice:";
       string ch;
       cin >> ch;
       if (toupper(ch[0]) == 'A'){
          cout << "Run labA ";
       }
       else if (toupper(ch[0]) == 'B'){
          cout << "Run labB ";
       }
       else if (toupper(ch[0]) == 'C'){
           ifstream fin("load.txt");
           if (!fin){
              cout << "Error opening file ";
           }
           else {
              
               ofstream fout("out.txt");
               double p,r;
               int n;
               fin >> p >> r >> n;
               double mm = mort(p,r,n);
               fout << "Hello " << name << endl;
               fout << "Principle " << p << endl;
               fout << "Intrest Rate: " << r << endl;
               fout << "Loan Term: " << r << endl;
               fout << "Monthly mortgage is: " << mm << endl;
               fout.close();
               cout << "Would you like to go back to Menu? (Y/N):";
               string ch;
               cin >> ch;
               if (toupper(ch[0]) == 'N')
                  return 0;
           }
       }
       else if (toupper(ch[0]) == 'D'){
          cout << "Coming soon ";
       }
       else if (toupper(ch[0]) == 'E'){
          cout << "Thank you ";
          break;
       }
       else {
          cout << "Invalid selcetion ";
       }


   }
   return 0;
}