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

List of all available Websheets


Viewing cpp/eggs 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
 
Eggs are pacakged in cartons holding 1 dozen eggs and then boxes
that store 5 cartons each.  Given a number of eggs by the user, compute
how many cartons and boxes the pacakger will need.
Public permissions remove
Remarks
Comments, history, license, etc.
 
Originally by Mark Redekopp (redekopp@usc.edu) and Dave Pritchard (daveagp@gmail.com)
remove
Engine
Template / Reference solution
 
#include <iostream>
using namespace std; 
int main() {
   // Declare a variable to store the number of eggs
   //  since we must declare a variable before storing to it
   \[ int eggs; ]\
   // Output a prompt to ask for the number of eggs
   cout << "How many eggs do you have?" << endl;
   // Read in the number of eggs
   \[ cin >> eggs; // read input  ]\
   int num_cartons, num_boxes;
   // Write code to compute the number of boxes & cartons needed
   \[
   num_cartons = eggs / 12;
   if(eggs % 12 != 0){
     num_cartons++;
   }
   num_boxes = num_cartons / 5;
   if(num_cartons % 5 != 0){
     num_boxes++;
   }
   ]\
   cout << "You need " << num_boxes << " boxes and " << num_cartons << " cartons" << 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": "12"},
   {"stdin": "60"},
   {"stdin": "61"},
   {"stdin": "119"},
   {"stdin": "120"},
   {"stdin": "1"}
]
Solution visibility remove
Is example?
i.e., just a demo
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'.