Question
1. Design a header file named BonusUtility.h that contains a namespace named BonusUtility. The BonusUtility namespace should contain definitions of the following functions: A function
1. Design a header file named BonusUtility.h that contains a namespace named BonusUtility. The BonusUtility namespace should contain definitions of the following functions:
A function template named swap that takes 2 references as parameters and swaps the values inside. i. HINT: This function template should work for any data type ii. HINT: DO NOT use the default swap function that is included in namespace std.
A function template named displayArray that takes an array of any type and the size of the array as parameters, then displays it separated by commas.
3. (8 marks) Design a header file named RandomArray.h that contains a namespace named RandomArray. The RandomArray namespace should contain the definition of a class named RandomIntArray which contains the following members: - Data Members o A private data member to store a dynamic integer array o A private data member to store the size of the dynamic int array - Member Functions o A public non-inline member function named randomize that will take 3 parameters (a minimum, maximum, and seed) and fill the array with randomize numbers using rand(). The seed argument should have a default value of 104 use srand() to set the seed before using rand() o 2 overloaded functions: A public non-inline constructor function named generateArray that takes 0 arguments. This function dynamically allocates an array with 10 items and a range of 0-100. A public non-inline constructor function named generateArray that takes 3 arguments. Parameters: a size, a minimum, and a maximum. o The minimum argument should have a default value of 1000 o The maximum argument should have a default value of 2000 Use the this pointer to set all data members Using these parameters, generate a dynamic array and populate it with random numbers. o An overloaded copy assignment (operator=) member function: This function should: Guard from self assignment Deallocate any memory before copying data if the space cannot be used o A public non-inline member function that reverses the array Example: Before Reversing: 5,9,2,8,4,6,64 After Reversing: 64,6,4,8,2,9,5
4. This should utilize your swap utility function o A public inline member function that will display the array.
5. This should utilize your displayArray utility function o A public inline destructor function that deallocates memory for the dynamic array.
3. Design the main program named LabTest1.cpp that will be used to test the class and function template above. The main program must do the following: - Prompt the user to enter the number of arrays they want to create - Use this number to create a dynamic array of RandomIntArray objects. - For each item in the dynamic array, ask the user to choose if they want a custom array or default array o If they choose default, generate the array with no arguments o If they choose size, ask the user to enter a size o If they choose range, ask the user to enter a size, minimum, and maximum - Display all of the randomly generated arrays to the user - Reverse all of the arrays - Display all of the reversed arrays to the user Please note that the error checking & handling for invalid inputs is required. The numbers generated should match the output below due to the seed that was specified. All input numbers and output arrays should be the exact same.
A sample format of the output of the program could be as follows: ENTER THE NUMBER OF RANDOM INTEGER ARRAYS: 3 ARRAY 1: Default(d), Size (s), Range (r): d ARRAY 2: Default(d), Size (s), Range (r): s Size: 5 ARRAY 3: Default(d), Size (s), Range (r): r Size: 10 Minimum: 2 Maximum: 8 --BEFORE REVERSING-- Array 1: 75, 28, 24, 8, 25, 95, 37, 36, 85, 69 Array 2: 377, 396, 291, 345, 477 Array 3: 2, 5, 5, 4, 5, 6, 7, 6, 5, 3 --AFTER REVERSING-- Array 1: 69, 85, 36, 37, 95, 25, 8, 24, 28, 75 Array 2: 477, 345, 291, 396, 377 Array 3: 3, 5, 6, 7, 6, 5, 4, 5, 5, 2
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