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

List of all available Websheets


Viewing cpp/var-expr/gpa 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>Assume a student is taking 4 classes. Each class has a number of units and a grade value.</p>
<p>Ask the user to enter the number of units and grade value for each of their classes then output their gpa
   which is a weighted average of their grade values.</p>
<p>
   Below is a table showing grade value that you should enter for each letter grade.</p>
<table>
   <tr><th>Letter</th><th>Value</th></tr>
   <tr><td>A</td><td>4.0</td></tr>
   <tr><td>A-</td><td>3.7</td></tr>
   <tr><td>B+</td><td>3.3</td></tr>
   <tr><td>B</td><td>3.0</td></tr>
   <tr><td>B-</td><td>2.7</td></tr>
   <tr><td>C+</td><td>2.3</td></tr>
   <tr><td>C</td><td>2.0</td></tr>
   <tr><td>C-</td><td>1.7</td></tr>
   <tr><td>D+</td><td>1.3</td></tr>
   <tr><td>D</td><td>1.0</td></tr>
   <tr><td>F</td><td>0.0</td></tr>
</table>
<p>Then output which day of the week it will be (again use <tt>1-7</tt> for Sun. through Sat.) after the <tt>n</tt> days will pass.</p>
Public permissions remove
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/var-expr/in_n_days (author: redekopp@usc.edu)
Copied from problem cpp/var-expr/char_arith (author: redekopp@usc.edu)
Copied from problem cpp/var-expr/hello (author: daveagp@gmail.com)
remove
Engine
Template / Reference solution
 
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
   // declare variables here
   \[
      int units1, units2, units3, units4;
      double val1, val2, val3, val4;
      double gpa;
   ]\
   
   cout << "Enter the units and grade value of your first class: " << endl;
  \[
   cin >> units1 >> val1;
  ]\
   cout << "Enter the units and grade value of your second class: " << endl;
  \[
   cin >> units2 >> val2;
  ]\
     
   cout << "Enter the units and grade value of your third class: " << endl;
  \[
   cin >> units3 >> val3;
  ]\
      cout << "Enter the units and grade value of your fourth class: " << endl;
  \[
   cin >> units4 >> val4;
  ]\
  // Compute their gpa
  \[
   double total_units = units1 + units2 + units3 + units4;
   gpa = (units1*val1 + units2*val2 + units3*val3 + units4*val4) / total_units;
   
  ]\
     cout << "GPA is  " << \[ gpa ]\ << endl;
   
  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":"4 4.0 4 4.0 4 4.0 2 4.0", "args":[]},
   {"stdin":"4 3.7 4 3.3 4 4.0 4 3.0", "args":[]},
   {"stdin":"3 2.7 4 3.3 3 3.7 2 4.0", "args":[]}
   
]
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'.