Question: study what the below code does. Copy/paste it into a project and run it. Then, after that, modify the program so that it has another
study what the below code does. Copy/paste it into a project and run it. Then, after that, modify the program so that it has another exception named FailingInputException. If the user inputs a grade < 60, the program should display a message that we don't allow failing grades and then continue accepting grades. The final output should display a histogram of the numbers entered (the frequencies of the numbers entered). For example:
90 - 100: 12 times
80-89: 3 times
70-79: 7 times
60-69: 2 times
Make sure you submit your code in word document together with a screenshot of the output.
#include
using namespace std;
class NegativeInputException {
public:
NegativeInputException() {
cout << "End of input data reached ";
}
}; // end NegativeInputException class
int main() // Any exception can be raised
{
int new_grade, index, limit_1, limit_2;
int freq[10] = {0};
// Exception to deal with end of data
try {
while (true) {
cout << "Please input a grade or -1 to end: ";
cin >> new_grade;
if (new_grade < 0) // Terminating condition
throw NegativeInputException();
index = new_grade / 10;
{ try {
if (index > 9)
throw new_grade;
freq[index]++;
}
catch (int grade) { // Handler for index error
if (grade == 100)
freq[9]++;
else
cout << "Error: " << grade << " out of range! ";
} // end of catch(int grade)
} // end of inner try-catch pari
} // end of while
} // end of outer try block
catch (NegativeInputException e) { // Handler for negative
cout << "Limits Frequency ";
for (index = 0; index < 10; index++) {
limit_1 = 10 *index;
limit_2 = limit_1 + 9;
if (index == 9)
limit_2 = 100;
cout << limit_1 << " " << limit_2 << " " << freq[index]
<< endl;
} // end for
} // end catch (negative int)
system("pause");
}
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
