Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this homework you will review a number of the concepts that were presented in CPTR 141 and apply them to calculating of the homework

In this homework you will review a number of the concepts that were presented in CPTR 141 and apply them to calculating of the homework portion of a student's grade using the Mastery Grading model described in the syllabus. You are provided with a program, `gradebook.cpp`, that contains a main function and prototypes for six other functions. One of the functions has been provided to you.

## Assignment

Your assignment is to modify main() by adding input validation and then add the five remaining functions so that the program provides the requested behavior. The remainder of this section will discuss these tasks and give some hints on the order in which to do the development and how to approach each task. I suggest that you read through the remainder of this document, including the section on Development and Testing below before starting on the assignment.

### Input validation

After setup of some variables used throughout the program (names, ids, homeworkScores), `main()` enters an infinite loop presenting a menu and doing the operation requested by the user (one of the options is to quit). The menu choice is an integer collected in the `menu` variable. If the user enters an integer other than the menu options (1-4), then the `default:` case in the `switch` statement will handle it.

But if the user enters something other than an integer, then the input stream will enter an error state. You need to add code to handle this situation. Basically, if the input is good then you can proceed to the `switch` statement, otherwise you should alert the user and clear the error.

### `getNextResubmission()`

As described in the function prototype comment, this function takes two arguments, a single-dimension character array of scores (E/M/R/N) and an integer designating the size of the array, and returns an integer indicating the next homework number (zero-based) the student should submit. If any score is 'R' or 'N', then the index of the first such score is returned. Next, if any score is an 'M', then the index of the first such score is returned. Finally, if all the scores are 'E's (which will be the case if neither of the previous conditions is satisfied), then return a -1 indicating that no assignments need to be redone.

Note that you will need to make two passes over the provided scores, first looking for 'R' or 'N', and next looking for 'M'. As you consider your loops (in this function and others), ask yourself which type of loop is best suited for the situation (`for`, `while`, or `do-while`).

To test each homework score you will need some form of branching. As you work on this function note that there are three ways it can return, one for an 'R' or 'N', one for an 'M', and one for all 'E's.

To test this function you could try variations on the following:

```c++

assert(getNextResubmission(homeworkScores[0], NUMBER_OF_SCORES) == 5);

assert(getNextResubmission(homeworkScores[2], NUMBER_OF_SCORES) == 4);

assert(getNextResubmission(homeworkScores[5], NUMBER_OF_SCORES) == -1);

```

### `displaySuggestedResubmissions()`

As described in the function prototype, this function takes three arguments, an array of strings, a two-dimensional array of scores, and an integer of the class size, and prints the student name and one of the following:

* "`STUDENT` should resubmit homework `NUMBER`", or

* "`STUDENT` has no homework to resubmit".

As should be obvious, it depends on `getNextResubmission()`. As you develop this function, I suggest that you do it in stages:

1. List the student names without any further text;

2. List the student names with the result of a call to `getNextResubmission()`; then

3. List the student names with the correct string (note that the value will be `-1` when no homework needs to be resubmitted).

Try to avoid calling `getNextResubmission()` more than once per student.

### `getHomeworkGrade()`

As described in the function prototype, this function takes four integer arguments (the number of scores with E/M/R/N respectively), and returns a character A/B/C/D/F based on the following criteria:

* 'A' requires an 'E' or 'M' on all 14 with an E on at least 10.

* 'B' requires an 'E' or 'M' on at least 13 with an E on at least 5.

* 'C' requires an 'E' or 'M' on at least 11.

* 'D' requires an 'E' or 'M' on at least 8.

* 'F' if an 'E' or 'M' on 7 or less.

As you work on this function, note that several of the tests look at the combined 'E' and 'M' score so look for a way to simplify that test. Also note that a couple of the tests have multiple criteria.

To test this function you could try variations on the following:

```c++

assert(getHomeworkGrade(10, 4, 0, 0) == 'A';

assert(getHomeworkGrade(9, 5, 0, 0) == 'B';

```

### `getGradeTotals()`

You may find this function to be one of the more conceptually challenging tasks, but there is a relatively simple and elegant solution that can be done in less than 20 lines total. This void function has five arguments: an array of characters and four integers. Part of the complexity is that the four integer parameters are [pass-by-reference] since the purpose of the function is to return four counts.

I suggest that you loop over the scores and use a [`switch`] statement to calculate the totals.

To test this function you could try variations on the following:

```c++

int e = 0, m = 0, r = 0, n = 0;

getGradeTotals(homeworkScores[0], NUMBER_OF_SCORES, e, m, r, n);

assert((e == 6) && (m == 2) && (r == 3) && (n == 3));

```

### `displayGrades()`

This function takes three arguments, a one-dimensional array of student names, a two-dimensional array of homework scores, and an integer of class sizes, and displays `Student Grades` as a heading then lines for each student's name, a tab, and the student's homework letter grade. You should be able to assemble out of the earlier functions and examples.

## Development and Testing

### Compile and Run

To get the program to compile, I suggest that you first comment out the function calls for cases `2` and `3` in the main menu. Test your code to see that it handles invalid integers and the quit request. Add input validation and see that it non-integer input.

Next, add [function stubs] for the declared functions (use the prototypes as guides). Remove the comments in the switch statement and see that the program still compiles correctly.

### Function Tests

