158k views
5 votes
Define a function ScaleGrade that takes two parameters: • points: an integer, passed by value, for the student's score. • grade: a char, passed by reference, for the student's letter grade. ScaleGrade() changes grade to C if the points are greater than or equal to 67 and less than 80, and grade is not C. Otherwise, grade is not changed. The function returns true if grade has changed, and returns false otherwise. Ex: If the input is 67 D, then the output is: Grade is C after curving. 2 using namespace std; 3 4 int main() { 5 int studentTotal; 6 char studentGrade; 7 bool isChanged; 8 9 cin >> student Total; 10 cin >> studentGrade; 11 12 isChanged = ScaleGrade (studentTotal, studentGrade); 13 14 if (isChanged) { 15 cout << "Grade is " << studentGrade << " after curving." endl; 16 } 17 else { 18 cout << "Grade " << studentGrade << " is not changed." << endl; 19 } 20 1 2 3​

User Kliew
by
7.0k points

1 Answer

3 votes
Here is a possible implementation of the ScaleGrade function in C++:

bool ScaleGrade(int points, char& grade) {
if (points >= 67 && points < 80 && grade != 'C') {
grade = 'C';
return true;
}
return false;
}

The function takes an integer points and a character grade by reference, which means that any changes made to grade inside the function will be reflected in the calling code. The function returns a boolean value indicating whether the grade was changed or not.

The function checks if points are between 67 (inclusive) and 80 (exclusive), and if grade is not already 'C'. If both conditions are true, then the function sets grade to 'C' and returns true. Otherwise, it returns false.

Here is an example usage of the function in the provided main function:

int main() {
int studentTotal;
char studentGrade;
bool isChanged;

cin >> studentTotal;
cin >> studentGrade;

isChanged = ScaleGrade(studentTotal, studentGrade);

if (isChanged) {
cout << "Grade is " << studentGrade << " after curving." << endl;
}
else {
cout << "Grade " << studentGrade << " is not changed." << endl;
}

return 0;
}

The main function reads the input values for studentTotal and studentGrade, calls the ScaleGrade function, and prints a message depending on whether the grade was changed or not.
User Nayan Katkani
by
8.3k points