List of all available Websheets
Viewing cpp/cs102/practice11/reversal by redekopp@usc.edu. You have unsaved changes. Log in above to create, edit, preview and publish Websheets.
Property | Value |
---|---|
Description html markup shown to student | <p>Your friend tells you that she's disappointed that "palindrome", a word or phrase that is the same backwards and forwards, is not itself a palindrome. Words such as "Bob" or "Taco cat" are palindromes.</p> <p>However, "palindrome" is an "emordnilap", which is a recently coined word that denotes a word or phrase that creates another word backwards (such as "dog" and "god" or "desserts" an "stressed".</p> <p>You decide to write a program that automatically reverses a string of up to 50 characters and prints out the result. Use arrays to reverse up to 50 characters and print them back to the screen. Assume there are no spaces.</p> |
Public permissions | |
Remarks Comments, history, license, etc. | Copied from problem cpp/cs102/practice10/netflixTimes (author: jmell@usc.edu) Copied from problem cpp/cs102/practice9/forCapitalization (author: jmell@usc.edu) Copied from problem cpp/cs102/practice8/for1 (author: jmell@usc.edu) Copied from problem cpp/cs102/practice7/whileMC1 (author: jmell@usc.edu) |
Engine | |
Template / Reference solution |
using namespace std; int main(){ char buffer[50]; cout<<"Enter a string to be reversed:"<<endl; //size as a variable is needed here because you don't know, a priori, how much of buffer will be filled //you will later learn a way to measure the size of an array directly, but don't worry about that here. int size = 0; for(int i = 0; cin>>buffer[i]; i++) { size++; } // What do you need to add to the end of the array? \[ REDACTED ]\ char reversedbuffer[50]; // Reverse the buffer from the buffer array into the reversedbuffer array // Don't forget what you need to add to the end of the reversedbuffer array \[ REDACTED ]\ cout<<"reversed string:"; // Print out the string (don't use a loop if you can help it) // Don't print a newline (endl)...we'll do that ourselves. \[ REDACTED ]\ cout << 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":"desserts", "args":[]}, {"stdin":"abcdefghijklmnopqrstuvwxyz", "args":[]}, {"stdin":"emosewa", "args":[]}, {"stdin":"amanaplanacanalpanama", "args":[]} ] |
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'.