Question: in C++ you are asked to use the template method pattern to refactor (i.e., redesign) this algorithm class. You also need to draw the UML
in C++ you are asked to use the template method pattern to refactor (i.e., redesign) this algorithm class. You also need to draw the UML diagram. You need to design classes so that the following main function will output the following. Your program must use this main function.
#include
int main(int argc, char** argv) { BubbleSort bs; IntegerVectorSortable ivs; ivs.insertInteger(5); ivs.insertInteger(4); ivs.insertInteger(6); ivs.insertInteger(10); cout<<"***************** Before Sorting Integers Decreasing"< cout<<"***************** After Sorting Integers Increasing"< return 0; } other functions: #ifndef SORTABLEVECTOR_H #define SORTABLEVECTOR_H class SortableVector{ public: virtual unsigned int getSize() const = 0; virtual bool smaller(int i, int j) const = 0; virtual void swap(int i, int j) = 0; }; #endif /* SORTABLEVECTOR_H */ -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #ifndef INTEGERVECTORSORTABLE_H #define INTEGERVECTORSORTABLE_H #include class IntegerVectorSortable: public SortableVector { protected: vector ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #ifndef BUBBLESORT_H #define BUBBLESORT_H #include "SortableVector.h" class BubbleSort{ public: void sortDecreasing(SortableVector* sortableVector){ bool sorted = false; int n=sortableVector->getSize(); while( !sorted ){ sorted = true; for(int i=1; i if(sortableVector->smaller(i-1,i)){ sortableVector->swap(i-1,i); sorted = false; } } n--; } } void sortIncreasing(SortableVector* sortableVector){ bool sorted = false; int n=sortableVector->getSize(); while( !sorted ){ sorted = true; for(int i=1; i if(!sortableVector->smaller(i-1,i)){ sortableVector->swap(i-1,i); sorted = false; } } n--; } } }; #endif /* BUBBLESORT_H */
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
