Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The first part of the program (the deque) is done with William\'s help. Below th

ID: 3634728 • Letter: T

Question

The first part of the program (the deque) is done with William's help. Below the sample output is the code to the deque that read in ten double numbers in nonsequential order, and store them in the dequeue. Then call the generic sort function to sort the numbers in the deque and display the results. The program can all be in a singel C++ file. Please help with the set and map! I've provided some code.

Using a Set
Consider a text file of names, with one name per line, that has been compiled from several different
sources. A sample follows:

Mark Panuelo

Toby Sawyers

Defa Defang
Shawon Sean
Toby Sawyers
Jacky Chang
Barbara Timothey
Mark Panuelo

David Sondon


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.

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<iostream>
using namespace std;
template <class T>
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 <class T>
SimpleVector<T>::SimpleVector(int s)
{
arraySize = s;
try
{
aptr = new T [s];
}
catch (bad_alloc)
{
memError();
}
for (int count = 0; count < arraySize; count++)
*(aptr + count) = 0;
}
template <class T>
SimpleVector<T>::SimpleVector(const SimpleVector &obj)
{
arraySize = obj.arraySize;
aptr = new T [arraySize];
if (aptr == 0)
memError();
for(int count = 0; count < arraySize; count++)
*(aptr + count) = *(obj.aptr + count);
}
template <class T>
SimpleVector<T>::~SimpleVector()
{
if (arraySize > 0)
delete [] aptr;
}
template <class T>
void SimpleVector<T>::memError()
{
cout << "ERROR ";
exit(EXIT_FAILURE);
}
template <class T>
void SimpleVector<T>::subError()
{
cout << "ERROR ";
exit(EXIT_FAILURE);
}
template <class T>
T SimpleVector<T>::getElementAt(int sub)
{
if (sub < 0 || sub >= arraySize)
subError();
return aptr[sub];
}
template <class T>
T &SimpleVector<T>::operator[](const int &sub)
{
if (sub < 0 || sub >= arraySize)
subError();
return aptr[sub];
}
template <class T>
class SearchableVector : public SimpleVector<T>
{
public:
SearchableVector() : SimpleVector<T>()
{}
SearchableVector(int size) : SimpleVector<T>(size)
{ }
SearchableVector(const SearchableVector &);
void SortItems();
};
template <class T>
SearchableVector<T>::SearchableVector(const SearchableVector &obj) :
SimpleVector<T>(obj.size())
{
for(int count = 0; count < this->size(); count++)
this->operator[](count) = obj[count];
}
template <class T>
void SearchableVector<T>::SortItems()
{
for (int i = 0; i <= this->size(); i++)
{
for(int j=0;j<this->size()-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<double> dequeue(SIZE);
//Inputting elements to dequeue
cout<<"Enter elements"<<endl;
for (count = 0; count < SIZE; count++)
{
cin>>dequeue[count];
}
cout << "The enter values are : ";
for (count = 0; count < SIZE; count++)
cout << dequeue[count] << " ";
cout << endl;
//Function calls to sort list of elemts in tables
dequeue.SortItems();
//Outputtind lists
cout << "After sorting : ";
for (count = 0; count < SIZE; count++)
cout << dequeue[count] << " ";
cout << endl;
//To pause system for a while
system("pause");
return 0;
}

Explanation / Answer

http://www.sgi.com/tech/stl/stl_introduction.html http://www.cplusplus.com/reference/stl/set/ http://www.daniweb.com/software-development/cpp/threads/22802 http://www.yolinux.com/TUTORIALS/LinuxTutorialC++STL.html

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote