Based on BubbleSortT function above: a. Modify the BubbleSortT function to take as parameter a new...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Based on BubbleSortT function above: a. Modify the BubbleSortT function to take as parameter a new templated class called MyList, instead of a vector. b. Define MyList so that it can be initialized with an array. c. Define an overloaded operator << that takes MyList and outputs its contents to the std:ostream. d. Use the above in the following Test () function: void Test () { const std:size_t arraySize = 10; short shortArr [ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 65, 44, 37 }; double doubleArr [ arraySize ] = { 2.0, 6.0, 4.0, 8.0, 10.0, 12.25, 89.99, 65.0, 45.0, 37.0 }; std:string strArr [ arraySize ] = { "two", "six", "four", "eight", "ten", "twelve", "eighty nine", "sixty five", "forty four", "thirty seven" }; MyList <short> shortList ( shortArr, arraySize ); MyList <double> doubleList ( doubleArr arraySize ); MyList <std:string> strlist ( strArr, arraySize ); std:cout << shortList << std:endl; BubbleSortT ( shortList ); std:cout << shortList << std:endl; std:cout << doubleList << std::endl; BubbleSortT ( doubleList ); std::cout << doubleList <« std::endl; std::cout << strList << std::endl; BubbleSortT ( strlist ); std:cout << strList << std::endl; }// Test Turn in the following documents: MyList.h, MyList.cpp, main.cpp, and output of Test (). main.cpp //Assignment 5.cpp by Tyler Hayes #include "BubbleSortT.h" int main() Test (): return 0: BubblesortT.cpp //BubbleTemplate.cpp by Tyler Hayes #include "BubblesortT.h" void Test (0 std::vector<int> shortArr; shortArr.push_back (2); shortArr.push_back (6) ; shortArr.push_back (4); shortArr.push_back (8); shortArr.push_back (10); shortArr.push_back (12) ; shortArr.push_back (87) ; shortArr.push back (68) ; shortArr.push back (45) ; shortArr.push back (38) ; BubblesortT( shortArr ); std::vector<double> doubleArr; doubleArr.push_back (2.0): doubleArr.push_back (6.0); doubleArr.push_back (4.0): doubleArr.push_back (8.0); doubleArr.push_back (10.0); doubleArr.push_back (12.0); doubleArr.push back (87.0): doubleArr.push back (68.0); doubleArr.push back (45.0); doubleArr.push_back (38.0); BubblesortT( doubleArr ); std::vector<std::string> stringArr; stringArr.push_back ("two"): stringArr.push_back ("six"); stringArr.push_back ("four"); stringArr.push back ("eight") : stringArr.push back ("ten"); stringArr.push back ("twelve"); stringArr.push_back ("eighty seven"): stringArr.push back ("sixty eight"): stringArr.push_back ("forty five"); stringArr.push_back ("thirty eight"); BubblesortT( stringArr ): BubblesortT.h //BubbleTemplate.h by Tyler Hayes #ifndef BUBBLESORTT_H #define BUBBLESORTT_H #include <iostream> tinclude <iomanip> #include <vector> tinclude <string> using std: :setw; using std::cout; using std: :endl; using std: :size_t; template <typename T> void BubblesortT (std::vector <T >6 List) T hold; bool swapMade; cout << "Data items in original order:" << endl; for ( size_t i - 0; i < List.size (); ++i ) cout < setw (16) << List [ i ]; } // for i SwapMade - true; for ( size t pass - 0; pass < List.size () && swapMade; ++pass) cout << "\n\n---New Pass--- swapMade - false; for ( size_tj - 0; j < List.size() - 1; ++j ) if ( List [ il > List [j +11) hold - List [ ); List [j] - List [j + 1 ]; List [j + 11 - hold; cout << "\nSwap made:" << endl; for ( size_t i - 0; i < List.size (); ++i ) cout << setw (16) << List [ i ]; swapMade - true; }// if else swapMade - false; //cout << "\n (No swap) \n" << endl; <----Was used to check computation }// for j }// for pass cout << endl << "\nData items in ascending order:" << end1; for ( size_ti - 0; i < List.size (0: ++i ) cout << setw ( 16 ) << List [ i 1; } // for i cout << endl; void Test ): tendif Based on BubbleSortT function above: a. Modify the BubbleSortT function to take as parameter a new templated class called MyList, instead of a vector. b. Define MyList so that it can be initialized with an array. c. Define an overloaded operator << that takes MyList and outputs its contents to the std:ostream. d. Use the above in the following Test () function: void Test () { const std:size_t arraySize = 10; short shortArr [ arraySize ] = { 2, 6, 4, 8, 10, 12, 89, 65, 44, 37 }; double doubleArr [ arraySize ] = { 2.0, 6.0, 4.0, 8.0, 10.0, 12.25, 89.99, 65.0, 45.0, 37.0 }; std:string strArr [ arraySize ] = { "two", "six", "four", "eight", "ten", "twelve", "eighty nine", "sixty five", "forty four", "thirty seven" }; MyList <short> shortList ( shortArr, arraySize ); MyList <double> doubleList ( doubleArr arraySize ); MyList <std:string> strlist ( strArr, arraySize ); std:cout << shortList << std:endl; BubbleSortT ( shortList ); std:cout << shortList << std:endl; std:cout << doubleList << std::endl; BubbleSortT ( doubleList ); std::cout << doubleList <« std::endl; std::cout << strList << std::endl; BubbleSortT ( strlist ); std:cout << strList << std::endl; }// Test Turn in the following documents: MyList.h, MyList.cpp, main.cpp, and output of Test (). main.cpp //Assignment 5.cpp by Tyler Hayes #include "BubbleSortT.h" int main() Test (): return 0: BubblesortT.cpp //BubbleTemplate.cpp by Tyler Hayes #include "BubblesortT.h" void Test (0 std::vector<int> shortArr; shortArr.push_back (2); shortArr.push_back (6) ; shortArr.push_back (4); shortArr.push_back (8); shortArr.push_back (10); shortArr.push_back (12) ; shortArr.push_back (87) ; shortArr.push back (68) ; shortArr.push back (45) ; shortArr.push back (38) ; BubblesortT( shortArr ); std::vector<double> doubleArr; doubleArr.push_back (2.0): doubleArr.push_back (6.0); doubleArr.push_back (4.0): doubleArr.push_back (8.0); doubleArr.push_back (10.0); doubleArr.push_back (12.0); doubleArr.push back (87.0): doubleArr.push back (68.0); doubleArr.push back (45.0); doubleArr.push_back (38.0); BubblesortT( doubleArr ); std::vector<std::string> stringArr; stringArr.push_back ("two"): stringArr.push_back ("six"); stringArr.push_back ("four"); stringArr.push back ("eight") : stringArr.push back ("ten"); stringArr.push back ("twelve"); stringArr.push_back ("eighty seven"): stringArr.push back ("sixty eight"): stringArr.push_back ("forty five"); stringArr.push_back ("thirty eight"); BubblesortT( stringArr ): BubblesortT.h //BubbleTemplate.h by Tyler Hayes #ifndef BUBBLESORTT_H #define BUBBLESORTT_H #include <iostream> tinclude <iomanip> #include <vector> tinclude <string> using std: :setw; using std::cout; using std: :endl; using std: :size_t; template <typename T> void BubblesortT (std::vector <T >6 List) T hold; bool swapMade; cout << "Data items in original order:" << endl; for ( size_t i - 0; i < List.size (); ++i ) cout < setw (16) << List [ i ]; } // for i SwapMade - true; for ( size t pass - 0; pass < List.size () && swapMade; ++pass) cout << "\n\n---New Pass--- swapMade - false; for ( size_tj - 0; j < List.size() - 1; ++j ) if ( List [ il > List [j +11) hold - List [ ); List [j] - List [j + 1 ]; List [j + 11 - hold; cout << "\nSwap made:" << endl; for ( size_t i - 0; i < List.size (); ++i ) cout << setw (16) << List [ i ]; swapMade - true; }// if else swapMade - false; //cout << "\n (No swap) \n" << endl; <----Was used to check computation }// for j }// for pass cout << endl << "\nData items in ascending order:" << end1; for ( size_ti - 0; i < List.size (0: ++i ) cout << setw ( 16 ) << List [ i 1; } // for i cout << endl; void Test ): tendif
Expert Answer:
Answer rating: 100% (QA)
Answer File Name MyListh ifndef MYLISTH define MYLISTH include using namespac... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
Modify the LU Factorization Algorithm so that it can be used to solve a linear system, and then solve the following linear systems. a. 2x1 x2+ x3 = 1, 3x1+3x2+9x3 = 0, 3x1+3x2+5x3 = 4. b. 1.012x1 ...
-
Modify the LU Factorization Algorithm so that it can be used to solve a linear system, and then solve the following linear systems. a. x1 x2 = 2, 2x1 + 2x2 + 3x3 = 1, x1 + 3x2 + 2x3 = 4 b. 1/3 x1 +...
-
Modify Theorem 11.1 so that it can be used to appraise the maximum error when 2 is unknown. This method can be used only after the data have been obtained.
-
Let x be the number of magazines a person reads every week. Based on a sample survey of adults, the following probability distribution table was prepared. Find the mean and standard deviation of x. 0...
-
An investment allows for end-of-year payments that grow by 3% per payment for 20 years, starting with $2000 at the end of the first year. If the payments earn 4% compounded annually, how much was...
-
Prove, using the same method as in Proposition 6.2.5.1 that \[\begin{aligned}\mathbb{P}_{r}^{(u)}\left[\frac{1}{R_{t}^{\alpha}} \exp \left(-\frac{\mu^{2}}{2} \int_{0}^{t} \frac{d s}{R_{s}^{2}} ight)...
-
An orthotropic AS/3501 carbon/epoxy lamina (see Tables 2.2 and 4.1) is subjected to the plane stress condition \(\sigma_{x}=1000 \mathrm{MPa}, \sigma_{y}=50 \mathrm{MPa}\), and \(\tau_{x y}=50...
-
Cal-C-Yum produces milk and sour cream from a joint process. During June, the company produced 120,000 quarts of milk and 160,000 pints of sour cream (there are two pints in a quart). Sales value at...
-
How do distillation systems incorporate heat integration and energy recovery techniques to optimize energy consumption, and what are the latest advancements in these areas ?
-
Cutler Corporation has a target capital structure of 55 % common stock, 5 % preferred stock, and 40 % debt. Its cost of equity is 16 %, the cost of preferred stock is 10 %, and the cost of debt is 9...
-
Convert 7,402 cm into Sl unit with 3 significant figures. Type your answer...
-
Using the concept of overfitting, explain why when a model is fit to training data, zero error with those data is not necessarily good.
-
What was the first period that the SEC believed that Bristol Myers stuffed the channels?
-
How does the correlation between independent variables impact multiple regression model building?
-
Direct Mailing to Airline Customers. EastWest Airlines has entered into a partnership with the wireless phone company Telcon to sell the latters service via direct mail. The file...
-
Define collinearity. How does it make the interpretation of multiple regression model difficult?
-
If the exchange rate is one dollar to 10 South African rand, how many dollars does it take to buy an item that costs 400 rand?
-
Assume Eq. 6-14 gives the drag force on a pilot plus ejection seat just after they are ejected from a plane traveling horizontally at 1300 km/h. Assume also that the mass of the seat is equal to the...
-
Show that a set {v1, . . . , vk} of k nonzero orthogonal vectors is linearly independent.
-
Repeat Exercise 1 using cubic Bézier polynomials. In Exercise 1 Let (x0, y0) = (0, 0) and (x1, y1) = (5, 2) be the endpoints of a curve. Use the given guidepoints to construct parametric cubic...
-
Show that if B is singular, then ABI K(A)IIAlI
-
In terms of leadership behaviors, someone who focuses on doing a very good job of planning work tasks, setting performance standards, and monitoring results would be described as _________. (a) task...
-
In the discussion of gender and leadership, it was pointed out that some perceive women as having tendencies toward, ________ a style that seems a good fit with developments in the new workplace. (a)...
-
In Houses path-goal theory, a leader who sets challenging goals for others would be described as using the _______ leadership style. (a) autocratic (b) achievement-oriented (c) transformational (d)...
Study smarter with the SolutionInn App