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

Due to lack of time, I need help with completing a c++ template/shell. I will ad

ID: 3857250 • Letter: D

Question

Due to lack of time, I need help with completing a c++ template/shell. I will add the description and the template below. Any help would be greatly appreciated. Thank you.

Write a C++ function that will reverse the characters in a C++ string The function prototype is void reverse( char word|) HE UND I Note: - The function can not have any work arrays, i.e., the function cannot have any local variables that are arrays. Note: - An Algorithm is outlined below: have 2 subscripts left and right find the 10' in the array and set right to be one less than the subscript where the 10 is located - set left to 0 - set up a while loop inside the while loop switch word[left] with word[right] - you will need a work char variable for the swith move left up by 1 and move right down by 1

Explanation / Answer

Comments have been added for explanation.

Code:

#include<iostream>
using namespace::std;

const int MAX_SIZE = 15; // Max word size of word, allow for ''

void reverse(char word[]); // function prototype

int main()
{

char word[MAX_SIZE];

cout << endl << "Enter a word : ";
cin >> word;
cout << "You entered the word " << word << endl;

reverse(word);

cout << "The word in reverse order is " << word << endl;

return 0;
} // main method ends

void reverse(char word[])
{
//created left and right as two subscripts
int left=0,right;//left initialized to 0


//By iterating through the string found '' and set right to the last position
for(int i=0; ;i++){ //works infinitely

if(word[i]==''){
right=i-1; //right is set to the last position
break; //breaks when '' is found i.e the end of string
}

}//for ends

//work variable is used to temporarily storing the left character while switching
while(left<right){ //This loop runs till we reach the center of the string

//Swapping operation
char work=word[left];
word[left]=word[right];
word[right]=work;

left++;
right--;

}//while ends

} //reverse function ends