Next, add test code before the `while (true)` line to test the `getNextResubmission()` function using the suggested `assert()` functions.

Modify your function stub to simply return an invalid result, such as `-99`, and verify that the code compiles and runs.

Then implement you function based on the suggestions above.

When these tests work, modify them to try a few other things, then move on to the next function.

In c++:

image text in transcribed

image text in transcribed

and the code goes on...

#include // for assert #include // for cin and cout #include // for exit using namespace std; 15 16 17 18 // sizes of arrays 'const int CLASS_SIZE = 6; const int NUMBER_OF_SCORES = 14; 19 24 // Function: displayGradebook || Precondition: names and ids are an array of length size and homeworkScores is a 2D array of size by scores. // Postcondition: Prints a gradebook table to the console. The table includes the students name, id number and all homework scores. No return value. void displayGradebook (string names[], long ids[], char homeworkScores[] [NUMBER_OF_SCORES], int size); 28 30 32 33 34 35 36 // Function: displayGrades // Precondition: names is an array of length size and / homeworkScores is a 2D array of size by scores. // Postcondition: Prints a each students name and their grade to the console. // No return value. void displayGrades (string names[], char homeworkScores[][NUMBER_OF_SCORES), int size); 37 40 41 // Function: displaySuggestedresubmissions // Precondition: names is an array of length size and // homeworkscores is a 2D array of size by scores. // Postcondition: Prints each student's name with a message about the homework, they should resubmit next. No return value. void displaySuggestedResubmissions (string names[], char homeworkScores[][NUMBER_OF_SCORES), int size); 53 54 55 // Function: getGradeTotals || Precondition: homeworkScores is an array of length size and eTotal, mTotal, rTotal, and nTotal represent the number of scores for each grade metric. // Postcondition: The function adds up the individual grade metrics into // eTotal, mTotal, rTotal, and nTotal. // The result is passed back using pass-by-reference variables. No return value. void getGradeTotals(char homeworkScores[], int size, int &e Total, int &mTotal, int &rTotal, int &nTotal); 57 58 LIL 1 TULA, IL TULAI 60 61 62 63 64 65 // Function: getHomeworkGrade // Precondition: eTotal, mTotal, rTotal, and nTotal represent the number of // scores for each grade metric. // Postcondition: Return the letter grade for the homework category based on // the CPTR142 syllabus. char getHomeworkGrade(int eTotal, int mTotal, int rTotal, int nTotal); 67 68 69 70 71 // Function: getNextResubmission // Precondition: homeworkScores is an array of length size // Postcondition: Returns the homework number the student should resubmit. // The suggested homework should be the first homework assignment // that the student scored a Ror N. If all homework has an M or E, then the suggested homework should be the first M. // If the student has all E's, then return -1. int getNextResubmission (char homeworkScores[], int size) { for(int i = @; i // for assert #include // for cin and cout #include // for exit using namespace std; 15 16 17 18 // sizes of arrays 'const int CLASS_SIZE = 6; const int NUMBER_OF_SCORES = 14; 19 24 // Function: displayGradebook || Precondition: names and ids are an array of length size and homeworkScores is a 2D array of size by scores. // Postcondition: Prints a gradebook table to the console. The table includes the students name, id number and all homework scores. No return value. void displayGradebook (string names[], long ids[], char homeworkScores[] [NUMBER_OF_SCORES], int size); 28 30 32 33 34 35 36 // Function: displayGrades // Precondition: names is an array of length size and / homeworkScores is a 2D array of size by scores. // Postcondition: Prints a each students name and their grade to the console. // No return value. void displayGrades (string names[], char homeworkScores[][NUMBER_OF_SCORES), int size); 37 40 41 // Function: displaySuggestedresubmissions // Precondition: names is an array of length size and // homeworkscores is a 2D array of size by scores. // Postcondition: Prints each student's name with a message about the homework, they should resubmit next. No return value. void displaySuggestedResubmissions (string names[], char homeworkScores[][NUMBER_OF_SCORES), int size); 53 54 55 // Function: getGradeTotals || Precondition: homeworkScores is an array of length size and eTotal, mTotal, rTotal, and nTotal represent the number of scores for each grade metric. // Postcondition: The function adds up the individual grade metrics into // eTotal, mTotal, rTotal, and nTotal. // The result is passed back using pass-by-reference variables. No return value. void getGradeTotals(char homeworkScores[], int size, int &e Total, int &mTotal, int &rTotal, int &nTotal); 57 58 LIL 1 TULA, IL TULAI 60 61 62 63 64 65 // Function: getHomeworkGrade // Precondition: eTotal, mTotal, rTotal, and nTotal represent the number of // scores for each grade metric. // Postcondition: Return the letter grade for the homework category based on // the CPTR142 syllabus. char getHomeworkGrade(int eTotal, int mTotal, int rTotal, int nTotal); 67 68 69 70 71 // Function: getNextResubmission // Precondition: homeworkScores is an array of length size // Postcondition: Returns the homework number the student should resubmit. // The suggested homework should be the first homework assignment // that the student scored a Ror N. If all homework has an M or E, then the suggested homework should be the first M. // If the student has all E's, then return -1. int getNextResubmission (char homeworkScores[], int size) { for(int i = @; i

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_2

Step: 3

blur-text-image_3

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions