Question
// These headers define some of the classes and functions we need #include #include #include #include // ONLY MAKE CHANGES WHERE THERE IS A TODO
// These headers define some of the classes and functions we need #include #include #include #include
// ONLY MAKE CHANGES WHERE THERE IS A TODO
// These using declarations let us refer to things more simply // e.g. instead of "std::cin" we can just write "cin" using std::cin, std::cout, std::endl; using std::string, std::getline;
// These methods are defined below the main function
// print instructions for inputting grades void print_instructions();
// pretty print a summary of the grades void print_results(double test_average, double hw_average, double lw_average, double engagement, double weighted_total, char final_letter_grade);
// YOU ARE NOT EXPECTED TO UNDERSTAND THIS ONE... YET // extract the category and score from the line // and store the values in the provided variables // if line := "test 95", then category := "test" and score := 95 // if the line is invalid, then category := "ignore" void get_category_and_score(const string& line, string* category, double* score);
int main() { print_instructions();
// ONLY MAKE CHANGES WHERE THERE IS A TODO
// TODO(student): declare and initialize variables that you want
string line; // read one line from standard input (discards the ending newline character) getline(cin, line); // read lines until an empty line is read while (!line.empty()) { string category; double score; get_category_and_score(line, &category, &score);
// process the grade entry if (category == "test") { // TODO(student): process test score } else if (category == "final-test") { // TODO(student): process final score } else if (category == "hw") { // TODO(student): process hw score } else if (category == "lw") { // TODO(student): process lw score } else if (category == "engagement") { // TODO(student): process engagement score } else { cout
// get the next line from standard input getline(cin, line); }
// TODO(student): compute component averages double test_average = 0; double hw_average = 0; double lw_average = 0; double engagement = 0;
// TODO(student): compute weighted total of components double weighted_total = 0;
// TODO(student): compute final letter grade char final_letter_grade = 'X';
print_results( test_average, hw_average, lw_average, engagement, weighted_total, final_letter_grade); }
// These methods are already implemented for you // You should not need to modify them
void print_instructions() { cout
void get_category_and_score( const string& line, string* category, double* score) { // turn the string into an input stream std::istringstream sin(line);
// read the category (as string) and score (as double) from the stream sin >> *category; sin >> *score;
if (sin.fail()) { // the stream is in a fail state (something went wrong) // clear the flags sin.clear(); // clear the stream buffer (throw away whatever garbage is in there) sin.ignore(std::numeric_limits::max(), ' '); // signal that the line was invalid *category = "ignore"; } }
void print_results( double test_average, double hw_average, double lw_average, double engagement, double weighted_total, char final_letter_grade) { cout
cout
cout
------------------------------------------------------------------------------------
I need help with few lines of code in TODO(student) part.
There are other files that hold category and score value.
Please try any assumptions and I will give you thumbs up no matter if it's right or wrong. I just want to learn.
If you got it correct, I will promise I will give you three thumbs up with my three Chegg accounts.
Grade Input Format Grades are specified as:Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started