Question: IN C++, 1.1 BUBBLE SORTING Bubble sorting is a prevailing method to sort an array in either descending or ascending order. Before you start, make

IN C++, 1.1 BUBBLE SORTING Bubble sorting is a prevailing method to sort an array in either descending or ascending order. Before you start, make sure youre able to write a small bubble-sorting function to sort an int array, which has two functions as below void swap(a, b) void bubbleSorting(int array[ ], const int& size) Try to use char, double, float array instead of int array, and test your program to make sure all work fine in descending or ascending order.

Then a natural intuition comes out that you could use template function to re-write this bubble-sort function.

1.2 CLASS DEFINITION Write a template class Holder which has a private template member variable element which might be char, double, float, int or string type. You should design member functions as below

Default constructor

Any appropriate operation inside is encouraged, and left empty is also fine

Constructor with one argument Pass in value of outside to element by argument

Destructor

Overloaded operator + = Take a Holder object as argument, and would return a newly created Holder object with summed/equal element. Overloaded stream <>

Appropriate accessor function Besides, you should also design a non-member overloaded operator - which takes two Holder object and return a third object with difference value of element.

1.3 MAIN FUNCTION Write a main function to test bubble sorting for a Holder array. 1

. Read from command line two positive integers. First int would be the size of Holder array (size is integers from 4 to 8), and second int would be either 1 or 2 (1 means ascending order and 2 means descending order).

Should judge argc 3 or not, should judge whether input numbers are positive and integers within designated range. For example, would test ./solution abc -2, ./solution -1.3 1.456, ./solution 10.346 string, and all these should fail and exit erroneously.

. 2. Create a Holder dynamic array After creating the array, you should use overloaded stream to enable user to define some (not all) Holder objects in the array, and rest of objects in the array should be defined by calling all different overloaded + - = operators. 3

. Call overloaded stream << to print the current array (before sorted)

. Bubble sort the Holder array by invoking your bubbleSort function, and call overloaded stream >> to print the current array (after sorted). Make sure the array is actually sorted well

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!