Question: Write a C++ program that : Write a class template ArrayUtils : template class ArrayUtils { ... }; The above class should contain the following

Write a C++ program that :

Write a class template ArrayUtils:

template

class ArrayUtils {

...

};

The above class should contain the following two member functions:

void print(T array[], int size).-should be able accept an array of any data type and thenumber of elements in the array. The member function should print the elements of the array.

void printReverse (T array[], int size) -should be able to accept an array of anydata type and the number of elements in the array. The member function should print the elements of the array in reverse order.

Note that the above member functions should be defined inside the class declaration, not separately.

The declaration of class ArrayUtils and the main function (given below) should be in a single file named Lab6Part1.cpp

int main() {

ArrayUtils<int> au1;

int arr1[3] = {2, 4, 6};

au1.print(arr1, 3);

au1.printReverse(arr1, 3);

ArrayUtils au2;

string arr2[3] = {"abc", "def", "ghi"};

au2.print(arr2, 3);

au2.printReverse(arr2, 3);

}

Output:

2 4 6

6 4 2

abc def ghi

ghi def abc

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!