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

List of all available Websheets


Viewing cpp/cppstrings/namegame by daveagp@gmail.com. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
PropertyValue
Description
html markup
shown to student
 
The function <tt>namegame(string s)</tt> should return
a string which is the same as its input, except
starting with <tt>Z</tt>.
<p>
For example <tt>namegame("David")</tt> returns <tt>"Zavid"</tt>.
Public permissions remove
Engine
Template / Reference solution
 
#include <iostream>
#include <string>
using namespace std;
// avoid copying the long name
string namegame(const string& name) {
\[
   return "Z" + name.substr(1);
\show:
   name[0] = 'Z'; // whoops
   return name;
]\
} 
int main() {
   string name;
   cin >> name;
   cout << "My name is: " << name << endl;
   cout << "Ziggity Zap " << namegame(name) << endl;
   cout << "My name is: " << name << endl; // should be unchanged
}
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": "Rumpelstiltskin"},
   {"stdin": "Wolfeschlegelsteinhausenbergerdorff"}
]
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'.