Write a function that takes a C string as an input parameter and reverses the st
ID: 3764577 • Letter: W
Question
Write a function that takes a C string as an input parameter and reverses the string. The function should use two pointers, front and rear. The front pointer should initially reference the first character in the string, and the rear pointer should initially reference the last character in the string. Reverse the string by swapping the characters referenced by front and rear, then increment front to point to the next characters and decrement rear to point to the preceding character, and and so on, until the entire string is reversed. Write a main program to test your function on various strings of both even and odd length.
Program must be written in C++
Explanation / Answer
#include #include using namespace::std; void reverse(char *); void main() { // RUN YOUR PROGRAM AT LEAST 3 TIMES TO TEST // A C++ string with exactly 1 char // A C++ string with an even number of characters // A C++ string with an odd number of characters // COPY AND PASTE THE OUTPUT OF EACH RUN AS A COMMENT // AT THE END OF THIS FILE const int SIZE = 101; // declare a char array of 101 characters char charArray[SIZE]; coutRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.