SlideShare ist ein Scribd-Unternehmen logo
1 von 14
all i need is these two files
Create VectorContainer.hpp
Create SelectionSort.hpp
Test SelectionSort.hpp using the VectorContainer.hpp class you
made
# Strategy Pattern
In this lab you will create a strategy pattern for sorting a
collection of expression trees by their `evaluate()` value, which
you will pair with different containers to see how strategies can
be paired with different clients through an interface to create an
easily extendable system. This lab requires a completed
composite pattern from the previous lab, so you should begin by
copying your or your partner's code from the previous
assignment into your new repo, making sure it compiles
correctly, and running your tests to make sure everything is still
functioning correctly.
You will start this lab by creating two expression tree
containers: one that uses a vector to hold your trees (class
`VectorContainer`) and one that uses a standard list (class
`ListContainer`). Each of these container classes should be able
to hold any amount of different expressions each of which can
be of any size. You will implement them both as subclasses of
the following `Container` abstract base class, which has been
provided to you in container.h. You should create each one
independently, creating tests for them using the google test
framework before moving on. Each container should be it’s own
commit with a proper commit message. Optionally you can
create each one as a branch and merge it in once it has been
completed.
class Container {
protected:
Sort* sort_function;
public:
/* Constructors */
Container() : sort_function(nullptr) { };
Container(Sort* function) : sort_function(function) { };
/* Non Virtual Functions */
void set_sort_function(Sort* sort_function); // set the type
of sorting algorithm
/* Pure Virtual Functions */
// push the top pointer of the tree into container
virtual void add_element(Base* element) = 0;
// iterate through trees and output the expressions (use
stringify())
virtual void print() = 0;
// calls on the previously set sorting-algorithm. Checks if
sort_function is not
// null, throw exception if otherwise
virtual void sort() = 0;
/* Functions Needed to Sort */
//switch tree locations
virtual void swap(int i, int j) = 0;
// get top ptr of tree at index i
virtual Base* at(int i) = 0;
// return container size
virtual int size() = 0;
};
Notice that our Container abstract base class does not have any
actual STL containers because it leaves the implementation
details of the container to the subclasses. You **must use the
homogeneous interface above for your sort functions, and you
are only allowed to manipulate the containers through this
interface, not directly**. This will allow you to extend and
change the underlying functionality without having to change
anything that interfaces with it.
## Sorting Classes
In addition to the containers you will also create two sort
functions capable of sorting your containers, one that uses the
[selection
sort](https://www.mathbits.com/MathBits/CompSci/Arrays/Sele
ction.htm) algorithm and one that uses the [bubble
sort](https://www.mathbits.com/MathBits/CompSci/Arrays/Bub
ble.htm) algorithm (you may adapt this code when writing your
sort functions). They should both be implemented as subclasses
of the `Sort` base class below which has been provided. You
should create each one independently, creating tests for them
using the google test framework before moving on. Each sort
class should be it's own commit with it’s own proper commit
message. When creating tests for these sort classes, make sure
you test them with each of the containers you developed
previously, and with a number of different expression trees.
```c++
class Sort {
public:
/* Constructors */
Sort();
/* Pure Virtual Functions */
virtual void sort(Container* container) = 0;
};
sort.hpp
#ifndef _SORT_HPP_
#define _SORT_HPP_
#include "container.hpp"
class Container;
class Sort {
public:
/* Constructors */
Sort();
/* Pure Virtual Functions */
virtual void sort(Container* container) = 0;
};
#endif //_SORT_HPP_
base.hpp
#ifndef _BASE_HPP_
#define _BASE_HPP_
#include
class Base {
public:
/* Constructors */
Base() { };
/* Pure Virtual Functions */
virtual double evaluate() = 0;
virtual std::string stringify() = 0;
};
#endif //_BASE_HPP_
container.hpp
#ifndef _CONTAINER_HPP_
#define _CONTAINER_HPP_
#include "sort.hpp"
#include "base.hpp"
class Sort;
class Base;
class Container {
protected:
Sort* sort_function;
public:
/* Constructors */
Container() : sort_function(nullptr) { };
Container(Sort* function) : sort_function(function) { };
/* Non Virtual Functions */
void set_sort_function(Sort* sort_function); // set the type of
sorting algorithm
/* Pure Virtual Functions */
// push the top pointer of the tree into container
virtual void add_element(Base* element) = 0;
// iterate through trees and output the expressions (use
stringify())
virtual void print() = 0;
// calls on the previously set sorting-algorithm. Checks if
sort_function is not null, throw exception if otherwise
virtual void sort() = 0;
/* Essentially the only functions needed to sort */
//switch tree locations
virtual void swap(int i, int j) = 0;
// get top ptr of tree at index i
virtual Base* at(int i) = 0;
// return container size
virtual int size() = 0;
};
#endif //_CONTAINER_HPP_
Example
#ifndef _LISTCONTAINER_HPP_
#define _LISTCONTAINER_HPP_
#include "container.hpp"
#include
#include
#include
class Sort;
class ListContainer: public Container{
public:
std::list baseList;
//Container() : sort_function(nullptr){};
//Container(Sort* function) : sort_Function(function){};
//void set_sort_funtion(Sort* sort_function){
// this -> sort_function = sort_function;
//}
void add_element(Base* element){
baseList.push_back(element);
}
void print(){
for(std::list::iterator i = baseList.begin(); i != baseList.end();
++i){
if(i == baseList.begin()){
std::cout <<(*i) -> stringify();
}
else{
std::cout << ", " << (*i) -> stringify();
}
}
std::cout << std::endl;
}
void sort(){
try{
if(sort_function != nullptr){
sort_function -> sort(this);
}
else{
throw std::logic_error("invalid sort_function");
}
}
catch(std::exception &exp){
std::cout << "ERROR : " << exp.what() << "n";
}
}
//sorting functions
void swap(int i, int j){
std::list::iterator first = baseList.begin();
for(int f = 0; f < i; f++){
first++;
}
Base* temp = *first;
std::list::iterator second = baseList.begin();
for(int s = 0; s < j; s++){
second++;
}
*first = *second;
*second = temp;
}
Base* at(int i){
std::list::iterator x = baseList.begin();
for(int a = 0; a < i; a++){
x++;
}
return *x;
}
int size(){
return baseList.size();
}
};
#endif //_LISTCONTAINER_HPP_
bubblesort.hpp
#ifndef __BUBBLESORT_HPP__
#define __BUBBLESORT_HPP__
#include "sort.hpp"
#include "container.hpp"
class BubbleSort: public Sort{
public:
void sort(Container* container){
memContainer = container;
int flag = 1;
int numLength = memContainer->size();
for(int i = 1; (i <= numLength) && (flag == 1);
i++){
flag = 0;
for(int j = 0; j < (numLength - 1); j++){
if(memContainer->at(j+1)->evaluate() <
memContainer->at(j)->evaluate()){
memContainer->swap(j+1, j);
flag = 1;
}
}
}
}
};
#endif // __BUBBLESORT_HPP__

Weitere ähnliche Inhalte

Ähnlich wie all i need is these two filesCreate VectorContainer.hppCreat.docx

In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
bradburgess22840
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherence
aragozin
 
Program Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docxProgram Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docx
sharold2
 
Program Specifications in c++ Develop an inventory management syste.docx
Program Specifications in c++    Develop an inventory management syste.docxProgram Specifications in c++    Develop an inventory management syste.docx
Program Specifications in c++ Develop an inventory management syste.docx
sharold2
 
Ive posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdfIve posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdf
deepaarora22
 
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 PriorityQueue.cs   Jim Mischel using System; using Sy.pdf PriorityQueue.cs   Jim Mischel using System; using Sy.pdf
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
rajat630669
 
Write a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfWrite a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdf
eyebolloptics
 

Ähnlich wie all i need is these two filesCreate VectorContainer.hppCreat.docx (20)

In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docxIn Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
In Class AssignmetzCST280W13a-1.pdfCST 280 In-Class Pract.docx
 
CS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUALCS2309 JAVA LAB MANUAL
CS2309 JAVA LAB MANUAL
 
Effective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's bookEffective Java. By materials of Josch Bloch's book
Effective Java. By materials of Josch Bloch's book
 
Online CPP Homework Help
Online CPP Homework HelpOnline CPP Homework Help
Online CPP Homework Help
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherence
 
svelte-en.pdf
svelte-en.pdfsvelte-en.pdf
svelte-en.pdf
 
Stack Implementation
Stack ImplementationStack Implementation
Stack Implementation
 
Maze
MazeMaze
Maze
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Program Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docxProgram Specifications in c++ Develop an inventory management system f.docx
Program Specifications in c++ Develop an inventory management system f.docx
 
Program Specifications in c++ Develop an inventory management syste.docx
Program Specifications in c++    Develop an inventory management syste.docxProgram Specifications in c++    Develop an inventory management syste.docx
Program Specifications in c++ Develop an inventory management syste.docx
 
Ive posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdfIve posted 3 classes after the instruction that were given at star.pdf
Ive posted 3 classes after the instruction that were given at star.pdf
 
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 PriorityQueue.cs   Jim Mischel using System; using Sy.pdf PriorityQueue.cs   Jim Mischel using System; using Sy.pdf
PriorityQueue.cs Jim Mischel using System; using Sy.pdf
 
Creational pattern 2
Creational pattern 2Creational pattern 2
Creational pattern 2
 
Oop lect3.pptx
Oop lect3.pptxOop lect3.pptx
Oop lect3.pptx
 
Write a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdfWrite a program that mimics the operations of several vending machin.pdf
Write a program that mimics the operations of several vending machin.pdf
 
React table tutorial use filter (part 2)
React table tutorial use filter (part 2)React table tutorial use filter (part 2)
React table tutorial use filter (part 2)
 
Cambio de bases
Cambio de basesCambio de bases
Cambio de bases
 
C++ Memory Management
C++ Memory ManagementC++ Memory Management
C++ Memory Management
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 

Mehr von jack60216

Annotated BibliographyIn preparation of next weeks final as.docx
Annotated BibliographyIn preparation of next weeks final as.docxAnnotated BibliographyIn preparation of next weeks final as.docx
Annotated BibliographyIn preparation of next weeks final as.docx
jack60216
 
Annual Report to the Nation on the Status of Cancer,Part I .docx
Annual Report to the Nation on the Status of Cancer,Part I .docxAnnual Report to the Nation on the Status of Cancer,Part I .docx
Annual Report to the Nation on the Status of Cancer,Part I .docx
jack60216
 
Analyzing a Short Story- The Necklace by Guy de MaupassantIntro.docx
Analyzing a Short Story- The Necklace by Guy de MaupassantIntro.docxAnalyzing a Short Story- The Necklace by Guy de MaupassantIntro.docx
Analyzing a Short Story- The Necklace by Guy de MaupassantIntro.docx
jack60216
 
Andy Sylvan was the assistant director of the community developm.docx
Andy Sylvan was the assistant director of the community developm.docxAndy Sylvan was the assistant director of the community developm.docx
Andy Sylvan was the assistant director of the community developm.docx
jack60216
 
Annotated Bibliography Althaus, F. U.S. Maternal Morta.docx
Annotated Bibliography  Althaus, F. U.S. Maternal Morta.docxAnnotated Bibliography  Althaus, F. U.S. Maternal Morta.docx
Annotated Bibliography Althaus, F. U.S. Maternal Morta.docx
jack60216
 
Andrea Walters Week 2 Main Post       The key functional area of n.docx
Andrea Walters Week 2 Main Post       The key functional area of n.docxAndrea Walters Week 2 Main Post       The key functional area of n.docx
Andrea Walters Week 2 Main Post       The key functional area of n.docx
jack60216
 
Analytical Research Project InstructionsINFA 630 – Intrusion.docx
Analytical Research Project InstructionsINFA 630 – Intrusion.docxAnalytical Research Project InstructionsINFA 630 – Intrusion.docx
Analytical Research Project InstructionsINFA 630 – Intrusion.docx
jack60216
 
Analyze the subjective portion of the note. List additiona.docx
Analyze the subjective portion of the note. List additiona.docxAnalyze the subjective portion of the note. List additiona.docx
Analyze the subjective portion of the note. List additiona.docx
jack60216
 

Mehr von jack60216 (20)

Anorexia1-Definition2-Epidemiology in united states2.docx
Anorexia1-Definition2-Epidemiology in united states2.docxAnorexia1-Definition2-Epidemiology in united states2.docx
Anorexia1-Definition2-Epidemiology in united states2.docx
 
Annotated BibliographyIn preparation of next weeks final as.docx
Annotated BibliographyIn preparation of next weeks final as.docxAnnotated BibliographyIn preparation of next weeks final as.docx
Annotated BibliographyIn preparation of next weeks final as.docx
 
Annual Report to the Nation on the Status of Cancer,Part I .docx
Annual Report to the Nation on the Status of Cancer,Part I .docxAnnual Report to the Nation on the Status of Cancer,Part I .docx
Annual Report to the Nation on the Status of Cancer,Part I .docx
 
Annotated BibliographyDue 1212019 @ 12pm Eastern Time (Unite.docx
Annotated BibliographyDue 1212019 @ 12pm Eastern Time (Unite.docxAnnotated BibliographyDue 1212019 @ 12pm Eastern Time (Unite.docx
Annotated BibliographyDue 1212019 @ 12pm Eastern Time (Unite.docx
 
Annotated BibliographyFor this assignment, you will create an .docx
Annotated BibliographyFor this assignment, you will create an .docxAnnotated BibliographyFor this assignment, you will create an .docx
Annotated BibliographyFor this assignment, you will create an .docx
 
Annotated bibliography due in 36 hours. MLA format Must incl.docx
Annotated bibliography due in 36 hours. MLA format Must incl.docxAnnotated bibliography due in 36 hours. MLA format Must incl.docx
Annotated bibliography due in 36 hours. MLA format Must incl.docx
 
Analyzing a Short Story- The Necklace by Guy de MaupassantIntro.docx
Analyzing a Short Story- The Necklace by Guy de MaupassantIntro.docxAnalyzing a Short Story- The Necklace by Guy de MaupassantIntro.docx
Analyzing a Short Story- The Necklace by Guy de MaupassantIntro.docx
 
Andy Sylvan was the assistant director of the community developm.docx
Andy Sylvan was the assistant director of the community developm.docxAndy Sylvan was the assistant director of the community developm.docx
Andy Sylvan was the assistant director of the community developm.docx
 
Annotated Bibliography Althaus, F. U.S. Maternal Morta.docx
Annotated Bibliography  Althaus, F. U.S. Maternal Morta.docxAnnotated Bibliography  Althaus, F. U.S. Maternal Morta.docx
Annotated Bibliography Althaus, F. U.S. Maternal Morta.docx
 
Ann, a community nurse, made an afternoon home visit with Susan and .docx
Ann, a community nurse, made an afternoon home visit with Susan and .docxAnn, a community nurse, made an afternoon home visit with Susan and .docx
Ann, a community nurse, made an afternoon home visit with Susan and .docx
 
Andrea Walters Week 2 Main Post       The key functional area of n.docx
Andrea Walters Week 2 Main Post       The key functional area of n.docxAndrea Walters Week 2 Main Post       The key functional area of n.docx
Andrea Walters Week 2 Main Post       The key functional area of n.docx
 
and emergency CPR all changed ways of thinking about risk of death.docx
and emergency CPR all changed ways of thinking about risk of death.docxand emergency CPR all changed ways of thinking about risk of death.docx
and emergency CPR all changed ways of thinking about risk of death.docx
 
analyze, and discuss emerging ICT tools and technologies present.docx
analyze, and discuss emerging ICT tools and technologies present.docxanalyze, and discuss emerging ICT tools and technologies present.docx
analyze, and discuss emerging ICT tools and technologies present.docx
 
Analyzing a Research ArticleNote Please complete this dis.docx
Analyzing a Research ArticleNote Please complete this dis.docxAnalyzing a Research ArticleNote Please complete this dis.docx
Analyzing a Research ArticleNote Please complete this dis.docx
 
Analyze the Civil Rights Movement of the 1950s and 1960s. What p.docx
Analyze the Civil Rights Movement of the 1950s and 1960s. What p.docxAnalyze the Civil Rights Movement of the 1950s and 1960s. What p.docx
Analyze the Civil Rights Movement of the 1950s and 1960s. What p.docx
 
Analytical Research Project InstructionsINFA 630 – Intrusion.docx
Analytical Research Project InstructionsINFA 630 – Intrusion.docxAnalytical Research Project InstructionsINFA 630 – Intrusion.docx
Analytical Research Project InstructionsINFA 630 – Intrusion.docx
 
Analyze the performance of the leadership of an organization (Netfli.docx
Analyze the performance of the leadership of an organization (Netfli.docxAnalyze the performance of the leadership of an organization (Netfli.docx
Analyze the performance of the leadership of an organization (Netfli.docx
 
Analyze the subjective portion of the note. List additiona.docx
Analyze the subjective portion of the note. List additiona.docxAnalyze the subjective portion of the note. List additiona.docx
Analyze the subjective portion of the note. List additiona.docx
 
Analyze the measures your state and local community have in pl.docx
Analyze the measures your state and local community have in pl.docxAnalyze the measures your state and local community have in pl.docx
Analyze the measures your state and local community have in pl.docx
 
Analyze two (2) advantages and two (2) disadvantages of creati.docx
Analyze two (2) advantages and two (2) disadvantages of creati.docxAnalyze two (2) advantages and two (2) disadvantages of creati.docx
Analyze two (2) advantages and two (2) disadvantages of creati.docx
 

Kürzlich hochgeladen

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
MateoGardella
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
SanaAli374401
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
PECB
 

Kürzlich hochgeladen (20)

SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Gardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch LetterGardella_PRCampaignConclusion Pitch Letter
Gardella_PRCampaignConclusion Pitch Letter
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 

all i need is these two filesCreate VectorContainer.hppCreat.docx

  • 1. all i need is these two files Create VectorContainer.hpp Create SelectionSort.hpp Test SelectionSort.hpp using the VectorContainer.hpp class you made # Strategy Pattern In this lab you will create a strategy pattern for sorting a collection of expression trees by their `evaluate()` value, which you will pair with different containers to see how strategies can be paired with different clients through an interface to create an easily extendable system. This lab requires a completed composite pattern from the previous lab, so you should begin by copying your or your partner's code from the previous assignment into your new repo, making sure it compiles correctly, and running your tests to make sure everything is still functioning correctly. You will start this lab by creating two expression tree containers: one that uses a vector to hold your trees (class `VectorContainer`) and one that uses a standard list (class `ListContainer`). Each of these container classes should be able to hold any amount of different expressions each of which can be of any size. You will implement them both as subclasses of the following `Container` abstract base class, which has been provided to you in container.h. You should create each one independently, creating tests for them using the google test framework before moving on. Each container should be it’s own commit with a proper commit message. Optionally you can create each one as a branch and merge it in once it has been
  • 2. completed. class Container { protected: Sort* sort_function; public: /* Constructors */ Container() : sort_function(nullptr) { }; Container(Sort* function) : sort_function(function) { }; /* Non Virtual Functions */ void set_sort_function(Sort* sort_function); // set the type of sorting algorithm /* Pure Virtual Functions */ // push the top pointer of the tree into container virtual void add_element(Base* element) = 0; // iterate through trees and output the expressions (use stringify()) virtual void print() = 0; // calls on the previously set sorting-algorithm. Checks if
  • 3. sort_function is not // null, throw exception if otherwise virtual void sort() = 0; /* Functions Needed to Sort */ //switch tree locations virtual void swap(int i, int j) = 0; // get top ptr of tree at index i virtual Base* at(int i) = 0; // return container size virtual int size() = 0; }; Notice that our Container abstract base class does not have any actual STL containers because it leaves the implementation details of the container to the subclasses. You **must use the homogeneous interface above for your sort functions, and you are only allowed to manipulate the containers through this interface, not directly**. This will allow you to extend and change the underlying functionality without having to change anything that interfaces with it. ## Sorting Classes In addition to the containers you will also create two sort
  • 4. functions capable of sorting your containers, one that uses the [selection sort](https://www.mathbits.com/MathBits/CompSci/Arrays/Sele ction.htm) algorithm and one that uses the [bubble sort](https://www.mathbits.com/MathBits/CompSci/Arrays/Bub ble.htm) algorithm (you may adapt this code when writing your sort functions). They should both be implemented as subclasses of the `Sort` base class below which has been provided. You should create each one independently, creating tests for them using the google test framework before moving on. Each sort class should be it's own commit with it’s own proper commit message. When creating tests for these sort classes, make sure you test them with each of the containers you developed previously, and with a number of different expression trees. ```c++ class Sort { public: /* Constructors */ Sort(); /* Pure Virtual Functions */ virtual void sort(Container* container) = 0; }; sort.hpp
  • 5. #ifndef _SORT_HPP_ #define _SORT_HPP_ #include "container.hpp" class Container; class Sort { public: /* Constructors */ Sort(); /* Pure Virtual Functions */ virtual void sort(Container* container) = 0; }; #endif //_SORT_HPP_ base.hpp #ifndef _BASE_HPP_ #define _BASE_HPP_
  • 6. #include class Base { public: /* Constructors */ Base() { }; /* Pure Virtual Functions */ virtual double evaluate() = 0; virtual std::string stringify() = 0; }; #endif //_BASE_HPP_ container.hpp #ifndef _CONTAINER_HPP_ #define _CONTAINER_HPP_ #include "sort.hpp"
  • 7. #include "base.hpp" class Sort; class Base; class Container { protected: Sort* sort_function; public: /* Constructors */ Container() : sort_function(nullptr) { }; Container(Sort* function) : sort_function(function) { }; /* Non Virtual Functions */ void set_sort_function(Sort* sort_function); // set the type of sorting algorithm /* Pure Virtual Functions */ // push the top pointer of the tree into container virtual void add_element(Base* element) = 0;
  • 8. // iterate through trees and output the expressions (use stringify()) virtual void print() = 0; // calls on the previously set sorting-algorithm. Checks if sort_function is not null, throw exception if otherwise virtual void sort() = 0; /* Essentially the only functions needed to sort */ //switch tree locations virtual void swap(int i, int j) = 0; // get top ptr of tree at index i virtual Base* at(int i) = 0; // return container size virtual int size() = 0; }; #endif //_CONTAINER_HPP_ Example #ifndef _LISTCONTAINER_HPP_
  • 9. #define _LISTCONTAINER_HPP_ #include "container.hpp" #include #include #include class Sort; class ListContainer: public Container{ public: std::list baseList; //Container() : sort_function(nullptr){}; //Container(Sort* function) : sort_Function(function){}; //void set_sort_funtion(Sort* sort_function){ // this -> sort_function = sort_function; //} void add_element(Base* element){
  • 10. baseList.push_back(element); } void print(){ for(std::list::iterator i = baseList.begin(); i != baseList.end(); ++i){ if(i == baseList.begin()){ std::cout <<(*i) -> stringify(); } else{ std::cout << ", " << (*i) -> stringify(); } } std::cout << std::endl; } void sort(){ try{ if(sort_function != nullptr){ sort_function -> sort(this); }
  • 11. else{ throw std::logic_error("invalid sort_function"); } } catch(std::exception &exp){ std::cout << "ERROR : " << exp.what() << "n"; } } //sorting functions void swap(int i, int j){ std::list::iterator first = baseList.begin(); for(int f = 0; f < i; f++){ first++; } Base* temp = *first; std::list::iterator second = baseList.begin(); for(int s = 0; s < j; s++){
  • 12. second++; } *first = *second; *second = temp; } Base* at(int i){ std::list::iterator x = baseList.begin(); for(int a = 0; a < i; a++){ x++; } return *x; } int size(){ return baseList.size(); } }; #endif //_LISTCONTAINER_HPP_ bubblesort.hpp
  • 13. #ifndef __BUBBLESORT_HPP__ #define __BUBBLESORT_HPP__ #include "sort.hpp" #include "container.hpp" class BubbleSort: public Sort{ public: void sort(Container* container){ memContainer = container; int flag = 1; int numLength = memContainer->size(); for(int i = 1; (i <= numLength) && (flag == 1); i++){ flag = 0; for(int j = 0; j < (numLength - 1); j++){ if(memContainer->at(j+1)->evaluate() < memContainer->at(j)->evaluate()){ memContainer->swap(j+1, j);
  • 14. flag = 1; } } } } }; #endif // __BUBBLESORT_HPP__