SlideShare a Scribd company logo
1 of 18
Download to read offline
Using C++
I keep getting message:
'head does not name a type'
'teal does not name a type'
Where do I place this code in my program:
/*search and delete with respect to location as current, head and tail
//define below 2 lines in LinkedList() function
head = new NodeType;
tail = new NodeType;
void UnsorderedType::DeleteItem(ItemType item)
{
NodeType *tempLocation, *location;
bool stop = false;
if(!isEmpty())
{
location = head;
tempLocation = head->link;
while (templocation != tail && !stop)
{
if (templocation->info == item)
stop = true;
else
{
location = templocation;
templocation = templocation->link;
}
}
if (!stop)
cout << "The node to delete is not in the list!" << endl;
else
{
location->link = templocation->link;
delete templocation;
count--;
}
}
else
{
cout << "The list is empty!" << endl;
}
}*/
/Problem and code:
Implement the UnsortedList class to store a list of strings that are input into the list from
data2.txt.
- create a main.cpp file that gets the numbers from the file
- insert the word "cat" into the list
- insert another word "antibacterial" into the list
- delete the word "letter" from the list
- print out the following:
--the entire list
- the greatest
- the least
2. Attach the main.cpp, UnsortedList.cpp, the ItemType.h, and the output file one called
outfile1.txt
- Yes you need to make your program output an "outfile1.txt"
3. Implement the UnsortedList class to store a list of numbers that are input into the list from
data.txt.
- create a main.cpp file that gets the numbers from the file
- insert the number 7 into the list
- insert another number 300 into the list
- delete the number 6 from the list
- print out the following:
--the entire list
- the greatest
- the least
2. Attach the main.cpp, UnsortedList.cpp, the ItemType.h, and the output file two called
outfile2.txt
- Yes you need to make your program output an "outfile2.txt"
data.txt
super formula travel free thick Josephine Clara education
data2.txt
super formula travel free thick Josephine Clara education
//My main.cpp
//--------------------------------------------------------------
// Test driver for Linked List UnsortedType list
// Navarr Barnier
// Your class CS3350 TTh 1:00
// Due date: Thursday, September 13, 2012
//
// Compile command: g++ hw2.cpp ch03-UnsortedType.cpp ch03-ItemType.cpp
// Input file name: hw2.txt
// Contains list of commands to add items to list, split original
// list into two lists, print each list and get the length of
// each list.
// Output: The result of each command is displayed on the screen.
// Filename: hw2.cpp
//--------------------------------------------------------------
#include
#include
#include
#include
#include
#include "ItemType.h"
using namespace std;
void PrintList(UnsortedType&);
void SplitList(UnsortedType&, ItemType);
ItemType GetItem(ItemType& item, bool& found);
int main()
{
ifstream inFile; // file containing operations
ofstream outFS; // Output file stream
string data; // operation to be executed
string command; // operation to be executed
int count = 0;
ItemType item;
UnsortedType list;
bool found;
//int numCommands;
//----------------------------------------
// Open input file with commands for testing
// list operations, check success of open
//----------------------------------------
inFile.open("data2.txt");
if (!inFile)
{
cout << "Unable to open input file - ending program." << endl;
return 1;
}
//----------------------------------------
// Read in and process commands to apply to list
//----------------------------------------
//inFile >> data;
//numCommands = 0;
while (!inFile.eof())
{
//numCommands++;
//cout << "Command " << numCommands << ": " << command << " ";
//----------------------------------------
// PutItem
//----------------------------------------
inFile >> data;
item.Initialize(data);
list.PutItem(item);
++count;
item.Print();
cout << ", " << "added to list" << endl;
}
inFile.close();
cout << " " << count << " words total in list." << "  ";
inFile.open("hw6.txt");
if (!inFile)
{
cout << "Unable to open input file - ending program." << endl;
return 1;
}
//----------------------------------------
// Read in and process commands to apply to list
//----------------------------------------
inFile >> command;
//numCommands = 0;
while (command != "Quit")
{
// numCommands++;
// cout << "Command " << numCommands << ": " << command << " ";
//----------------------------------------
// PutItem
//----------------------------------------
if (command == "PutItem")
{
inFile >> data;
item.Initialize(data);
list.PutItem(item);
item.Print();
cout << " added to list" << endl;
}
//----------------------------------------
// GetItem
//----------------------------------------
else if (command == "GetItem")
{
inFile >> data;
item.Initialize(data);
item = list.GetItem(item, found);
item.Print();
if (found)
cout << " found in list." << endl;
else
cout << " not in list." << endl;
}
//----------------------------------------
// DeleteItem
//----------------------------------------
else if (command == "DeleteItem")
{
inFile >> data;
item.Initialize(data);
list.DeleteItem(item);
item.Print();
cout << " deleted from list" << endl;
}
//----------------------------------------
// GetLength
//----------------------------------------
else if (command == "GetLength")
cout << "Length of list = " << list.GetLength() << endl;
//----------------------------------------
// IsFull
//----------------------------------------
else if (command == "IsFull")
if (list.IsFull())
cout << "List is full." << endl;
else
cout << "List is not full." << endl;
//----------------------------------------
// MakeEmpty
//----------------------------------------
else if (command == "MakeEmpty")
{ list.MakeEmpty();
cout << "List is empty." << endl;
}
//----------------------------------------
// PrintList
// Non-member function to print list of items
//----------------------------------------
else if (command == "PrintList")
{
cout << "  List values" << endl;
PrintList(list);
}
//----------------------------------------
// SplitList
// Split the list
//----------------------------------------
else if (command == "SplitList")
{
inFile >> data;
item.Initialize(data);
//SplitList(list,item);
}
//----------------------------------------
// Invalid command
//----------------------------------------
else
cout << command << " is not a valid command." << endl;
inFile >> command;
};
cout << "Testing completed." << endl;
inFile.close();
/*//----------------------------------------
// PutItem
//----------------------------------------
if (command == "PutItem")
{
inFile >> data;
item.Initialize(data);
list.PutItem(item);
item.Print();
cout << " added to list" << endl;
}
//----------------------------------------
// GetItem
//----------------------------------------
else if (command == "GetItem")
{
inFile >> data;
item.Initialize(data);
item = list.GetItem(item, found);
item.Print();
if (found)
cout << " found in list." << endl;
else
cout << " not in list." << endl;
}
//----------------------------------------
// DeleteItem
//----------------------------------------
else if (command == "DeleteItem")
{
inFile >> data;
item.Initialize(data);
list.DeleteItem(item);
item.Print();
cout << " deleted from list" << endl;
}
//----------------------------------------
// PrintList
// Non-member function to print list of items
//----------------------------------------
else if (command == "PrintList")
{
cout << "  List values" << endl;
PrintList(list);
}
*/
return 0;
}
//----------------------------------------
// PrintList
// Non-member function to print all items in list
// Pre: list has been initialized
// Post: Each component in list has been written to cout
//----------------------------------------
void PrintList(UnsortedType &list)
{
int length;
ItemType item;
list.ResetList();
length = list.GetLength();
for (int counter = 1; counter <= length; counter++)
{
item = list.GetNextItem();
item.Print();
cout << endl;
}
cout << "Length of list = " << length << endl << endl;
}
//My UnsortedList.cpp Code
//------------------------------------------------------
// ItemType
// Class Implementation File
// Ch. 3, C++ Plus Data Structures, Dale 5e, p. 155
// Filename: ch03-ItemType.cpp
//------------------------------------------------------
#include
#include
#include "ItemType.h"
using namespace std;
//------------------------------
// ItemType
// default constructor
//------------------------------
ItemType::ItemType()
{ value = ""; }
//------------------------------
// ComparedTo
// Compares one ItemType object to another. Returns
// LESS, if self "comes before" item
// GREATER, if self "comes after" item
// EQUAL, if self and item are the same
//------------------------------
RelationType ItemType::ComparedTo(ItemType otherItem) const
{
if (value < otherItem.value)
return LESS;
else if (value > otherItem.value)
return GREATER;
else return EQUAL;
}
//------------------------------
// Initialize
//------------------------------
void ItemType::Initialize(string data)
{ value = data; }
//------------------------------
// Print
// Adds ItemType value to output stream
//------------------------------
void ItemType::Print() const
// pre: out has been opened.
// post: value has been sent to the stream cout.
{ cout << value; }
//------------------------------------------------------
// UnsortedType
// Linked List - Class Implementation File
// Your name
// Your class CS3350 classtime
// Due date: Thursday, September 13, 2012
//------------------------------------------------------
//---------------------------------------------
// Constructor
//---------------------------------------------
UnsortedType::UnsortedType()
{
length = 0;
listData = NULL;
}
//---------------------------------------------
// Destructor
// Deallocates all items in list
// Post: List is empty
// All items have been deallocated
//---------------------------------------------
UnsortedType::~UnsortedType()
{
NodeType* tempPtr;
// Loop removes all nodes from list
// deallocating space for each one
while(listData != NULL)
{
tempPtr = listData;
listData = listData->next;
delete tempPtr;
}
}
//---------------------------------------------
// MakeEmpty
// Returns the list to the empty state
// Post: List is empty
//---------------------------------------------
void UnsortedType::MakeEmpty()
// Post: List is empty
{
NodeType* tempPtr;
// Loop removes all nodes from list
// deallocating space for each one
while(listData != NULL)
{
tempPtr = listData;
listData = listData->next;
delete tempPtr;
}
length = 0;
}
//---------------------------------------------
// IsFull
// Function: Determines whether list is full.
// Pre: List has been initialized.
// Post: Function value = (list is full)
// Returns: true if there is no room for another
// ItemType on the free store; false otherwise.
//---------------------------------------------
bool UnsortedType::IsFull() const
{
NodeType* location;
// Try adding a new node, if successful, there
// is room for more nodes so list is NOT full
try
{
location = new NodeType;
delete location;
return false;
}
// If adding a new node was unsuccessful,
// the list is full
catch(bad_alloc)
{
return true;
}
}
//---------------------------------------------
// GetLength
// Determines number of elements in list
// Pre: List has been initialized
// Post: Number of items in the list is returned
//---------------------------------------------
int UnsortedType::GetLength() const
{
return length;
}
//---------------------------------------------
// PutItem
// Adds item to list
// Pre: List has been initialized
// List is not full
// item is not in list
// Post: item is in list; length has been incremented
//---------------------------------------------
void UnsortedType::PutItem(ItemType item)
{
NodeType* location = new NodeType;
location->info = item;
location->next = listData;
listData = location;
length++; // Increment length of list
}
//---------------------------------------------
// GetItem
// Retrieves list element whose key matches item's key (if present)
// Pre: List has been initialized.
// Key member of item is initialized.
// Post: If there is an element someItem whose key matches
// item's key, then found = true and someItem is returned;
// otherwise found = false and item is returned unchanged.
// List is unchanged.
//---------------------------------------------
ItemType UnsortedType::GetItem(ItemType& item, bool& found)
{
bool moreToSearch;
NodeType* location;
location = listData;
found = false;
moreToSearch = (location != NULL);
while (moreToSearch && !found)
{
switch (item.ComparedTo(location->info))
{
case LESS :
case GREATER : location = location->next;
moreToSearch = (location != NULL);
break;
case EQUAL : found = true;
item = location->info;
break;
}
}
return item;
}
//---------------------------------------------
// DeleteItem
// Deletes the element whose key matches item's key.
// Pre: List has been initialized.
// Key member of item is initialized.
// One and only one element in list has a key
// matching item's key.
// Post: No element in list has a key matching item's key.
//---------------------------------------------
void UnsortedType::DeleteItem(ItemType item)
{
NodeType* location;
NodeType* tempLocation;
location = listData;
if (item.ComparedTo(location->info) == EQUAL)
{
tempLocation = location;
listData = listData->next;
}
else
{
while (!((item.ComparedTo((location->next)->info) == EQUAL)))
break;
location = location->next;
tempLocation = location->next;
location->next = (location->next)->next;
}
delete tempLocation;
length--;
}
//---------------------------------------------
// ResetList
// Initializes current position for an iteration through the list
// Pre: List has been initialized
// Post: Current position has been initialized
// and is prior to list
//---------------------------------------------
void UnsortedType::ResetList()
{
currentPos = NULL;
}
//---------------------------------------------
// GetNextItem
// Gets next element in list
// Pre: ResetList was called to initialize iteration
// No transformer has been executed since last call
// Current position is defined.
// Post: item is copy of element at current position
// Current position is updated to next position
// Returns: copy of next item in list
//---------------------------------------------
ItemType UnsortedType::GetNextItem()
{
if (currentPos == NULL)
currentPos = listData;
else
currentPos = currentPos->next;
return currentPos->info;
}
//My ItemType.h Code
//------------------------------------------------------
// ItemType
// Class Specification File
// Encapsulates type of items in list
// Ch. 3, C++ Plus Data Structures, Dale 5e, p. 154, 155
// same as code from Ch. 4 ItemType.h
// Filename: ch03-ItemType.h
//------------------------------------------------------
#include
using namespace std;
#ifndef ITEMTYPE_H
#define ITEMTYPE_H
const int MAX_ITEMS = 25;
enum RelationType {LESS, GREATER, EQUAL};
class ItemType
{
private:
string value;
public:
ItemType();
RelationType ComparedTo(ItemType) const;
void Print() const;
void Initialize(string data);
};
//------------------------------------------------------
// UnsortedType
// Linked List - Class Specification File
// Your name
// Your class CS3350 classtime
// Due date: Thursday, September 13, 2012
//
// Defines an unsorted list type whose elements are of ItemType
// Ch. 3, C++ Plus Data Structures, Dale 5e, p. 183-185
// Filename: hw2-UnsortedType.h
// File ch03-ItemType.h must be provided by the user of this class.
// It must contain the following definitions:
// MAX_ITEMS: the maximum number of items on the list
// RelationType: {LESS, GREATER, EQUAL}, an enumerated type
// ItemType: class with definition of the objects in the list
//------------------------------------------------------
class UnsortedType
{
private:
struct NodeType
{
ItemType info;
NodeType* next;
};
NodeType* listData; // Pointer to head of list
int length; // # of items (nodes) in list
NodeType* currentPos;
public:
UnsortedType(); // Constructor
~UnsortedType(); // Destructor
void MakeEmpty(); // Returns the list to the empty state
bool IsFull() const; // Determines whether list is full
int GetLength() const; // Determines the number of elements in list
ItemType GetItem(ItemType& item, bool& found);
// Retrieves list element whose key
// matches item's key (if present)
void PutItem(ItemType item); // Adds item to list
void DeleteItem(ItemType item); // Deletes element whose key
// matches item's key.
void ResetList(); // Initializes current position for
// an iteration through the list
ItemType GetNextItem(); // Gets the next element in list
//void SplitList(ItemType item, UnsortedType &list1, UnsortedType &list2);
// Splits a list into two based on the item
};
#endif // CH03-ITEMTYPE_H_INCLUDED
Solution
The error you are geting for head and tail is because the compiler is not able to find NodeType.
That means you have defined it later but used it before it was known by compiler.
At first, you are having a method DeleteItem() that you need to define. It is already declared in
ItemType.h class
UnsortedType.
Now, to write this code, you will have to go to the file where its implementation is written, Here
it is UnsortedList.cpp.
So, go to the UnsortedList.cpp file. There is a DeleteItem() method already written. You replace
it with the code you have written in the question's starting (from head = ........). This is needed
because the instructions in the comment says that. So, replace it with the code you provided in
starting of the question. This will work for sure.
Do comment for any query. I will address it for sure. Thank you. :)

