View the step-by-step solution to:

Question

For this C++ assignment, we define three types of "reversal"


A "line" reversal reverses the

entire line. In a line reversal, 

"Hello world!" becomes "!dlrow olleH"


A "word" reversal reverses each word. In a word reversal, 

"Hello world!" becomes "olleH !dlrow"


A "lineword" reversal performs a line reversal and a word reversal. In a lineword reversal, 

"Hello world!" becomes "world! Hello".


No matter how many spaces between words in the input, the output should have only one space after each word. So a line reversal of 

"Hello world!" becomes "!dlrow olleH"


The program is told which type of reversal to perform by providing a single command line argument, "line", "word", or "lineword".

If no command line arguments are provided, the program should print "MISSING FLAG" and stop.

If an unrecognized command line argument is provided, the program should print "UNKNOWN FLAG" followed by the unrecognized argument, and stop.

If more than one command line argument is provided, the program should print "TOO MANY FLAGS" and stop.


Hints:

1. your input to the program is lines read from standard input

2. the best way to structure the program is to interpret the command line arguments, remembering what was specified, THEN loop reading lines and performing the specified reversal

3. IF you see a message about binary file detected, it's probably because you printed out a null character. This is likely caused by an off-by-one error. If you reversed the line by looping through the input string, starting at the end and looping to the beginning, that's probably the error. Remember if the string is of length X, the characters go from 0 ... X-1. SO... don't start your loop at X, or you're reading past the end of the string.


Question:

I am able to get the command from argv[1] but am not able to detect multiple commands. How should I detect multiple commands, so that I can define them as "Too many flags"

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Let our 24/7 Computer Science tutors help you get unstuck! Ask your first question.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes
A+ icon
Ask Expert Tutors