Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// 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 " := test | final-test | hw | lw | engagement" := numeric value"

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<:streamsize>::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

image text in transcribed

------------------------------------------------------------------------------------

I need help with few lines of code in TODO(student) part.

There are other files that hold category and score value. For example, when you open "test_score_1.txt", you will see 'Test 80' and "test_score_2.txt", you will see 'Test 70'.

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: values are: exam, final-exam, hw, lw, engagement values for exam, final-exam, hw, engagement are specified as percentages (i.e. numbers from 0.0 to 100.0, but sometimes more when there is an opportunity for extra credit). Converting a fraction to a decimal percentage is easy: 123/164 = (do the division) 0.75 = (multiply by 100) 75%. values for lw are boolean-valued (0 or not-o, for incomplete or complete). This is an example of grade input: exam 78.2 exam 83.8 final-exam 71.2 hw 62 hw 65.4 hw 70 hw 77.4 hw 82.8 lw 1 lw 1 lw 1 lw 1 lw 1 lw 1 engagement 10 engagement 26 engagement 28 engagement 21

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

Fundamentals Of Database System

Authors: Elmasri Ramez And Navathe Shamkant

7th Edition

978-9332582705

More Books

Students also viewed these Databases questions

Question

Discuss the techniques for allocating file blocks on disk.

Answered: 1 week ago

Question

=+differences in home- and host-country costs of living?

Answered: 1 week ago

Question

=+derived from the assignment will balance the costs?

Answered: 1 week ago