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

List of all available Websheets


Viewing cpp/cppstrings/excited 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>Complete the function that receives a string, <tt>word</tt>, and, <strong>if the string ends with 
   an <tt>!</tt> character</strong>, return a newly formed string that adds another <tt>!</tt> to the end.</p>
<p><strong>Note:</strong> Recall that C++ strings allow use of the <tt>+</tt> operator to perform concatenation.</p>
<p>For example: If the parameter is <tt>Yes</tt> then you should just return:</p>
<pre>
Yes
</pre>
<p>If the parameter is <tt>No!</tt> then you should return:</p>
<pre>
No!!
</pre>
<p>If the parameter is <tt>Wow!!</tt> then you should return:</p>
<pre>
Wow!!!
</pre>
<p>But if the exclamation marks are not at the end, do not alter anything</p>
<p>For example: If the parameter is <tt>What!?</tt> then you should just return:</p>
<pre>
What!?
</pre>
Public permissions remove
Remarks
Comments, history, license, etc.
 
Copied from problem cpp/cppstrings/prefixes (author: redekopp@usc.edu)
Copied from problem cpp/cppstrings/namegame (author: daveagp@gmail.com)
remove
Engine
Template / Reference solution
 
#include <iostream>
#include <string>
using namespace std;
string excited(string word)
{
   \[
      if(word.size() > 0){
         if(word[word.size()-1] == '!'){
            word = word + "!";  
         }
      }
      return word;
   ]\
}
int main()
{
   string word;
   cin >> word;
   // Call the function
   string newword = excited(word);
   // Print the result
   cout << "Orig: " << word << " New: " << newword << 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": "Yes"},
   {"stdin": "No!"},
   {"stdin": "Wow!!"},
   {"stdin": "What!?"}
]
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'.