Templated Sorted Lists For this project, you will complete a C++ program in Code
ID: 3822739 • Letter: T
Question
Templated Sorted Lists
For this project, you will complete a C++ program in CodeLite to store hospital patients. (Create a new project using the 2170 template.) The driver code is located in TemplatedSortedList-main.cpp. (Do not modify this code.) Your assignment is to write a TemplatedSortedList class (in TemplatedSortedList.h) that implements a sorted list (linked- or array-based). Additionally, you get to template the class and provide overloaded operators such that the driver code compiles and produces the correct output.
The driver code processes the following commands:
A <NAME> (admits patient NAME)
D <NAME> (discharges patient NAME if NAME is in the list, silently continues otherwise)
F <NAME> (prints patient NAME if found in the list)
V (visits all patients and displays their names in list order)
. Write a sorted list class
· Write a templated class
· Overload different operators
Skeleton code / Driver code
OUTPUT
Your program should match the following output exactly: (user input in bold text)
URL LINK TO VIEW ASSIGNMENT
https://drive.google.com/open?id=0B8OHmjK8INMnZjRaWGJXWE1LZUE
Explanation / Answer
Here is the code for the question. Sample input file and output is also shown. Please don't forget to rate teh answer if it helped. Thank you very much.
#ifndef TEMPLATEDSORTEDLIST_H
#define TEMPLATEDSORTEDLIST_H
#define MAX 100
#include <iostream>
template <typename T>
class SortedList
{
private:
T array[MAX];
int count;
void moveElementsDown(int start)
{
for(int i=count;i>start;i--)
{
array[i]=array[i-1];
}
}
void moveElementsUp(int start)
{
for(int i=start;i<count-1;i++)
{
array[i]=array[i+1];
}
}
public:
SortedList()
{
count=0;
}
int getCount() const
{
return count;
}
SortedList& operator += (T value)
{
if(count<MAX)
{
int i;
for(i=0; i<count; i++)
{
if(array[i] > value )
{
break;
}
}
if(i<count)
moveElementsDown(i);
array[i]=value;
count++;
}
return *this;
}
SortedList& operator -= (T value)
{
if(count>0)
{
int i;
for(i=0; i<count; i++)
{
if(array[i] == value )
{
break;
}
}
if(i<count)
{
moveElementsUp(i);
count--;
}
}
return *this;
}
void print(T value)
{
for(int i=0;i<count;i++)
{
if(array[i] == value)
{
cout<<value << " is in the list"<<endl;
return ;
}
}
cout<<value<<" is not found in the list"<<endl;
}
friend std::ostream& operator <<(std::ostream &output, const SortedList<T> &list)
{
if(list.getCount()==0)
{
output<<"There are no entries in the list to display"<<endl;
return output;
}
else if(list.getCount()==1)
{
cout<<"Displaying the single entry in the list:"<<endl;
}
else
{
cout<<"Displaying all "<<list.getCount()<<" entries in the list:"<<endl;
}
for(int i=0;i<list.getCount();i++)
{
cout<<list.array[i]<<endl;
}
return output;
}
};
typedef SortedList<std::string> TemplatedSortedList;
#endif
Sample input file
V
F Sophia
A Sophia
V
F Sophia
D Sophia
V
A Aiden
A Emma
A Jackson
A Lucas
A Olivia
V
D Aiden
D Emma
D Jackson
D Lucas
D Olivia
V
Sample outpu
Please enter the input filename (or simply press return to use project5-testA.tab)
input.txt
Importing patients from input.txt ...
There are no entries in the list to display
Sophia is not found in the list
Displaying the single entry in the list:
Sophia
Sophia is in the list
There are no entries in the list to display
Displaying all 5 entries in the list:
Aiden
Emma
Jackson
Lucas
Olivia
There are no entries in the list to display
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.