More Related Content

Similar to Using C++I keep getting messagehead does not name a type.pdf

Week 2 - Advanced C++list1.txt312220131197.docx
Week 2 - Advanced C++list1.txt312220131197.docxWeek 2 - Advanced C++list1.txt312220131197.docx
Week 2 - Advanced C++list1.txt312220131197.docx
melbruce90096
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
stn_tkiller
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
cgraciela1
 
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdfHello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
amittripathi2002
 
Data StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdfData StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdf
arkleatheray
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
mallik3000
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
fsenterprises
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
JUSTSTYLISH3B2MOHALI
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
amitbagga0808
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
nitinarora01
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdf
armyshoes
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
Blake0FxCampbelld
 
Lab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxLab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docx
DIPESH30
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
lakshmijewellery
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
Adamq0DJonese
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
clarkjanyce
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
dhavalbl38
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
ganisyedtrd
 

Similar to Using C++I keep getting messagehead does not name a type.pdf (20)

Week 2 - Advanced C++list1.txt312220131197.docx
Week 2 - Advanced C++list1.txt312220131197.docxWeek 2 - Advanced C++list1.txt312220131197.docx
Week 2 - Advanced C++list1.txt312220131197.docx
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
Please answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docxPlease answer the 4 questions using C- The expected output is shown be.docx
Please answer the 4 questions using C- The expected output is shown be.docx
 
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdfHello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
Hello Everyone!!!I’m writing a c++ program that presents a menu to.pdf
 
