Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

any suggestions? Part 2: Use arrays & strings & functions. Description: Use the

ID: 3878622 • Letter: A

Question

any suggestions?

Part 2: Use arrays & strings & functions. Description: Use the C++ string header and write a function that is passed two strings and copies the second str function to manipulate the characters in a C++ strin string, calls your reverse function, and prints out th function getline(cin,str) for input of text with spaces. ing into the first, in reverse order. The objective is to write and demonstrate your own g. Write a main function that reads in the original e reversed string. You will want to use the lO Example: Original string: My Name Reversed string: emaN yM Notes We want a separate file for the reverse function. You can write the code in main first just to get the string-handling down, if you want, and when it is working then make it into a function - Write a main to exercise your function and to illustrate that the function is working properly. (This is known as a driver program. It "drives/tests" some other function/code.) - Test your program with several strings Nicely format and label your output -Put both C++ files and the .h header into the D2L drop box, along with a screenshot showing the program working.

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements. Defined following things in this answer.

//REVERSE.h file

#ifndef REVERSE_H

#define REVERSE_H

using namespace std;

/**

method to reverse a string

str- string to be reversed

dest- where the reversed string is to be copied to */

void strReverse(string &dest,string str){

    for(int i=str.length()-1;i>=0;i--){

        /**

         * copies charcters from the last index to the first index into the dest string */

        dest=dest+str[i];

    }

}

#endif

//main.cpp file

#include <iostream>

#include "REVERSE.h"

using namespace std;

int main() {

              cout<<"Enter a string:"<<endl;

    string a,b;

    /**

     * getting a string input from user */

    getline(cin,a);

    /**

     * calling the reverse method we have defined */

                strReverse(b,a);

                /**

                * Displaying the reversed string */

    cout<<"Reverse: "<< b;

}

/*OUTPUT*/

Enter a string:

hello world

Reverse: dlrow olleh