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?


--mycode--
--main.cpp--
#include "ListItem.h" #include "algorithm_utils.h" #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
// TODO: write call to sort() to sort the vectorOfNums
vectIter = sort (vectorOfNums.begin(), vectorOfNums.end());
for (std::vector 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.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 // 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 // TODO: write the prototype for a greater-than comparison function for string template #endif --algorithm_utils.cpp-- #include "algorithm_utils.h" // TODO: write the definition for a greater-than comparison function for ints template // TODO: write the definition for a greater-than comparison function for strings template
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