Data StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdfData StructuresPlease I need help completing this c++ program..pdf
Data StructuresPlease I need help completing this c++ program..pdf
 
Using the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdfUsing the C++ programming language1. Implement the UnsortedList cl.pdf
Using the C++ programming language1. Implement the UnsortedList cl.pdf
 
Were writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdfWere writing code for a project that dynamically allocates an arra.pdf
Were writing code for a project that dynamically allocates an arra.pdf
 
Write a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdfWrite a program that accepts an arithmetic expression of unsigned in.pdf
Write a program that accepts an arithmetic expression of unsigned in.pdf
 
Program In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdfProgram In C You are required to write an interactive C program that.pdf
Program In C You are required to write an interactive C program that.pdf
 
Uncover and score the usages of the underscore
Uncover and score the usages of the underscoreUncover and score the usages of the underscore
Uncover and score the usages of the underscore
 
Please need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdfPlease need help on following program using c++ language. Please inc.pdf
Please need help on following program using c++ language. Please inc.pdf
 
Data structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdfData structuresUsing java language and develop a prot.pdf
Data structuresUsing java language and develop a prot.pdf
 
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docxIn C pls -- Write your name here -- Write the compiler used- Visual st.docx
In C pls -- Write your name here -- Write the compiler used- Visual st.docx
 
