Not logged in. Log in with GitHub. About Websheets.

List of all available Websheets


Viewing cpp/arraypassing/grade-histogram by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
<p>Write a function that will take in an array of student <tt><strong>scores</strong></tt> between <tt>0</tt>
and <tt>100</tt> along with the <tt><strong>size</tt></strong> of the array and a <tt><strong>totals</strong></tt> array of 5 elements where the 0th represents the total number of As in the class, the 2nd represents the number of Bs, ...,
 while the 4th represents the number of Fs.  Your function may assume the 5 element
array is initialized to 0s.  It should then count the total number of As, Bs, Cs, Ds, and Fs.  The range for each letter grade are given below:</p>
<table>
<tr><th>Range</th><th>Letter Grade</th></tr>
<tr><td><strong>90-100<strong></td><td>A</td></tr>
<tr><td><strong>80-89<strong></td><td>B</td></tr>
<tr><td><strong>70-79<strong></td><td>C</td></tr>
<tr><td><strong>60-69<strong></td><td>D</td></tr>
<tr><td><strong>0-59<strong></td><td>F</td></tr>
</table>
   
   <p>Rather than write a lot of <tt>if..else if</tt> statements, use them only for <tt>100</tt> and values <tt>49</tt> or below. 
      Consider how you could use math to convert the decade ranges 90-99, 80-89, ..., 50-59 to the correct index of the <tt>totals</tt> array.
      <strong>Write a table to show the input and the desired output.</strong></p>
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/arrays/reverse (author: redekopp@usc.edu)
Copied from problem cpp/cs103/hw-arrays/reverse_copy (author: redekopp@usc.edu)
remove
Engine
Template / Reference solution
 
#include <iostream>
using namespace std;
void letterGrades(int scores[], int size, int totals[])
{
   \[
REDACTED
]\
}
int main()
{
   int scores[50];
   int n = 0, num;
   // Track number of As, Bs, Cs, Ds, and Fs
   int totals[5] = {0,0,0,0,0};
   
   // Get all the scores
   cin >> num;
   while(num != -1){
      scores[n++] = num;
      cin >> num;
   }
   
   // Call the letterGrades function to compute
   //  the total As, Bs, ...
   letterGrades(scores, n, totals);
   
   // Output the results
   char letter = 'A';
   for(int i=0; i < 5; i++){
      cout << letter << ": " << totals[i] << endl;
      if(letter == 'D'){
         letter += 2;  
      }
      else {
         letter++; 
      }
   }
   
   return 0;
}
C++ test suite
json list of stdin/args tests
e.g. [{"stdin":"hi", "args":["4", "5"]},
{"stdin":"noargs"}]

to just run once with no input use [{}]
 
[
   {"stdin": "100 90 80 70 60 50 51 52 93 99 -1"},
   {"stdin": "80 81 82 83 84 63 62 61 59 100 -1"},
   {"stdin": "10 20 30 40 50 60 70 80 90 100 95 -1"}
]
Solution visibility remove


Optional properties:

Note: problems are open-source by default (see 'Public permissions'). Assumed license for open problems is Creative Commons 4.0 Attribution-ShareAlike unless specified in 'Remarks'.