Question
3460:209Assignment 9-A Assignment 9-A: Reverse C-String using pointers The purpose of this assignment is to help gauge your skills in writing small programs that involve
3460:209Assignment 9-A
Assignment 9-A: Reverse C-String using pointers
The purpose of this assignment is to help gauge your skills in writing small programs that involve pointers. The program also contains functions and may perform input, output, files and file processing, use arrays and vectors and/or c-string/string arrays, flow of control, and/or calculations.
PROGRAM SPECIFICATION
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 character and decrement rear to point to the preceding character, and so on, until the entire string is reversed.
Make sure to test your program on various strings of both even and odd length.
The Functions (in separate files):
1) The only function will be called reverse. This function must use two pointers, and perform the reverse process entirely with those pointers (front and back).
For this program, you can use this code for main. Very simply, your outputmust display correctly using these 5 test cases. Otherwise, credit will be reduced for the problem. ?
int main ()
// these are the testcases charstr1 [] "time"; char str2 [] "straw"; char str3[] "deliver"; char str4 [] "star";
char str5 [] "knits";
cout
reverse (str1) ; reverse (str2) ; reverse (str3); reverse (str4) ; reverse (str5) ;
cout
- return 0;
Code Blocks, C++.
Thanks;)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started