Lab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docxLab11.cppLab11.cpp.docx
Lab11.cppLab11.cpp.docx
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
 
-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx-- Reminder that your file name is incredibly important- Please do not.docx
-- Reminder that your file name is incredibly important- Please do not.docx
 
There are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docxThere are a number of errors in the following program- All errors are.docx
There are a number of errors in the following program- All errors are.docx
 
For each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdfFor each task, submit your source java code file.(1) Objective Im.pdf
For each task, submit your source java code file.(1) Objective Im.pdf
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
-- Write the compiler used- Visual studio or gcc -- Reminder that your.pdf
 

More from alokkesh1

An industry analysis by Porters Five Forces reveals that the soft dr.pdf
An industry analysis by Porters Five Forces reveals that the soft dr.pdfAn industry analysis by Porters Five Forces reveals that the soft dr.pdf
An industry analysis by Porters Five Forces reveals that the soft dr.pdf
alokkesh1
 
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdfABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
alokkesh1
 
Which of the following sets of biomes is placed in order from lowest.pdf
Which of the following sets of biomes is placed in order from lowest.pdfWhich of the following sets of biomes is placed in order from lowest.pdf
Which of the following sets of biomes is placed in order from lowest.pdf
alokkesh1
 
When a planetary nebula forms around a star you see gas emitting ligh.pdf
When a planetary nebula forms around a star you see gas emitting ligh.pdfWhen a planetary nebula forms around a star you see gas emitting ligh.pdf
When a planetary nebula forms around a star you see gas emitting ligh.pdf
alokkesh1
 

More from alokkesh1 (20)

Describe the transformation that has taken place with the function.pdf
Describe the transformation that has taken place with the function.pdfDescribe the transformation that has taken place with the function.pdf
Describe the transformation that has taken place with the function.pdf
 
Each student at State University has a student I.D. number consisting.pdf
Each student at State University has a student I.D. number consisting.pdfEach student at State University has a student I.D. number consisting.pdf
Each student at State University has a student I.D. number consisting.pdf
 
