Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions

Question

What are the essential conditions of a credible audit?

Answered: 1 week ago

Question

Discuss the history of human resource management (HRM).

Answered: 1 week ago