Question
For this program, Additionally, you will need to create a short driver program that demonstrates your template class working with a few different numeric data
For this program, Additionally, you will need to create a short driver program that demonstrates your template class working with a few different numeric data types.CHALLENGETest your program using integers, doubles, and chars. For each test, randomize the values stored in the initial array. Each type will need its own randomization method (to ensure integers for the integers array, decimal values for the doubles, and letters for the chars). Because of this, you will likely not want to include the randomization code in the template class itself.Code:// Used for input & output function#include // Used for random function#include // Used for time as a seed for random function#include using namespace std;// Create a template classtemplateclass Array{ // Used to store the size of array int size; // Used to store array elements T *arr; public: // Constructor to intialize array Array(int n) { // Store the size of array size = n; // Dynamic allocation of array arr = new T[n]; // Loop intialize array randomally for (int i = 0; i { // Store the number as ith element arr[i] = static_cast(rand() % 101); } } // Method to find the maximum element in array T findMax() { // Used to store the maximum element T max; // Intialize max with 1st element of array max = arr[0]; // Loop for each array element for(int i = 0; i { // If max is less than ith element if(max // Store ith element as max max = arr[i]; } // Return maximum element return max; } // Method to find the minimum element in array T findMin() { // Used to store the minimum element T min; // Intialize min with 1st element of array min = arr[0]; // Loop for each array element for(int i = 0; i { // If min is greater than ith element if(min > arr[i]) // Store ith element as min min = arr[i]; } // Return minimum element return min; }};// Main methodint main(){ // Use current time as seed for random function srand(time(0)); // Create an object that contains 10 elements of integer type Arraya(10); // Find the maximum element cout // Find the minimum element cout return 0;}
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