Describe personality traits and their implications in leadership..pdf
Describe personality traits and their implications in leadership..pdfDescribe personality traits and their implications in leadership..pdf
Describe personality traits and their implications in leadership..pdf
 
Analyze Which of the following isare found in ALL species of fungi.pdf
Analyze Which of the following isare found in ALL species of fungi.pdfAnalyze Which of the following isare found in ALL species of fungi.pdf
Analyze Which of the following isare found in ALL species of fungi.pdf
 
An industry analysis by Porters Five Forces reveals that the soft dr.pdf
An industry analysis by Porters Five Forces reveals that the soft dr.pdfAn industry analysis by Porters Five Forces reveals that the soft dr.pdf
An industry analysis by Porters Five Forces reveals that the soft dr.pdf
 
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdfABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
ABSTRACT In 2011, Japan was shocked by the revelation of a fraud at.pdf
 
Why are general capital assets reported on the statement of net asse.pdf
Why are general capital assets reported on the statement of net asse.pdfWhy are general capital assets reported on the statement of net asse.pdf
Why are general capital assets reported on the statement of net asse.pdf
 
Which of the following sets of biomes is placed in order from lowest.pdf
Which of the following sets of biomes is placed in order from lowest.pdfWhich of the following sets of biomes is placed in order from lowest.pdf
Which of the following sets of biomes is placed in order from lowest.pdf
 
When a planetary nebula forms around a star you see gas emitting ligh.pdf
When a planetary nebula forms around a star you see gas emitting ligh.pdfWhen a planetary nebula forms around a star you see gas emitting ligh.pdf
When a planetary nebula forms around a star you see gas emitting ligh.pdf
 
Which of the following is consistent with a history of positibe sele.pdf
Which of the following is consistent with a history of positibe sele.pdfWhich of the following is consistent with a history of positibe sele.pdf
Which of the following is consistent with a history of positibe sele.pdf
 
What is the difference between protein-based and polysaccharide-based.pdf
What is the difference between protein-based and polysaccharide-based.pdfWhat is the difference between protein-based and polysaccharide-based.pdf
What is the difference between protein-based and polysaccharide-based.pdf
 
What is Flexibility of Command Usage.SolutionOne of the advant.pdf
What is Flexibility of Command Usage.SolutionOne of the advant.pdfWhat is Flexibility of Command Usage.SolutionOne of the advant.pdf
What is Flexibility of Command Usage.SolutionOne of the advant.pdf
 
What data type is the value 25.25Solution25.25 is floating po.pdf
What data type is the value 25.25Solution25.25 is floating po.pdfWhat data type is the value 25.25Solution25.25 is floating po.pdf
What data type is the value 25.25Solution25.25 is floating po.pdf
 
What are the reasons for joining management development programs Wh.pdf
What are the reasons for joining management development programs Wh.pdfWhat are the reasons for joining management development programs Wh.pdf
What are the reasons for joining management development programs Wh.pdf
 
true or false A primary sources tend to be firsthand observations of.pdf
true or false A primary sources tend to be firsthand observations of.pdftrue or false A primary sources tend to be firsthand observations of.pdf
true or false A primary sources tend to be firsthand observations of.pdf
 
To what extent can MarxistStructuralist perspectives provide valuab.pdf
To what extent can MarxistStructuralist perspectives provide valuab.pdfTo what extent can MarxistStructuralist perspectives provide valuab.pdf
To what extent can MarxistStructuralist perspectives provide valuab.pdf
 
This Question 1 pt Resources are 0 A, the inputs used to make good a.pdf
This Question 1 pt Resources are 0 A, the inputs used to make good a.pdfThis Question 1 pt Resources are 0 A, the inputs used to make good a.pdf
This Question 1 pt Resources are 0 A, the inputs used to make good a.pdf
 
There are n couples invited to a banquet. Suppose there are some numb.pdf
There are n couples invited to a banquet. Suppose there are some numb.pdfThere are n couples invited to a banquet. Suppose there are some numb.pdf
There are n couples invited to a banquet. Suppose there are some numb.pdf
 
The Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdf
The Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdfThe Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdf
The Northwest Ordinance inclmsted all of the following EXCEPT a. Nom.pdf
 
the initiation phase of eukaryotic transcription via RNA polymerase .pdf
the initiation phase of eukaryotic transcription via RNA polymerase .pdfthe initiation phase of eukaryotic transcription via RNA polymerase .pdf
the initiation phase of eukaryotic transcription via RNA polymerase .pdf
 

Recently uploaded

Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
Elizabeth Walsh
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
httgc7rh9c
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 

