Please help with cpp code Your goal is to determine the nal grade given certain
ID: 3849779 • Letter: P
Question
Please help with cpp code
Your goal is to determine the nal grade given certain threshold values and the score. For example, here is an example for threshold values: 90 up for A, 80 - below 90 for B, 70 - below 80 for C, and below 70 for F. Here we can think of 90, 80, 70 as the threshold values. Under these values, if your grade is 86, then your nal grade is B. In this assignment, we consider the case where there are only 4 possible grades: A, B, C, and F, so we need 3 integers to specify the threshold values. Next we describe your tasks:
• Task 1: write a function to determine whether the input threshold values are valid. The function takes inputs 3 integers a, b, c and returns a boolean value (true/false). In particular, it checks whether 100 > a > b > c > 0. If the condition is true, then return true. Otherwise, return false.
• Task 2: write a function that takes inputs three values as the threshold and a score, and then returns the grade. (Think about what output data type you should use). In particular, the function takes inputs 4 integers a, b, c and g. The rst three numbers represent the threshold, and the last represents the (numerical) score. Then the function rst checks whether the input threshold values are valid. If not, return a character ’N’; if valid, then return the nal grade (a character, A, B, C or F).
• Task 3: Inside the main function, you print “Enter the values of threshold for A,B,C, and F” on the rst line, and then the user inputs 3 integers. Then print “What is your numerical score?” on the next line, followed by a user input (for an integers). On the next line, print either “The threshold is not valid.” or “Your nal grade is X.”, where X depends on the threshold and your numerical score.
Explanation / Answer
Below is your program: -
#include<iostream>
using namespace std;
//#task 1 for checking if threashhold is valid
bool isThreashHoldValid(int a,int b,int c) {
if((a<100 && a>0) && (b<100 && b>0) && (c<100 && c>0)) {
return true;
}
return false;
}
//#task 2 for getting grade
char getGrade(int a,int b,int c,int score) {
if(isThreashHoldValid(a,b,c)) {
if(score > a) {
return 'A';
} else if(score <= a && score > b) {
return 'B';
} else if(score <= b && score > c) {
return 'C';
} else {
return 'F';
}
} else {
return 'N';
}
}
//#task 3 main function to test the functions
int main() {
cout<<"Enter the values of threshold for A,B,C, and F: ";
int a,b,c,score;
cin>>a;
cin>>b;
cin>>c;
cout<<"What is your numerical score?";
cin>>score;
char grade = getGrade(a,b,c,score);
if(grade == 'N') {
cout<<"The threshold is not valid.";
} else {
cout<<"Your final grade is "<<grade<<".";
}
}
Sample output
#1.
Enter the values of threshold for A,B,C, and F: 121
12
90
What is your numerical score?60
The threshold is not valid.
--------------------------------
Process exited after 16.34 seconds with return value 0
Press any key to continue . . .
#2.
Enter the values of threshold for A,B,C, and F: 90
80
70
What is your numerical score?84
Your final grade is B.
--------------------------------
Process exited after 9.459 seconds with return value 0
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.