Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IN C++ PROGRAMMING USING THE CODE PROVIDED: Create a set of three functions that take a pointer to an array as an input parameter and

IN C++ PROGRAMMING USING THE CODE PROVIDED:

Create a set of three functions that take a pointer to an array as an input parameter and reverses the contents of the array. The function should use two pointers, front and rear. The prototypes for functions reverse1, 2, and 3 hath been put in place for you. The front pointer should initially reference the first element in the array, and the rear pointer should initially reference the last element in the array. Reverse the array by swapping the elements referenced by front and rear, then increment front to point to the next element and decrement rear to point to the preceding element, and so on, until the entire array is reversed. So the function must use two pointers, and perform the reverse process entirely with those pointers (front and back). The program also already contains a constant mySize shared by all with the three prototypes for three different data types held by these arrays. The driver in task B includes the code to call the functions as well as handle the output of the results. The approach to writing these functions is to be able to have one function handle bool type, char type, and short type with the same logic. So the goal for writing these first three reverse functions should not only be to write the solution, but also to universally accomplish it with the functions being clones.

IN C++ PROGRAMMING USING THE CODE PROVIDED:

const size_t mySize = 25; void reverse1(char *); // The prototype for the first function void reverse2(bool *); // The prototype for the second function void reverse3(short *); // The prototype for the third function

int main

{ // these are the test cases char str1[] = "sriahc gab naeb evah emos"; bool str2[] = {0,0,0,1,1,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0}; short str3[] = {99,98,97,96,95,94,93,92,91,90,89,88,87,86,85,84,83,82,81,80,79,78,77,76,75};

cout << " *** - Separate Reverse Functions - ***" << endl << endl; cout << "The arrays before and after reversing: " << endl; cout << " array1: " << str1 ; reverse1(str1); cout << endl << " array1: " << str1 << endl; cout << " array2: "; for (int i = 0; i < mySize; ++i) { cout << str2[i] << " " ; } reverse2(str2); cout << endl;

cout << " array2: "; for (int i = 0; i < mySize; ++i) { cout << str2[i] << " " ; } cout << endl;

cout << " array3: "; for (int i = 0; i < mySize; ++i) { cout << str3[i] << " " ; } cout << endl;

reverse3(str3); cout << " array3: "; for (int i = 0; i < mySize; ++i) { cout << str3[i] << " " ; } cout << endl;

cout << "end of task B" << endl; cin.get(); }

//THREE FUNCTIONS FOR REVERSING THE THREE ARRAYS GO HERE

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

Database Marketing The New Profit Frontier

Authors: Ed Burnett

1st Edition

0964535629, 978-0964535626

More Books

Students also viewed these Databases questions

Question

How to find if any no. is divisble by 4 or not ?

Answered: 1 week ago

Question

Explain the Pascals Law ?

Answered: 1 week ago