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...
-
1. Is Mayos corporate culture something that other healthcare systems can copy? Would it be possible to develop a national healthcare system modeled on the Mayo Clinic? Explain. 2. Under most...
-
What factors affect region/community location decisions?
-
Assume that the production manager at Alumafloat reminds you that four years ago sales skyrocketed for a while. Demand was so great that production increased to the limit of the companys capacity....
-
The trial balance of Lexington Inn Company at December 31, 2012, and the data needed for the month-end adjustments follow. Adjustment data at December 31 follow: a. Prepaid insurance still in force,...
-
An internal study by the Technology Services department at LaheyElectronics revealed company employees receive an average of 5.5non-work-related e-mails per hour. Assume the arrival of thesee-mails 2...
-
A hydroponic garden uses the 10 m long perforated pipe system shown below to deliver water at 20 degrees Celsius. The pipe is 5 cm in diameter and contains a circular hole every 20 cm. A pump...
-
The possibility of a power outage seems to grow every year because of demand and an aging infrastructure. What can/should companies do to mitigate this risk?
-
Robert Company, which applies overhead to production on the basis of machine hours, reported the following data for the period just ended: Actual units produced: 10,000 Actual variable overhead...
-
The ABC Companys share (based in Canada) is priced at C$ 400 per share. The spot rate of the peso is US$0.76. You expect that the stock price of ABC Company will increase by 62% next year. You also...
-
Problem #5: A corporation is sick of paying taxes each year so it attempts to reach an agreement with the IRS to pay all of its future taxes exactly 6 years from today. The corporation expects it...
-
For the following questions consider exhibit 9 for interest rates and assume for BB: 6.5%, B: 7% and CCC: 7.5%. 4. For both scenarios (10% and 90% debt to capital (Book) ratios), estimate BBBY's bond...
-
Record the following transactions for Adcock Company. (Credit account titles are automatically indented when the amount is entered. Do not indent manually. If no entry is required, select "No Entry"...
-
If demand decreases, what happens to the price of a product, as well as producer surplus? a. The price will increase and the producer surplus will increase. b. The price will decrease and the...
-
Figure displays a 12.0 V battery 3 four uncharged capacitors of capacitances C1 = 4.00F, C2 = 6.00F, and C3 = 3.00F. The switch is thrown to the left side until capacitor 1 is fully charged. Then 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
-
The following are the summarised balance sheets of P Ltd and S Ltd at 31 December 19X6. There were no additions or disposals of fixed assets by the group during the year. (b) P Limited acquired its...
-
X plc acquired 80 per cent of the ordinary share capital of Y plc on 1 January \(19 \mathrm{X} 6\) for \( 300,000\). The lists of balances of the two companies at 31 December 19X6 were as follows:...
-
A P plc acquired 80 per cent of the ordinary share capital of \(S\) plc for \( 150,000\) and 50 per cent of the issued 10 per cent cumulative preference shares for \( 10,000\), both purchases being...
Study smarter with the SolutionInn App