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 #include using namespace std; #include "BubbleSort.h" #include "IntegerVectorSortable.h"

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 #include #include "SortableVector.h"

class IntegerVectorSortable: public SortableVector { protected: vector m_IntegerVector; public: virtual unsigned int getSize() const { return m_IntegerVector.size(); } virtual bool smaller(int i, int j) const { if(getInteger(i) < getInteger(j)) return true; else return false; } virtual void swap(int i, int j){ int temp = m_IntegerVector[i]; m_IntegerVector[i]=m_IntegerVector[j]; m_IntegerVector[j]=temp; } virtual void print() const { for(int i=0; i

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#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

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!