Question
Linked LIST C++ I have a completed .h file but can't seems to get the .cpp file to work. -----Driver file------.cpp file----Given in assignment #include
Linked LIST C++
I have a completed .h file but can't seems to get the .cpp file to work.
-----Driver file------.cpp file----Given in assignment
#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 "LinkedList.h" bool DEBUG = false; // toggles extra printing const string DEFAULT_INPUT_FILENAME = "project4-inputA.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 ){ LinkedList 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.insert( name ); if( DEBUG ){ patientList.printAll(); } break; case DISCHARGE: // get the patient's name from the file fileStream >> name; // remove them from the list patientList.remove( name ); if( DEBUG ){ patientList.printAll(); } 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 patientList.printAll(); break; default: cerr << "ERROR: Unknown action " << action << "!" << endl; exit(1); } } // close the file fileStream.close(); }
-----------My work------- header file (.h)
#ifndef LINKEDLIST_H_INCLUDED
#define LINKEDLIST_H_INCLUDED
#include
using namespace std;
struct node
{
string data;
node* next;
};
class LinkedList{
private:
struct node *head;
public:
LinkedList();
struct node *ccreate(string):
void insert(string);
void remove(string);
void print(string);
void printAll();
};
--------My work------ (.cpp)-----Need help in this file
LinkedList::LinkedList()
{
head = NULL;
}
struct node *create(string )
{
struct node *t;
t = new(struct node);
if (t == NULL)
{
cout<<"Memory not allocated "<
return 0;
}
else
{
t->data = name;
t->next = NULL;
return t;
}
}
void LinkedList::insert(string)
{
struct node *t, *p;
t = create(name);
if (head == NULL)
{
head = t;
head->next = NULL;
}
else
{
p = head;
head = temp;
head->next = p;
}
}
void LinkedList::remove(string name)
{
struct node *pre = NULL, *del = NULL;
if (_head->data == name) {
del = head;
head = del->next;
delete del;
return;
}
pre = head;
del = head->next;
while (del != NULL) {
if (del->data == name) {
pre->next = del->next;
delete del;
break;
}
pre = del;
del = del->next;
}
}
void LinkedList::print(string name)
{
if ()
{
cout<<"There are no entries in the list to display"<
return;
}
t = head;
while ()
{
if (t->data == name)
{
f = true;
cout<< name << "is in the List "<
}
// t = t->next;
}
// if (!f)
// cout<
// }
void LinkedList::printAll()
{
int count =0;
struct node *t;
if (head == )
{
return;
}
t = head;
while (temp != NULL)
{
count++;
t = t->next;
}
cout<<"Displaying all" <
while ()
{
t = t->next;
}
}
ASSIGNMENT DETAIL
the LinkedList class should use a pointer based LinkedList, that will need a constructor and destructor, for our insertion methods, insert at the beginning of the list. without modifying the LinkedList-main.cpp , fix the the LinkedList.h (header File) and create a LinkedList.cpp (implementation) file.
the driver code produces these following commands
A (admits patient NAME to the beginning of the list)
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)
and the input file is
V
F Sophia
D Sophia
A Sophia
V
F Sophia
D Sophia
V
F Sophia
D Sophia
A Jackson
A Emma
A Aiden
A Olivia
A Lucas
V
D Jackson
D Emma
D Aiden
D Olivia
D Lucas
V
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started