Question
Consider a text file of names, with one name per line, that has been compiled from several different sources. A sample follows:
Michael Joe
Edward Jacob
Ramon Ezra
Sean Nakamura
Michael Joe
Jie Lee
Meguro Sam
Edward Jacob
David Johnny
There are duplicate names in the file. We would like to generate an invitation list for a holiday party, but don’t want to send multiple invitations to the same person. Write a program that eliminates the duplicate names by using the set template class. Read each name from the file, add it to the set, then
output all names in the set to generate the invitation list without duplicates.
Explanation / Answer
Using a Map Write a program that uses the map template class to compute a histogram of positive numbers entered by the user. The map’s key should be the number that is entered, and the value should be a counter of the number of times the key has been entered so far. Use -1 as a sentinel value to signal the end of user input. For example, if the user inputs: 5 12 3 5 5 3 21 -1 Then the program should output the following (not necessarily in this order): The number 3 occurs 2 times. The number 5 occurs 3 times. The number 12 occurs 1 times. The number 21 occurs 1 times _______Using a deque #include using namespace std; template class SimpleVector { private: T *aptr; int arraySize; void memError(); void subError(); public: // Default constructor SimpleVector() { aptr = 0; arraySize = 0;} // Constructor declaration SimpleVector(int); // Copy constructor declaration SimpleVector(const SimpleVector &); // Destructor declaration ~SimpleVector(); // Accessor to return the array size int size() const { return arraySize; } // Accessor to return a specific element T getElementAt(int position); // Overloaded [] operator declaration T &operator[](const int &); }; template SimpleVector::SimpleVector(int s) { arraySize = s; try { aptr = new T [s]; } catch (bad_alloc) { memError(); } for (int count = 0; count operator[](count) = obj[count]; } template void SearchableVector::SortItems() { for (int i = 0; i size(); i++) { for(int j=0;jsize()-1;j++) { if (getElementAt(j) > getElementAt(j+1)) { T temp=this->operator [](j); this->operator [](j)=this->operator [](j+1); this->operator [](j+1)=temp; } } } } //main function int main() { //Variable declartion const int SIZE = 10; int count; SearchableVector dequeue(SIZE); //Inputting elements to dequeue cout