Recently uploaded (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17How to Manage Call for Tendor in Odoo 17
How to Manage Call for Tendor in Odoo 17
 
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdfFICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
FICTIONAL SALESMAN/SALESMAN SNSW 2024.pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Play hard learn harder: The Serious Business of Play
Play hard learn harder:  The Serious Business of PlayPlay hard learn harder:  The Serious Business of Play
Play hard learn harder: The Serious Business of Play
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lessonQUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
QUATER-1-PE-HEALTH-LC2- this is just a sample of unpacked lesson
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
OSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & SystemsOSCM Unit 2_Operations Processes & Systems
OSCM Unit 2_Operations Processes & Systems
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111Details on CBSE Compartment Exam.pptx1111
Details on CBSE Compartment Exam.pptx1111
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
Introduction to TechSoup’s Digital Marketing Services and Use Cases
Introduction to TechSoup’s Digital Marketing  Services and Use CasesIntroduction to TechSoup’s Digital Marketing  Services and Use Cases
Introduction to TechSoup’s Digital Marketing Services and Use Cases
 

Using C++I keep getting messagehead does not name a type.pdf

  • 1. Using C++ I keep getting message: 'head does not name a type' 'teal does not name a type' Where do I place this code in my program: /*search and delete with respect to location as current, head and tail //define below 2 lines in LinkedList() function head = new NodeType; tail = new NodeType; void UnsorderedType::DeleteItem(ItemType item) { NodeType *tempLocation, *location; bool stop = false; if(!isEmpty()) { location = head; tempLocation = head->link; while (templocation != tail && !stop) { if (templocation->info == item) stop = true; else { location = templocation; templocation = templocation->link; } } if (!stop) cout << "The node to delete is not in the list!" << endl; else { location->link = templocation->link;
  • 2. delete templocation; count--; } } else { cout << "The list is empty!" << endl; } }*/ /Problem and code: Implement the UnsortedList class to store a list of strings that are input into the list from data2.txt. - create a main.cpp file that gets the numbers from the file - insert the word "cat" into the list - insert another word "antibacterial" into the list - delete the word "letter" from the list - print out the following: --the entire list - the greatest - the least 2. Attach the main.cpp, UnsortedList.cpp, the ItemType.h, and the output file one called outfile1.txt - Yes you need to make your program output an "outfile1.txt" 3. Implement the UnsortedList class to store a list of numbers that are input into the list from data.txt. - create a main.cpp file that gets the numbers from the file - insert the number 7 into the list - insert another number 300 into the list - delete the number 6 from the list - print out the following: --the entire list - the greatest - the least 2. Attach the main.cpp, UnsortedList.cpp, the ItemType.h, and the output file two called outfile2.txt - Yes you need to make your program output an "outfile2.txt"
  • 3. data.txt super formula travel free thick Josephine Clara education data2.txt super formula travel free thick Josephine Clara education //My main.cpp //-------------------------------------------------------------- // Test driver for Linked List UnsortedType list // Navarr Barnier // Your class CS3350 TTh 1:00 // Due date: Thursday, September 13, 2012 // // Compile command: g++ hw2.cpp ch03-UnsortedType.cpp ch03-ItemType.cpp // Input file name: hw2.txt // Contains list of commands to add items to list, split original // list into two lists, print each list and get the length of // each list. // Output: The result of each command is displayed on the screen. // Filename: hw2.cpp //-------------------------------------------------------------- #include #include #include #include #include #include "ItemType.h" using namespace std; void PrintList(UnsortedType&); void SplitList(UnsortedType&, ItemType); ItemType GetItem(ItemType& item, bool& found); int main() { ifstream inFile; // file containing operations ofstream outFS; // Output file stream string data; // operation to be executed string command; // operation to be executed int count = 0;
  • 4. ItemType item; UnsortedType list; bool found; //int numCommands; //---------------------------------------- // Open input file with commands for testing // list operations, check success of open //---------------------------------------- inFile.open("data2.txt"); if (!inFile) { cout << "Unable to open input file - ending program." << endl; return 1; } //---------------------------------------- // Read in and process commands to apply to list //---------------------------------------- //inFile >> data; //numCommands = 0; while (!inFile.eof()) { //numCommands++; //cout << "Command " << numCommands << ": " << command << " "; //---------------------------------------- // PutItem //---------------------------------------- inFile >> data; item.Initialize(data); list.PutItem(item); ++count; item.Print(); cout << ", " << "added to list" << endl; } inFile.close(); cout << " " << count << " words total in list." << " "; inFile.open("hw6.txt");
  • 5. if (!inFile) { cout << "Unable to open input file - ending program." << endl; return 1; } //---------------------------------------- // Read in and process commands to apply to list //---------------------------------------- inFile >> command; //numCommands = 0; while (command != "Quit") { // numCommands++; // cout << "Command " << numCommands << ": " << command << " "; //---------------------------------------- // PutItem //---------------------------------------- if (command == "PutItem") { inFile >> data; item.Initialize(data); list.PutItem(item); item.Print(); cout << " added to list" << endl; } //---------------------------------------- // GetItem //---------------------------------------- else if (command == "GetItem") { inFile >> data; item.Initialize(data); item = list.GetItem(item, found); item.Print(); if (found) cout << " found in list." << endl;
  • 6. else cout << " not in list." << endl; } //---------------------------------------- // DeleteItem //---------------------------------------- else if (command == "DeleteItem") { inFile >> data; item.Initialize(data); list.DeleteItem(item); item.Print(); cout << " deleted from list" << endl; } //---------------------------------------- // GetLength //---------------------------------------- else if (command == "GetLength") cout << "Length of list = " << list.GetLength() << endl; //---------------------------------------- // IsFull //---------------------------------------- else if (command == "IsFull") if (list.IsFull()) cout << "List is full." << endl; else cout << "List is not full." << endl; //---------------------------------------- // MakeEmpty //---------------------------------------- else if (command == "MakeEmpty") { list.MakeEmpty(); cout << "List is empty." << endl; } //---------------------------------------- // PrintList
  • 7. // Non-member function to print list of items //---------------------------------------- else if (command == "PrintList") { cout << " List values" << endl; PrintList(list); } //---------------------------------------- // SplitList // Split the list //---------------------------------------- else if (command == "SplitList") { inFile >> data; item.Initialize(data); //SplitList(list,item); } //---------------------------------------- // Invalid command //---------------------------------------- else cout << command << " is not a valid command." << endl; inFile >> command; }; cout << "Testing completed." << endl; inFile.close(); /*//---------------------------------------- // PutItem //---------------------------------------- if (command == "PutItem") { inFile >> data; item.Initialize(data); list.PutItem(item); item.Print(); cout << " added to list" << endl;
  • 8. } //---------------------------------------- // GetItem //---------------------------------------- else if (command == "GetItem") { inFile >> data; item.Initialize(data); item = list.GetItem(item, found); item.Print(); if (found) cout << " found in list." << endl; else cout << " not in list." << endl; } //---------------------------------------- // DeleteItem //---------------------------------------- else if (command == "DeleteItem") { inFile >> data; item.Initialize(data); list.DeleteItem(item); item.Print(); cout << " deleted from list" << endl; } //---------------------------------------- // PrintList // Non-member function to print list of items //---------------------------------------- else if (command == "PrintList") { cout << " List values" << endl; PrintList(list); } */
  • 9. return 0; } //---------------------------------------- // PrintList // Non-member function to print all items in list // Pre: list has been initialized // Post: Each component in list has been written to cout //---------------------------------------- void PrintList(UnsortedType &list) { int length; ItemType item; list.ResetList(); length = list.GetLength(); for (int counter = 1; counter <= length; counter++) { item = list.GetNextItem(); item.Print(); cout << endl; } cout << "Length of list = " << length << endl << endl; } //My UnsortedList.cpp Code //------------------------------------------------------ // ItemType // Class Implementation File // Ch. 3, C++ Plus Data Structures, Dale 5e, p. 155 // Filename: ch03-ItemType.cpp //------------------------------------------------------ #include #include #include "ItemType.h" using namespace std; //------------------------------ // ItemType // default constructor
  • 10. //------------------------------ ItemType::ItemType() { value = ""; } //------------------------------ // ComparedTo // Compares one ItemType object to another. Returns // LESS, if self "comes before" item // GREATER, if self "comes after" item // EQUAL, if self and item are the same //------------------------------ RelationType ItemType::ComparedTo(ItemType otherItem) const { if (value < otherItem.value) return LESS; else if (value > otherItem.value) return GREATER; else return EQUAL; } //------------------------------ // Initialize //------------------------------ void ItemType::Initialize(string data) { value = data; } //------------------------------ // Print // Adds ItemType value to output stream //------------------------------ void ItemType::Print() const // pre: out has been opened. // post: value has been sent to the stream cout. { cout << value; } //------------------------------------------------------ // UnsortedType // Linked List - Class Implementation File // Your name // Your class CS3350 classtime
  • 11. // Due date: Thursday, September 13, 2012 //------------------------------------------------------ //--------------------------------------------- // Constructor //--------------------------------------------- UnsortedType::UnsortedType() { length = 0; listData = NULL; } //--------------------------------------------- // Destructor // Deallocates all items in list // Post: List is empty // All items have been deallocated //--------------------------------------------- UnsortedType::~UnsortedType() { NodeType* tempPtr; // Loop removes all nodes from list // deallocating space for each one while(listData != NULL) { tempPtr = listData; listData = listData->next; delete tempPtr; } } //--------------------------------------------- // MakeEmpty // Returns the list to the empty state // Post: List is empty //--------------------------------------------- void UnsortedType::MakeEmpty() // Post: List is empty {
  • 12. NodeType* tempPtr; // Loop removes all nodes from list // deallocating space for each one while(listData != NULL) { tempPtr = listData; listData = listData->next; delete tempPtr; } length = 0; } //--------------------------------------------- // IsFull // Function: Determines whether list is full. // Pre: List has been initialized. // Post: Function value = (list is full) // Returns: true if there is no room for another // ItemType on the free store; false otherwise. //--------------------------------------------- bool UnsortedType::IsFull() const { NodeType* location; // Try adding a new node, if successful, there // is room for more nodes so list is NOT full try { location = new NodeType; delete location; return false; } // If adding a new node was unsuccessful, // the list is full catch(bad_alloc) { return true; }
  • 13. } //--------------------------------------------- // GetLength // Determines number of elements in list // Pre: List has been initialized // Post: Number of items in the list is returned //--------------------------------------------- int UnsortedType::GetLength() const { return length; } //--------------------------------------------- // PutItem // Adds item to list // Pre: List has been initialized // List is not full // item is not in list // Post: item is in list; length has been incremented //--------------------------------------------- void UnsortedType::PutItem(ItemType item) { NodeType* location = new NodeType; location->info = item; location->next = listData; listData = location; length++; // Increment length of list } //--------------------------------------------- // GetItem // Retrieves list element whose key matches item's key (if present) // Pre: List has been initialized. // Key member of item is initialized. // Post: If there is an element someItem whose key matches // item's key, then found = true and someItem is returned; // otherwise found = false and item is returned unchanged. // List is unchanged.
  • 14. //--------------------------------------------- ItemType UnsortedType::GetItem(ItemType& item, bool& found) { bool moreToSearch; NodeType* location; location = listData; found = false; moreToSearch = (location != NULL); while (moreToSearch && !found) { switch (item.ComparedTo(location->info)) { case LESS : case GREATER : location = location->next; moreToSearch = (location != NULL); break; case EQUAL : found = true; item = location->info; break; } } return item; } //--------------------------------------------- // DeleteItem // Deletes the element whose key matches item's key. // Pre: List has been initialized. // Key member of item is initialized. // One and only one element in list has a key // matching item's key. // Post: No element in list has a key matching item's key. //--------------------------------------------- void UnsortedType::DeleteItem(ItemType item) { NodeType* location; NodeType* tempLocation;
  • 15. location = listData; if (item.ComparedTo(location->info) == EQUAL) { tempLocation = location; listData = listData->next; } else { while (!((item.ComparedTo((location->next)->info) == EQUAL))) break; location = location->next; tempLocation = location->next; location->next = (location->next)->next; } delete tempLocation; length--; } //--------------------------------------------- // ResetList // Initializes current position for an iteration through the list // Pre: List has been initialized // Post: Current position has been initialized // and is prior to list //--------------------------------------------- void UnsortedType::ResetList() { currentPos = NULL; } //--------------------------------------------- // GetNextItem // Gets next element in list // Pre: ResetList was called to initialize iteration // No transformer has been executed since last call // Current position is defined. // Post: item is copy of element at current position // Current position is updated to next position
  • 16. // Returns: copy of next item in list //--------------------------------------------- ItemType UnsortedType::GetNextItem() { if (currentPos == NULL) currentPos = listData; else currentPos = currentPos->next; return currentPos->info; } //My ItemType.h Code //------------------------------------------------------ // ItemType // Class Specification File // Encapsulates type of items in list // Ch. 3, C++ Plus Data Structures, Dale 5e, p. 154, 155 // same as code from Ch. 4 ItemType.h // Filename: ch03-ItemType.h //------------------------------------------------------ #include using namespace std; #ifndef ITEMTYPE_H #define ITEMTYPE_H const int MAX_ITEMS = 25; enum RelationType {LESS, GREATER, EQUAL}; class ItemType { private: string value; public: ItemType(); RelationType ComparedTo(ItemType) const; void Print() const; void Initialize(string data); }; //------------------------------------------------------
  • 17. // UnsortedType // Linked List - Class Specification File // Your name // Your class CS3350 classtime // Due date: Thursday, September 13, 2012 // // Defines an unsorted list type whose elements are of ItemType // Ch. 3, C++ Plus Data Structures, Dale 5e, p. 183-185 // Filename: hw2-UnsortedType.h // File ch03-ItemType.h must be provided by the user of this class. // It must contain the following definitions: // MAX_ITEMS: the maximum number of items on the list // RelationType: {LESS, GREATER, EQUAL}, an enumerated type // ItemType: class with definition of the objects in the list //------------------------------------------------------ class UnsortedType { private: struct NodeType { ItemType info; NodeType* next; }; NodeType* listData; // Pointer to head of list int length; // # of items (nodes) in list NodeType* currentPos; public: UnsortedType(); // Constructor ~UnsortedType(); // Destructor void MakeEmpty(); // Returns the list to the empty state bool IsFull() const; // Determines whether list is full int GetLength() const; // Determines the number of elements in list ItemType GetItem(ItemType& item, bool& found); // Retrieves list element whose key // matches item's key (if present) void PutItem(ItemType item); // Adds item to list
  • 18. void DeleteItem(ItemType item); // Deletes element whose key // matches item's key. void ResetList(); // Initializes current position for // an iteration through the list ItemType GetNextItem(); // Gets the next element in list //void SplitList(ItemType item, UnsortedType &list1, UnsortedType &list2); // Splits a list into two based on the item }; #endif // CH03-ITEMTYPE_H_INCLUDED Solution The error you are geting for head and tail is because the compiler is not able to find NodeType. That means you have defined it later but used it before it was known by compiler. At first, you are having a method DeleteItem() that you need to define. It is already declared in ItemType.h class UnsortedType. Now, to write this code, you will have to go to the file where its implementation is written, Here it is UnsortedList.cpp. So, go to the UnsortedList.cpp file. There is a DeleteItem() method already written. You replace it with the code you have written in the question's starting (from head = ........). This is needed because the instructions in the comment says that. So, replace it with the code you provided in starting of the question. This will work for sure. Do comment for any query. I will address it for sure. Thank you. :)