Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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 output must display

correctly using these 5 test cases.

int main()

{

// these are the test cases

char str1[] = "time";

char str2[] = "straw";

char str3[] = "deliver";

char str4[] = "star";

char str5[] = "knits";

cout << "The strings before reversing: " << endl;

cout << str1 << " " << str2 << " " << str3 << " " << str4 << " " << str5 << " " << endl;

reverse(str1);

reverse(str2);

reverse(str3);

reverse(str4);

reverse(str5);

cout << "The strings after reversing: " << endl;

cout << str1 << " " << str2 << " " << str3 << " " << str4 << " " << str5 << " " << endl;

return 0;

}

Make sure that your programs follow good documentation standards and follow the

requirements for assignments.

Dont forget

to use pre and post condition comments.

Note functions and data validation are now

required. Do not use

using namespace std;

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Refactoring Databases Evolutionary Database Design

Authors: Scott Ambler, Pramod Sadalage

1st Edition

0321774515, 978-0321774514

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago