List of all available Websheets
Viewing cpp/pointers/increase_by by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | Write a program <tt>increase_by</tt> that takes a command-line argument <tt>n</tt> and then adds <tt>n</tt> to every number on input, and prints them out one per line. For example <pre> ./increase_by 5 </pre> with input <pre> 1 2 100 </pre> should print <pre> 6 7 105 </pre> |
Public permissions | |
Engine | |
Template / Reference solution |
using namespace std; int main(int argc, char* argv[]) { // parse command-line argument, save as variable n \[ int n = atoi(argv[1]); ]\ // put each number from standard input as "read", one at a time int read; while (cin >> read) { cout << \[read + n]\ << 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": "1\n2\n100", "args": ["5"]}, {"stdin": "1\n0\n3", "args": ["1"]}, {"stdin": "11\n22", "args": ["-10"]} ] |
Solution visibility |
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'.