Question

In: Computer Science

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

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

#include <iostream>

#include <cstring>

using namespace std;

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

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

{

const int STRINGSIZE = 10;

char oldCString[] = "Hello!";

char newCString[STRINGSIZE];

cout << "oldCString: " << oldCString << endl;

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

Reverse(newCString, oldCString, STRINGSIZE); // testing your function...

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

return 0;

}

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

// 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 placed into

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

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

// it. However, you might find it useful to use array notation

// temporarily while developing the function, and then replace

// with pointer notation before turning in the assignment.

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

{

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

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

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

return 0;

}

Solutions

Expert Solution

#include <iostream>

#include <cstring>

using namespace std;

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

int main(int argc,char* argv[]) // this is the test/driver code, for your function

{

    const int STRINGSIZE = 100;

    char oldCString[] = "Hello!";

    char newCString[STRINGSIZE];

    printf("\nWelcome to our Lab 9 program which reverses a string!\n");

    // if there is no arguments print message
    if(argc==1)
    {
         printf("\nTo use this program, please use the following syntax: lab9.exe \"input string\"\n");
    }

    // else reverse the string
    else
    {
        // copy command line argument to oldString
        strcpy(oldCString,argv[1]);

        cout << "oldCString: " << oldCString << endl;

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

        Reverse(newCString, oldCString, STRINGSIZE); // testing your function...

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

    }
    return 0;

}

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

// 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 placed into

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

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

// it. However, you might find it useful to use array notation

// temporarily while developing the function, and then replace

// with pointer notation before turning in the assignment.

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

{

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

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

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

    return 0;

}


Output


Related Solutions

Make a modification of the program below, that will read in the string as a “command-line...
Make a modification of the program below, that will read in the string as a “command-line argument” to your program, instead of having the user type it while your program is running. Your program should print out the inverted string to the screen. #include <iostream> #include <cstring> using namespace std; int Reverse(char * destination, const char * source, int num); int main() // this is the test/driver code, for your function { const int STRINGSIZE = 10; char oldCString[] =...
when some monosaccharaides are in solution: what structural modification occurs? considering the structural modification above, what...
when some monosaccharaides are in solution: what structural modification occurs? considering the structural modification above, what type of isomerisation can occur?
Using java, I need to make a program that reverses a file. The program will read...
Using java, I need to make a program that reverses a file. The program will read the text file character by character, push the characters into a stack, then pop the characters into a new text file (with each character in revers order) EX: Hello World                       eyB       Bye            becomes    dlroW olleH I have the Stack and the Linked List part of this taken care of, I'm just having trouble connecting the stack and the text file together and...
1. What prediction does the neutral theory make that is not true and what modification was...
1. What prediction does the neutral theory make that is not true and what modification was made to its assumptions to produce a new theory created by Ohta that better fit the data? A) genetic change should be constant/most mutations are under very weak selection B) evolutionary rate should be a function of mutation rate per generation/most mutations are under very weak selection C) evolutionary rate should be a function of mutation rate per generation/drift is not acting D) evolutionary...
Write a menu program to have the above options for the polynomials. Your menu program should...
Write a menu program to have the above options for the polynomials. Your menu program should not use global data; data should be allowed to be read in and stored dynamically. Test your output with the data below. Poly #1: {{2, 1/1}, {1, 3/4}, {0, 5/12}} Poly #2: {{4, 1/1}, {2, -3/7}, {1, 4/9}, {0, 2/11}} provide a C code (only C please) that gives the output below: ************************************ *         Menu HW #4 * * POLYNOMIAL OPERATIONS * * 1....
This will be your first collaborative assignment with your team. Your team will submit one 1-2...
This will be your first collaborative assignment with your team. Your team will submit one 1-2 page plan outlining the methods your team will use to work together. Topics such as communications, expectations of team members, and technology use should be covered.
*********C++ Program************ This assignment is the continuation of project 4, with the modification and improvement with...
*********C++ Program************ This assignment is the continuation of project 4, with the modification and improvement with the following modifications: In Frac.h, replace the methods addition (const Fraction & ), subtraction( const Fraction& ), multiply( const Fraction & ), divide( const Fraction & ), void printFraction() by overloading operators +, -, *, /, << respectively. Add overloading operators > and < so that they can compare two Fractions. Write your own implementation file which is named Frac2.cpp to replace Frac.cpp and...
In Python, your program will read in a number (no need to prompt the user), and...
In Python, your program will read in a number (no need to prompt the user), and then reads in that number of lines from the terminal. Then the program should print an array of strings formatted in a nice regular box. So if the user inputs this: 5 Grim visaged war has smooth’d his wrinkled front And now, instead of mounting barded steeds To fright the souls of fearful adversaries He capers nimbly in a lady’s chamber To the lascivious...
Your team is looking for a way to make some revenue as either a for-profit or...
Your team is looking for a way to make some revenue as either a for-profit or not-for-profit organization. This organization can market locally, nationally, or internationally. The product that you have decided to sell is lemonade. To make the endeavor work, you will have to define a marketable form of the drink and decide on a target market. Your marketing team's mission is to prove the company's goals will be met by providing research, strategy development, and the reason why...
As noted above, your CEO has traveled to London, UK to make a presentation to the...
As noted above, your CEO has traveled to London, UK to make a presentation to the company’s board of directors. Your company, Belleaqua, produces bottled water for consumer use in Canada. Recent negative publicity for the bottled water industry has caused your CEO to design a new bottle return policy for Belleaqua’s products. This would greatly reduce the amount of plastic currently finding its way to landfills and into the oceans. The first bottled water company to successfully launch such...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT