Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me fix this error I get from the following code: CourseGradebook.h #ifndef COURSEGRADEBOOK_H #define COURSEGRADEBOOK_H #include #include Gradebook.h class CourseGradebook : public Gradebook

Please help me fix this error I get from the following code:

CourseGradebook.h

#ifndef COURSEGRADEBOOK_H #define COURSEGRADEBOOK_H

#include #include "Gradebook.h"

class CourseGradebook : public Gradebook { protected: std::unordered_map> gradebookData;

public: virtual ~CourseGradebook() {}

std::unordered_map GetAssignmentScores(std::string assignmentName) override { if (gradebookData.count(assignmentName) == 0) { return std::unordered_map(); } return gradebookData[assignmentName]; }

double GetScore(std::string assignmentName, int studentID) override { if (gradebookData.count(assignmentName) == 0 || gradebookData[assignmentName].count(studentID) == 0) { return NAN; } return gradebookData[assignmentName][studentID]; }

std::vector GetSortedAssignmentNames() override { std::vector assignmentNames; for (const auto& entry : gradebookData) { assignmentNames.push_back(entry.first); } std::sort(assignmentNames.begin(), assignmentNames.end()); return assignmentNames; }

std::vector GetSortedStudentIDs() override { std::unordered_map studentIDMap; for (const auto& entry : gradebookData) { for (const auto& subEntry : entry.second) { studentIDMap[subEntry.first] = true; } } std::vector studentIDs; for (const auto& entry : studentIDMap) { studentIDs.push_back(entry.first); } std::sort(studentIDs.begin(), studentIDs.end()); return studentIDs; }

std::unordered_map GetStudentScores(int studentID) override { std::unordered_map studentScores; for (const auto& entry : gradebookData) { if (entry.second.count(studentID) != 0){ studentScores[entry.first] = entry.second[studentID]; } } return studentScores; }

void SetScore(std::string assignmentName, int studentID, double score) override { gradebookData[assignmentName][studentID] = score; } };

#endif

Error

In file included from main.cpp:6: CourseGradebook.h: In member function virtual std::unordered_map, double> CourseGradebook::GetStudentScores(int): CourseGradebook.h:57:68: error: passing const std::unordered_map as this argument discards qualifiers [-fpermissive] 57 | studentScores[entry.first] = entry.second[studentID];

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Formal SQL Tuning For Oracle Databases Practical Efficiency Efficient Practice

Authors: Leonid Nossov ,Hanno Ernst ,Victor Chupis

1st Edition

3662570564, 978-3662570562

More Books

Students also viewed these Databases questions

Question

Question Can a Roth IRA invest in stock of the IRA owners business?

Answered: 1 week ago