68.6k views
3 votes
19.5 LAB: Student grades (map) Instructor note: map Documentation ZyBook Documentation map m; V at(K); emplace(K, V); int count(K); int erase(K); void clear(); Given a map pre-filled with student names as keys and grades as values, complete main() by reading in the name of a student, outputting their original grade, and then reading in and outputting their new grade. Ex: If the input is: Quincy Wraight 73.1 the output is: Quincy Wraight's original grade: 65.4 Quincy Wraight's new grade: 73.1

Code given : #include #include #include using namespace std; int main () { string studentName; double studentGrade; map studentGrades; // Students' grades (pre-entered) studentGrades.emplace("Harry Rawlins", 84.3); studentGrades.emplace("Stephanie Kong", 91.0); studentGrades.emplace("Shailen Tennyson", 78.6); studentGrades.emplace("Quincy Wraight", 65.4); studentGrades.emplace("Janine Antinori", 98.2); // TODO: Read in new grade for a student, output initial // grade, replace with new grade in map, // output new grade return 0; }

User Csharpest
by
7.9k points

1 Answer

0 votes

Final answer:

To update a student's grade in a map, use the count(), erase(), and emplace() functions.

Step-by-step explanation:

To complete the given code, you need to read in the name of a student, output their original grade, read in their new grade, replace the original grade with the new grade in the map, and then output the new grade. You can achieve this by using the count() function to check if the student name exists in the map, and the erase() function to remove the student's entry from the map. After that, you can use the emplace() function to insert the student's name and new grade into the map. Finally, you can use the at() function to retrieve and output the original and new grades.

User RavensKrag
by
8.2k points