Comprehensive Programming Assignment Problem 2 This problem counts for approxima
ID: 3565848 • Letter: C
Question
Comprehensive Programming Assignment Problem 2
This problem counts for approximately 40 percent of your comprehensive programming assignment grade.
You are a mortgage broker who is determining whether you should provide a mortgage to prospective home purchasers. If you are willing to provide a mortgage, you need to decide how much you should charge the borrower. You design a point system that assigns prospective borrowers a score of 1, 2, 3, 4, or 5 based on some mysterious formula. Based on these scores, you come up with the following decisions:
Score
Decision
5
=
Provide mortgage at 5% interest rate
4
=
Provide mortgage at 6% interest rate
3
=
Provide mortgage at 7% interest rate
2
=
Do not provide mortgage
1
=
Do not provide mortgage
Create a program that takes the scores as input and provides as output the management decision. In the program, include 2 void functions titled getScore and printDecision, each with an int argument.
The function getScore should have a Reference parameter that gets the score in getScore and then passes the value back to be printed in main ( ), and
printDecision should have a Value parameter.
The function getScore will prompt the user for the integer score from 1 to 5, get the input from the user, and display the input received on the screen. The function printDecision will determine the mortgage decision and print the decision. (Be careful and note that this problem requires you to input the score into getScore and not directly into the main function.)
Score
Decision
5
=
Provide mortgage at 5% interest rate
4
=
Provide mortgage at 6% interest rate
3
=
Provide mortgage at 7% interest rate
2
=
Do not provide mortgage
1
=
Do not provide mortgage
Explanation / Answer
#include <iostream>
using namespace std;
void getScore(int* pScore){
cout << "Enter prospective borrower's score. Integer between 1 to 5." << endl;
while(1){ // to keep getting values input until a valid input is entered
cin >> *pScore;
cout << "Entered Value is " << *pScore << endl;
if(*pScore > 5 || *pScore < 1){
cout << "Ivalid data. Please enter a value between 1 and 5 (both inclusive)." << endl;
}
else
{
break;
}
}
}
void printDecision(int score){
switch(score){
case 5:
cout << "Provide mortgage at 5% interest rate";
break;
case 4:
cout << "Provide mortgage at 6% interest rate";
break;
case 3:
cout << "Provide mortgage at 7% interest rate";
break;
case 2:
case 1:
cout << "Do not provide mortgage.";
break;
default:
cout << "Bad Data.";
break;
}
}
int main()
{
int score;
getScore(&score); // passing a reference of the variable score
printDecision(score); // passing the value of the variable score
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.