Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Templated Sorted Lists I have completed this program but I am getting many errors. Anyone, please take can look over it and let me know

Templated Sorted Lists

I have completed this program but I am getting many errors. Anyone, please take can look over it and let me know the changes I am required to make fix those error. I have attached the error screenshot URL link and assignment URL link. I have also mentioned my code and the driver code, you can find everything below. All the links are at the end of the question.

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 (admits patient NAME) D (discharges patient NAME if NAME is in the list, silently continues otherwise) F (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

Driver code / TemplatedSortedList-main.cpp

#include #include #include #include // for exit() using std::string; using std::cin; using std::cout; using std::cerr; using std::endl; using std::getline; using std::ifstream; #include "TemplatedSortedList.h" bool DEBUG = false; // toggles extra printing const string DEFAULT_INPUT_FILENAME = "project5-testA.tab"; // Action characters in the input file const char ADMIT = 'A'; const char DISCHARGE = 'D'; const char VISIT = 'V'; const char FIND = 'F'; // Process the patient records in inputFilename void processPatients( string inputFilename ); int main( /*int argc, char* argv[] */){ // If just a return (' ') is entered, then use DEFAULT_INPUT_FILENAME. // Otherwise, read in the input filename from STDIN. string inputFilename; cout << "Please enter the input filename (or simply press return to use " << DEFAULT_INPUT_FILENAME << ") "; getline( cin, inputFilename); if( inputFilename == ""){ inputFilename = DEFAULT_INPUT_FILENAME; } // process transactions in the file processPatients( inputFilename ); return 0; } void processPatients( string inputFilename ){ TemplatedSortedList patientList; // list to store patients // open file ifstream fileStream; fileStream.open( inputFilename.c_str() ); // verify the file is opened correctly if( ! fileStream ){ cerr << "ERROR: Can not open input file " << inputFilename << "!" << endl; exit(1); } cout << "Importing patients from " << inputFilename << " ..." << endl; char action = '\0'; // while there's more patients to process // read in the action and make sure that we're not at the end of the file while( fileStream >> action ){ if( DEBUG ){ cout << "action: " << action << endl; } string name; switch( action ){ case ADMIT: // get the patient's name from the file fileStream >> name; // add them to the list patientList += name; if( DEBUG ){ cout << patientList; } break; case DISCHARGE: // get the patient's name from the file fileStream >> name; // remove them from the list patientList -= name; if( DEBUG ){ cout << patientList; } break; case FIND: // get the patient's name from the file fileStream >> name; // look for this patient in the list patientList.print( name ); break; case VISIT: // display all patients in the list cout << patientList; break; default: cerr << "ERROR: Unknown action " << action << "!" << endl; exit(1); } } // close the file fileStream.close(); } 

OUTPUT

Your program should match the following output exactly: (user input in bold text)

Please enter the input filename (or simply press return to use project5-testA.tab) Importing patients from project5-testA.tab ... 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 Sophia is not found in the list Displaying all 5 entries in the list: Aiden Emma Jackson Lucas Olivia There are no entries in the list to display 

MY WORK //TemplatedSortedList.h

#ifndef TEMPLATEDSORTEDLIST_H

#define TEMPLATEDSORTEDLIST_H

#define MAX 100

#include

template

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

{

array[i]=array[i+1];

}

}

public:

SortedList()

{

count=0;

}

int getCount() const

{

return count;

}

SortedList& operator += (T value)

{

if(count

{

int i;

for(i=0; i

{

if(array[i] > value )

{

break;

}

}

if(i

moveElementsDown(i);

array[i]=value;

count++;

}

return *this;

}

SortedList& operator -= (T value)

{

if(count>0)

{

int i;

for(i=0; i

{

if(array[i] == value )

{

break;

}

}

if(i

{

moveElementsUp(i);

count--;

}

}

return *this;

}

void print(T value)

{

for(int i=0;i

{

if(array[i] == value)

{

cout<

return ;

}

}

cout<

}

friend std::ostream& operator <<(std::ostream &output, const SortedList &list)

{

if(list.getCount()==0)

{

output<<"There are no entries in the list to display"<

return output;

}

else if(list.getCount()==1)

{

cout<<"Displaying the single entry in the list:"<

}

else

{

cout<<"Displaying all "<

}

for(int i=0;i

{

cout<

}

return output;

}

};

typedef SortedList TemplatedSortedList;

#endif

Assignment URL

https://www.cs.mtsu.edu/~hcarroll/2170/private/projects/project5.html

Error URL:

https://drive.google.com/open?id=0B8OHmjK8INMnN3hyN2NIWllaNkk

URL LINK TO VIEW ASSIGNMENT

https://drive.google.com/open?id=0B8O

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions