Question: I am writing out this c++ program that uses the sort () to sort various elements using overload operators and comparison functions when I run

I am writing out this c++ program that uses the sort () to sort various elements using overload operators and comparison functions

when I run the program I am getting these errors as a result. Is there any way to fix this?

I am writing out this c++ program that uses the sort ()

to sort various elements using overload operators and comparison functions when I

--mycode--

--main.cpp--

#include "ListItem.h" #include "algorithm_utils.h" #include #include #include #include #include

using namespace std;

int main () {

// working with a vector of ints int myints[] = { 32,71,12,45,26,80,53,33}; std::vector vectorOfNums (myints,myints+8);

// TODO: write call to sort() to sort the vectorOfNums

vectIter = sort (vectorOfNums.begin(), vectorOfNums.end());

for (std::vector::iterator vectIter = vectorOfNums.begin(); vectIter != vectorOfNums.end(); vectIter++) cout

cout

// working with a vector of strings std::vector<:string> vectorOfWords;

vectorOfWords.push_back("house"); vectorOfWords.push_back("cup"); vectorOfWords.push_back("car"); vectorOfWords.push_back("lamp");

// TODO: write call to sort for vectorOfWords vectIter = sort (vectorOfWords.begin(), vectorOfWords.end());

for (std::vector<:string>::iterator vectIter = vectorOfWords.begin(); vectIter != vectorOfWords.end(); vectIter++) cout

cout

// working with a vector of listItems std::vector vectorOfListItems; std::vector::iterator listItemIter;

vectorOfListItems.push_back(ListItem("shoes", 150.95)); vectorOfListItems.push_back(ListItem("laptop", 1245.85)); vectorOfListItems.push_back(ListItem("dress", 85.68)); vectorOfListItems.push_back(ListItem("polo shirt", 25.67));

// TODO: write call to sort on the vectorOfListItems vectIter = sort (vectorOfListItems.begin(), vectorOfListItems.end());

cout ::iterator vectIter = vectorOfListItems.begin(); vectIter != vectorOfListItems.end(); vectIter++) cout

// TODO: write call to sort on the vectorOfListItems using comparison function to compare names vectIter = sort(vectorOfListItems.begin(),vectorOfListItems.end(),Greater);

cout ::iterator vectIter = vectorOfListItems.begin(); vectIter != vectorOfListItems.end(); vectIter++) cout

// working with another vector of ints std::vector vectorOfNums2 (myints,myints+8);

// TODO: write call to sort() to sort the vectorOfNums2 in reverse (hint: need a comp function) vectIter = sort(vectorOfNums2.begin(),vectorOfNums2.end(),Greater);

cout ::iterator vectIter = vectorOfNums2.begin(); vectIter != vectorOfNums2.end(); vectIter++) cout

cout

// working with a vector of strings std::vector<:string> vectorOfWords2;

vectorOfWords2.push_back("house"); vectorOfWords2.push_back("cup"); vectorOfWords2.push_back("car"); vectorOfWords2.push_back("lamp");

// TODO: write call to sort for vectorOfWords2 to sort in reverse using a comp function vectIter = sort(vectorOfWords2.begin(),vectorOfWords2.end(),Greater);

for (std::vector<:string>::iterator vectIter = vectorOfWords2.begin(); vectIter != vectorOfWords2.end(); vectIter++) cout

cout

return 0; }

--ListItem.h--

#ifndef LISTITEMH #define LISTITEMH

#include

using namespace std;

// TODO: write the prototype for the 'compareNames' comparison function (may or may not be a friend)

bool Greater(const ListItem& a, const ListItem& b) { return a.priority > b.priority;

}

bool Less(const ListItem& a, const ListItem& b) { return a.priority

// TODO: write the prototype for the '

bool operator

friend ostream& operator

class ListItem { public: ListItem();

ListItem(string itemInit, double priceInit);

// Print this node void PrintNodeData();

// TODO: write the prototype for '

private: string item; double price; };

#endif

--ListItem.cpp--

#include "ListItem.h" #include

ListItem::ListItem() { item = ""; price = 0.0; }

ListItem::ListItem(string itemInit, double priceInit) { item = itemInit; price = priceInit; }

// Print this node void ListItem::PrintNodeData() { cout

// TODO: write the definition for '

// TODO: write the definition for the names comparison function (may or may not be a friend)

bool Greater(const ListItem& a, const ListItem& b) { return a.priority > b.priority;

}

bool Less(const ListItem& a, const ListItem& b) { return a.priority

--algorithm_utils.h--

#ifndef LESSON_9_STL_ALGORITHM_SORT_ALGORITHM_UTILS_H #define LESSON_9_STL_ALGORITHM_SORT_ALGORITHM_UTILS_H

#include "ListItem.h"

#include

// TODO: write the prototype for a greater-than comparison function for int template void printVector(std::vector vec)

// TODO: write the prototype for a greater-than comparison function for string template void printVector(std::vector vec)

#endif

--algorithm_utils.cpp--

#include "algorithm_utils.h"

// TODO: write the definition for a greater-than comparison function for ints template void printVector(std::vector vec) { for (typename std::vector::iterator it = vec.begin(); it != vec.end(); ++it) std::cout

// TODO: write the definition for a greater-than comparison function for strings template void printVector(std::vector vec) { for (typename std::vector::iterator it = vec.begin(); it != vec.end(); ++it) std::cout

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!