Your team will make a modification of the program #1 above, that will read in the...

90.2K

Verified Solution

Question

Programming

Your team will make a modification of the program #1 above, thatwill read in the string as a “command-line argument” to yourprogram, instead ofhaving the user type it while your program isrunning. Your program should print out the inverted string to thescreen. For example, if you are running your program in the commandwindow (by clicking the Start button, then typing in “cmd”, thenpressing Enter, then using the “cd ” command to change to theappropriate directory where the compiler has placed your .exeexecutable file), a successful run might look like this:M:\CS1113\Lab9>lab9.exe \"This is a test\" tset a si sihT If theuser does not enter the string argument, your program should printout a brief “proper usage” message, which explains to the user theproper syntax of running your program, and which arguments to passin. For example, M:\CS1113\Lab9>lab9.exe Welcome to our Lab 9program which reverses a string! To use this program, please usethe following syntax: lab9.exe “input string”M:\CS1113\Lab9>

#include

#include

using namespace std;

int Reverse(char * destination, const char * source, intnum);

int main() // this is the test/driver code, for yourfunction

{

const int STRINGSIZE = 10;

char oldCString[] = \"Hello!\";

char newCString[STRINGSIZE];

cout << \"oldCString: \" << oldCString <

cout << \"newCString before changing: \" << oldCString<< endl;

Reverse(newCString, oldCString, STRINGSIZE); // testing yourfunction...

cout << \"newCString after Reverse: \" << newCString<< endl;

return 0;

}

// Reverses a C-string passed in (source), and places thereversed

// C-string into (destination).

// (num) should represent the maximum valid length of(destination).

// If no null-zero character is found in (source) within(num-1)

// characters,the function will only read up to (num-1)characters

// from (source), and then copy the reversed characters to

// (destination) and append a null-zero to the end of it.

// The function will return the number of characters placedinto

// (destination), including the null-zero.

// The function MUST use pointer notation (not array notation)inside

// it. However, you might find it useful to use arraynotation

// temporarily while developing the function, and thenreplace

// with pointer notation before turning in the assignment.

int Reverse(char * destination, const char * source, intnum)

{

for (int x = 0; x < strlen(source); x++)

*( x + destination) = *( strlen(source) + source - 1 - x);

*(destination + strlen(source)) = '\0';

return 0;

}

Answer & Explanation Solved by verified expert
4.5 Ratings (762 Votes)
include include using namespace stdint Reversechar destination const char source intnumint mainint    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students