Please solve this in Eclipse C code cin cout etc 1 Add a man
Please solve this in Eclipse C++ code. (cin, cout, etc.)
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 todo 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 3 program.
If the user select B,b 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 ismade, 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() toprocess the calculations.
7. Go to the following linked for math calculation, and design your program based on theseinformation. Make sure you understand the information before you proceed. I am using Eclipse C++
Solution
Please follow the code and comments for description :
CODE :
#include <cstdlib> // required header files
 #include <iostream>
 #include <fstream>
 #include <string>
 #include <cmath>
using namespace std;
int main(int argc, char** argv) { // driver method
string name, line, lineStr; // local varaibles
 char choice, option;
 double lineData, interest, principalAmt, tenure, Payment;
ifstream myfile(\"load.txt\"); // loading the data
cout << \"Enter your name : \"; // get the name of the user
 cin >> name;
cout << \"Hello \" << name << \" ,Please Select the Service : \" << endl; // print the message
while (true) { // loop over the data
 cout << \"Please Select the Service : \" << endl; // mesage about the code
 cout << \"\ --------------------------------------\" << endl;
 cout << \"A: Investment projection.\ B: Retirement planning.\ C: Mortgage.\ D: College fund.\ E: Exit.\" << endl;
cin >> choice; // get the choice
if (choice == \'A\' || choice == \'a\') { // check for the choice
 cout << \"Need to add the Lab 3 Program.!\" << endl; // message to console
 cout << \"Would you like to go back to Menu?\" << endl; // ask for the option
 cin >> option; // get the option
 if (option == \'y\' || option == \'Y\') { // check the data
 continue;
 } else if (option == \'n\' || option == \'N\'){
 cout << \"Have a nice day.\" << endl; // end if not needed
 break;
 }
 } else if (choice == \'B\' || choice == \'b\') { // check for the choice
 cout << \"Service Coming Soon.!\" << endl; // message to console
 cout << \"Would you like to go back to Menu?\" << endl; // ask for the option
 cin >> option; // get the option
 if (option == \'y\' || option == \'Y\') { // check the data
 continue;
 } else if (option == \'n\' || option == \'N\'){
 cout << \"Have a nice day.\" << endl; // end if not needed
 break;
 }
 } else if (choice == \'C\' || choice == \'c\') { // check for the choice
 int count = 0;
 if (myfile.is_open()) { // check for the file
 while (getline(myfile, line)) {
 count++;
 size_t pos = line.find(\":\"); // seperate the data from the strings
 lineStr = line.substr(pos + 1); // get the required data
 lineData = atof(lineStr.c_str()); // convert to double type
if (count == 1) { // read every data line
 principalAmt = lineData;
 } else if (count == 2) {
 interest = lineData;
 } else if (count == 3) {
 tenure = lineData;
 }
double MonthlyInt = interest / 12; // calculations for the interest and the payments
 double NumPayments = tenure * 12;
Payment = MonthlyInt * pow((1 + MonthlyInt), NumPayments) / (pow((1 + MonthlyInt), NumPayments) - 1) * principalAmt; // calculations for the amount
 }
 cout << \"Hello \" << name << endl; // print data to console
 cout << \"Principal Amount : \" << principalAmt << endl;
 cout << \"Interest Rate : \" << interest << endl;
 cout << \"Loan Term : \" << tenure << endl;
 cout << \"The Monthly Mortgage is : \" << Payment << endl;
myfile.close(); // close the file
 } else {
 cout << \"Unable to open file\";
 }
 cout << \"Would you like to go back to Menu?\" << endl;
 cin >> option;
 if (option == \'y\' || option == \'Y\') {
 continue;
 } else if (option == \'n\' || option == \'N\'){
 cout << \"Have a nice day.\" << endl; // end if not needed
 break;
 }
 } else if (choice == \'D\' || choice == \'d\') { // check for the choice
 cout << \"Service Coming Soon.!\" << endl;
 cout << \"Would you like to go back to Menu?\" << endl; // message to console
 cin >> option;
 if (option == \'y\' || option == \'Y\') { // check for the choice
 continue;
 } else if (option == \'n\' || option == \'N\') {
 cout << \"Have a nice day.\" << endl; // end if not needed
 break;
 }
 } else if (choice == \'E\' || choice == \'e\') { // check for the choice
 cout << \"Thank you.\" << endl;
 cout << \"Would you like to go back to Menu?\" << endl; // message to console
 cin >> option;
 if (option == \'y\' || option == \'Y\') {
 continue;
 } else if (option == \'n\' || option == \'N\'){
 cout << \"Have a nice day.\" << endl; // end if not needed
 break;
 }
 } else {
 cout << \"Invalid Selection.\" << endl; // mesage and then continue
 continue;
 }
 }
 return 0;
 }
OUTPUT :
Enter your name : John
 Hello John ,Please Select the Service :
 Please Select the Service :
--------------------------------------
 A: Investment projection.
 B: Retirement planning.
 C: Mortgage.
 D: College fund.
 E: Exit.
 a
 Need to add the Lab 3 Program.!
 Would you like to go back to Menu?
 y
 Please Select the Service :
--------------------------------------
 A: Investment projection.
 B: Retirement planning.
 C: Mortgage.
 D: College fund.
 E: Exit.
 b
 Service Coming Soon.!
 Would you like to go back to Menu?
 y
 Please Select the Service :
--------------------------------------
 A: Investment projection.
 B: Retirement planning.
 C: Mortgage.
 D: College fund.
 E: Exit.
 x
 Invalid Selection.
 Please Select the Service :
--------------------------------------
 A: Investment projection.
 B: Retirement planning.
 C: Mortgage.
 D: College fund.
 E: Exit.
 d
 Service Coming Soon.!
 Would you like to go back to Menu?
 y
 Please Select the Service :
--------------------------------------
 A: Investment projection.
 B: Retirement planning.
 C: Mortgage.
 D: College fund.
 E: Exit.
 c
 Hello John
 Principal Amount : 500000
 Interest Rate : 0.12
 Loan Term : 5
 The Monthly Mortgage is : 11122.2
 Would you like to go back to Menu?
 e
 Have a nice day.
 Hope this is helpful.




