2 Replies - 964 Views - Last Post: 22 November 2010 - 03:54 PM Rate Topic: -----

#1 woodpryan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 65
  • Joined: 30-April 09

Getting some errors I don't understand

Posted 22 November 2010 - 01:43 PM

I'm getting some errors that I don't understand when attempting to compile these files. First, I'll give the errors in case it can be figured out before looking at the code. Then I'll give the code. This is a program I'm writing for my C++ class, by the way. It's not a test. Just a regular programming assignment. This is the second to last chapter in the book, and we are studying linked lists. Here are my errors:
g++ linkedListIterator.o linkedListType.o unorderedLinkedList.o videoListType.o videoType.o videoStoremain.o -o videoStore
Undefined symbols:
"linkedListType<videoType>::linkedListType()", referenced from:
unorderedLinkedList<videoType>::unorderedLinkedList()in videoStoremain.o
"videoType::getNoOfCopiesInStock() const", referenced from:
videoListType::isVideoAvailable(std::basic_string<char, std::char_traits<char>, std::allocator<char> >) constin videoListType.o
videoType::checkOut() in videoType.o
"unorderedLinkedList<videoType>::insertFirst(videoType const&)", referenced from:
vtable for videoListTypein videoStoremain.o
vtable for unorderedLinkedList<videoType>in videoStoremain.o
"unorderedLinkedList<videoType>::search(videoType const&) const", referenced from:
vtable for videoListTypein videoStoremain.o
vtable for unorderedLinkedList<videoType>in videoStoremain.o
"unorderedLinkedList<videoType>::deleteNode(videoType const&)", referenced from:
vtable for videoListTypein videoStoremain.o
vtable for unorderedLinkedList<videoType>in videoStoremain.o
"linkedListType<videoType>::print() const", referenced from:
_main in videoStoremain.o
"unorderedLinkedList<videoType>::insertLast(videoType const&)", referenced from:
vtable for videoListTypein videoStoremain.o
vtable for unorderedLinkedList<videoType>in videoStoremain.o
"linkedListType<videoType>::~linkedListType()", referenced from:
unorderedLinkedList<videoType>::~unorderedLinkedList()in videoStoremain.o
ld: symbol(s) not found
collect2: ld returned 1 exit status
make: *** [videoStore] Error 1


The object of this program is a video rental store. The program has a lot of code, so please bear with me. For each of the following files, you will first see fileName.h then, the code. Following each .h file is the corresponding .cpp file. The main program is the last file here. Any help that you all could provide would be so greatly appreciated. Thanks.

Here is my code:
#ifndef UNORDERED_LINKED_LIST_H
#define UNORDERED_LINKED_LIST_H

#include <iostream>
#include "node.h"
#include "linkedListType.h"
#include "linkedListIterator.h"

using namespace std;

template <class Type>
class unorderedLinkedList: public linkedListType<Type>
{
public:
	bool search(const Type &searchItem) const;
	//function to determine whether searchItem is in the list.
	//postCondition: returns true if searchItem is in the list,
	//				 otherwise the value false is returned
	
	void insertFirst(const Type &newItem);
	//function to insert newItem at the beginning of the list.
	//postCondition: first point to the new list, newItem is
	//				 inserted at the beginning of the list,
	//				 last points to last node in the list,
	//				 and count is incremented by 1.
	
	void insertLast(const Type &newItem);
	//function to insert newItem at the end of the list.
	//postCondition: first points to the new list,
	//				 newItem is inserted at the end of the list,
	//				 last points to the last node in the list,
	//				 and count is incremented by 1.
	
	void deleteNode(const Type &deleteItem);
	//function to delete deleteItem from the list.
	//postCondition: if found, the node containing
	//				 deleteItem is deleted from the list.
	//				 first points to the first node,
	//				 last points to the last node of the updated
	//				 lis, and count is decremented by 1.
	
};
#endif




#include <iostream>
#include "node.h"
#include "linkedListIterator.h"
#include "linkedListType.h"
#include "unorderedLinkedList.h"

using namespace std;

template <class Type>
bool unorderedLinkedList<Type>::
					search(const Type &searchItem) const
{
	nodeType<Type> *current; //pointer to traverse the list
	bool found = false;
	current = this -> first; //set current to point to the first
					//node in the list
	while (current != NULL && !found) //search the list
		if(current -> info == searchItem) //search item is found
			 found = true;
		else
			current = current -> link; //make current point to the next node
		return found;
}//end search

template <class Type>
void unorderedLinkedList<Type>::insertFirst(const Type &newItem)
{
	nodeType<Type> *newNode; //pointer to create the new node
	newNode = new nodeType<Type>; //creat the new node
	newNode -> info = newItem; //store the new item in the node
	newNode -> link = this -> first; //insert newNode before first
	this -> first = newNode; //make first pointo the actual first node
	this -> count++;		//increment count

	if (this -> last == NULL) //if the list was empty, newNode is also the last node in the list
		this -> last = newNode;
}//end insertFirst

template<class Type>
void unorderedLinkedList<Type>::insertLast(const Type &newItem)
{
	nodeType<Type> *newNode; //pointer to create the new node

	newNode = new nodeType<Type>; //create the new node
	newNode -> info = newItem; //store the new item in the node
	newNode -> link = NULL; //set the link field of newNode to NULL

	if (this -> first == NULL) //if the list is empty, newNode is both
					  //both the first and last node
	{
		this -> first = newNode;
		this -> last = newNode;
		this -> count ++; //increment count
	}
	else //the list is not empty, insert newNode after last
	{
		this -> last -> link = newNode; //insert newNode after last
		this -> last = newNode; //make last point to the actual last node in the list
		this -> count ++; //increment count
	}//end else
}//end insertLast


template <class Type>
void unorderedLinkedList<Type>::deleteNode(const Type &deleteItem)
{
	nodeType<Type> *current; //pointer to traverse the list
	nodeType<Type> *trailCurrent; //pointer just before current
	bool found;

	if (this -> first == NULL) //case 1; the list is empty
		cout << "Cannot delete from an empty list." << endl;
	else
	{
		if(this -> first -> info == deleteItem) //case 2
		{
			current = this -> first;
			this -> first = this -> first -> link;
			this -> count --;

			if(this -> first == NULL) //the list has only one node
			   this -> last = NULL;

			delete current;
		}
		else //search the list for the node for node with the given info
		{
			this -> found = false;
			trailCurrent = this -> first; //set trailCurrent to point
								 //to the first node
			current = this -> first ->link; //set current to point to
									//the second node

			while (current != NULL && !found)
			{
				if (current -> info != deleteItem)
				{
					trailCurrent = current;
					current = current -> link;
				}
				else
				found = true;
			} //end while
			if(found) //case3; if found, delete the node
			{
				trailCurrent -> link = current -> link;
				this -> count --;

				if (this -> last == current) //node to be deleted was last node
				this -> last = trailCurrent; //update the value of last
				delete current; //delete the node from the list
			}
			else
				cout << "The item to be deleted is not in the list." << endl;
			}//end else
		}//end else
	}//end deleteNode




#ifndef NODE_H
#define NODE_H

#include <iostream>

using namespace std;

template<class Type>
struct nodeType
{
	Type info;
	nodeType<Type> *link;
};

#endif


#ifndef LINKED_LIST_ITERATOR_H
#define LINKED_LIST_ITERATOR_H
#include <iostream>
#include "node.h"

using namespace std;

template <class Type>
class linkedListIterator
{
	public:
		linkedListIterator();
		//default constructor.
		//postCondition: current = null;

		linkedListIterator(nodeType<Type> *ptr);
		//constructor with aparameter.
		//postCondition: current = ptr;

		Type operator* ();
		//function to overload the dereferencing operator *.
		//postCondition: returns the info contained in the node.

		linkedListIterator<Type> operator++();
		//overload the pre-increment operator.
		//postCondition: the iterator is advanced to the next node.

		bool operator == (const linkedListIterator<Type> &right) const;
		//overload the equality operator.
		//postCondition: Returns true if this iterator is equal to
		//				 the iterator specified by right,
		//				 otherwise it returns false.

		bool operator !=(const linkedListIterator<Type> &right) const;
		//overload the not equal to operator
		//postCondition: returns true if this iterator is not equal
		//				 to the iterator specified by right,
		//				 otherwise it returns false.

	private:
		nodeType<Type> *current;
		//pointer to point to the current node in the linked list
};
#endif


#include <iostream>
#include "linkedListIterator.h"
#include "node.h"

using namespace std;

template <class Type>
linkedListIterator<Type>::linkedListIterator()
{
	current = NULL;
}
template <class Type>
linkedListIterator<Type>::
						linkedListIterator(nodeType<Type> *ptr)
{
	current = ptr;
}

template <class Type>
Type linkedListIterator<Type>::operator* ()
{
	return current->info;
}

template <class Type>
linkedListIterator<Type> linkedListIterator<Type>::operator++ ()
{
	current = current -> link;
	return *this;
}

template <class Type>
bool linkedListIterator<Type>::operator ==
					(const linkedListIterator<Type> &right) const
{
	return (current == right.current);
}

template <class Type>
bool linkedListIterator<Type>::operator!=
					(const linkedListIterator<Type> &right) const
{
	return (current != right.current);
}



#ifndef LINKED_LIST_TYPE_H
#define LINKED_LIST_TYPE_H
#include <iostream>
#include "linkedListIterator.h"
#include "node.h"

using namespace std;

template <class Type>
class linkedListType
{
public:
	const linkedListType<Type> & operator=
								(const linkedListType<Type> &);
	//overload the assignment operator.
	
	void initializeList();
	//initialize the list to an empty state.
	//postCondition: first = NULL, last = NULL, count = 0;
	
	bool isEmptyList() const;
	//function to ditermine whether the list is empty.
	//postCondition: returns true if the list is empty,
	//otherwise returns false
	
	void print() const;
	//function to output the data contained in each node.
	//postcondition: none
	
	void reversePrint(nodeType<Type> *current) const;
	//function to output the info contained in each node in reverse order.
	
	int length() const;
	//function to return the number of nodes in the list.
	//postcondition: the value of count is returned.
	
	void destroyList();
	//function to delete all the nodes from the list.
	//postCondition: first = NULL, last = NULL, count = 0;
	
	Type front() const;
	//function to return the first element of the list.
	//preCondition: the list must exist and must not be empty.
	//postCondition: if the list is empty, the program
	//					terminates; otherwise, the first
	//					element of the list is returned.
	
	Type back() const;
	//function to return the last element of the list.
	//preCondition: the list must exist and must not be empty.
	//postCondition: if the list is empty, the program terminates;
	//						otherwise the last element
	//						of the list is returned.
	
	virtual bool search(const Type& searchItem) const = 0;
	//function to determine whether searchItem is in the list.
	//postCondition: returns true if searchItem is in the list.
	//otherwise the value false is returned
	
	virtual void insertFirst(const Type &newItem) = 0;
	//function to insert newItem at the beginning of the list.
	//postCondition: first points to the new list, newItem is 
	//				inserted at the end of the list, 
	//				last points to the last node in the list,
	//				and count is incremented by 1.
	
	virtual void insertLast(const Type &newItem) = 0;
	//function to insert newItem at the end of the list
	//postCondition: first points to the new list,
	//				 newItem is inserted
	//				 at the end of the list,
	//				 last points to the last node in the list,
	//				 and count is incremented by 1.
	
	virtual void deleteNode(const Type &deleteItem) = 0;
	//function to delete deleteItem from the list.
	//postCondition: if found, the node containing
	//				 deleteItem is deleted from the list.
	//				 first points to the first node,
	//				 last points to the last node of the updated
	//				 list, and count is decremented by 1.
	
	linkedListIterator<Type> begin();
	//function to return an iterator at the beginning of the linked list
	//postCondition: returns an iterator such that current is set to first.
	
	linkedListIterator<Type> end();
	//function to return an iterator one element past the last
	//element of the linked list.
	//postCondition: returns an iterator such that current is set to NULL
	
	linkedListType();
	//default constructor
	//initializes the list to an empty state.
	//postCondition: first = NULL, last = NULL, count = 0;
	
	linkedListType(const linkedListType<Type> &otherList);
	//copy constructor
	
	~linkedListType();
	//destructor
	//deletes all the nodes from the list.
	//postCondition: the list object is destroyed.


protected:
	int count; //variable to store the number of elements in the list
	nodeType<Type> *first; //pointer to the first node of the list
	nodeType<Type> *last; //pointer to the last node of the list

private:
	void copyList(const linkedListType<Type> &otherList);
	//function to make a copy of otherList.
	//postCondition: a copy of otherList is created and assigned to this list.

};
#endif


#include <iostream>
#include "linkedListIterator.h"
#include "linkedListType.h"

using namespace std;

template <class Type>
bool linkedListType<Type>::isEmptyList() const
{
	return (first == NULL);
}

template <class Type>
linkedListType<Type>::linkedListType() //default constructor
{
	first = NULL;
	last = NULL;
	count = 0;
}

template <class Type>
void linkedListType<Type>::destroyList()
{
	nodeType<Type> *temp; //pointer to deallocate the memory
						 //occupied by the node
	while (first != NULL) //while there are nodes in the list
	{
		temp = first;	 //set temp to the current node
		first = first -> link; //advance first to the next node
		delete temp; 		//deallocate the memory occupied by temp
	}

	last = NULL; //initialize last to NULL; first has already
				//been set to NULL by the while loop
	count = 0;
}

template <class Type>
void linkedListType<Type>::initializeList()
{
	destroyList(); //if the list has any nodes, delete them
}

template <class Type>
void linkedListType<Type>::print() const
{
	nodeType<Type> *current; //pointer to traverse the list

	current = first; //set current so that it points to the first node

	while (current != NULL) //while more data to print
	{
		cout << current -> info << " ";
		current = current -> link;
	}
} //end print

template <class Type>
void linkedListType<Type>::reversePrint
						(nodeType<Type> *current) const
{
	if (current != NULL)
	{
		reversePrint(current -> link); //print tail
		cout << current->info << " "; //print the node
	}
}

template <class Type>
int linkedListType<Type>::length() const
{
	return count;
}

template <class Type>
Type linkedListType<Type>::front() const
{
	assert (first != NULL);
	return first -> info; //return the info of the first node
}//end front
template <class Type>
Type linkedListType<Type>::back() const
{
	assert (last != NULL);

	return last -> info; //return the info of the last node
}//end back

template <class Type>
linkedListIterator<Type> linkedListType<Type>::begin()
{
	linkedListIterator<Type> temp(first);

	return temp;
}

template <class Type>
linkedListIterator<Type> linkedListType<Type>::end()
{
	linkedListIterator<Type> temp(NULL);

	return temp;
}

template <class Type>
void linkedListType<Type>::copyList
					(const linkedListType<Type> &otherList)
{
	nodeType<Type> *newNode; //pointer to create a node
	nodeType<Type> *current; //pointer to traverse the list

	if (first != NULL) //if the list is nonempty, make it empty
		destroyList();
	
	if (otherList.first == NULL) //otherList is empty
	{
		first = NULL;
		last = NULL;
		count = 0;
	}
	else
	{
		current = otherList.first; //current point to the list to be copied
		count = otherList.count;
		//copy the first node
		first = new nodeType<Type>; //create the node
		first -> info = current -> info; //copy the info
		first -> link = NULL; 		//set the link field of the node to NULL
		last = first; 				//make last point to the first node
		current = current -> link;	//make current point to the next node

		//copy the remaining list

		while(current != NULL)
		{
			newNode = new nodeType<Type>; //create a node
			newNode -> info = current -> info; //copy the info
			newNode -> link = NULL;			//set the link of newNode to NULL
			last -> link = newNode;			//attach a newNode after last
			last = newNode;					//make last point to the actual last node
			current = current -> link;		//make current point to the next node
		}//end while
	}//end else
}//end copyList

template<class Type>
linkedListType<Type>::~linkedListType() //destructor
{
	destroyList();
}

template<class Type>
linkedListType<Type>::linkedListType(const linkedListType<Type> &otherList)
{
	first = NULL;
	copyList(otherList);
} //end copy constructor

template<class Type>
const linkedListType<Type> &linkedListType<Type>::operator=
							(const linkedListType<Type> &otherList)
{
	if (this != &otherList) //avoid self-copy
	{
		copyList(otherList);
	}//end if/else
	return this;
}


#ifndef VIDEO_TYPE_H
#define VIDEO_TYPE_H
#include <iostream>
#include <string>

using namespace std;

class videoType
{
	friend ostream &operator << (ostream&, const videoType&);

public:
	void setVideoInfo(string title, string star1, string star2, string producer,
					  string director, string productionCo, int setInStock);
		//function to set the details of the video.
		//the member variables are set according to the parameters.
		//postCondition: videoTitle = title; movieStar1 = star1;
		//movieStar2 = star2; movieProducer = producer;
		//movieProductionCo = productionCo;
		//copiesInStock = setInStock;
	int getNoOfCopiesInStock() const;
		//function to check the number of copies in stock.
		//postCondition: The value of copiesInStock is returned.
	
	void checkOut();
		//function to rent a video.
		//postCondition: The number of copies in stock is decremented by one.
	
	void checkIn();
		//function to check in a video.
		//postCondition: the number of copies in stock is incremented by one.

	void printTitle() const;
		//function to print the title of a movie.
	
	void printInfo() const;
		//function to print the details of a video.
		//postCondition: the title of the movie, star, director,
		//               and so on are displayed on the screen
	
	bool checkTitle(string title);
		//function to check whether the title is the same as the
		//title of the video.
		//postCondition: returns the value true if the title is the same
		//				 as the title of the video; false otherwise
	
	void updateInStock(int num);
		//function to increment the number of copies in stock by
		//adding the value of the parameter num.
		//postConition: copiesInStock = copiesInStock + num;


	void setCopiesInStock(int num);
		//function to set the number of copies in stock.
		//postcondition: copiesInStock = num;
	
	string getTitle() const;
		//function to return the title of the video.
		//postCondition: the title of the video is returned.

	videoType(string title = " ", string star1 = " ", string star2 = " ",
			  string producer = " ", string director = " ",
			  string productionCo = " ", int setInStock = 0);
		//constructor
		//the member variables are set according to the
		//incoming parameters. if no values are specified, the default values are assigned.
		//postCondition: videoTitle = title; movieStar1 = star1;
		//				 movieStar2 = star2;
		//				 movieProducer = producer;
		//				 movieDirector = director;
		//				 movieProductionCo = productionCo;
		//				 copiesInStock = setInStock;
		//
		//overload the relational operators.

	bool operator == (const videoType &) const;
	bool operator != (const videoType &) const;

private:
	string videoTitle;
	string movieStar1;
	string movieStar2;
	string movieProducer;
	string movieDirector;
	string movieProductionCo;
	int copiesInStock;
};
#endif


#include <iostream>
#include <string>
#include "videoType.h"

using namespace std;

void videoType::setVideoInfo(string title, string star1, string star2, string producer,
							 string director, string productionCo, int setInStock)
{
	videoTitle = title;
	movieStar1 = star1;
	movieStar2 = star2;
	movieProducer = producer;
	movieDirector = director;
	movieProductionCo = productionCo;
	copiesInStock = setInStock;
}

void videoType::checkOut()
{
	if (getNoOfCopiesInStock() > 0)
		copiesInStock --;
	else
		cout << "Currently out of stock" << endl;
}

void videoType::checkIn()
{
	copiesInStock ++;
}

void videoType::printTitle() const
{
	cout << "Video Title: " << videoTitle << endl;
}

void videoType::printInfo() const
{
	cout << "videoTitle: " << videoTitle << endl;
	cout << "Stars: " << movieStar1 << " and "
		 << movieStar2 << endl;
	cout << "Producer: " << movieProducer << endl;
	cout << "Director: " << movieDirector << endl;
	cout << "Production Company: " << movieProductionCo
		 << endl;
	cout << "Copies in stock: " << copiesInStock
		 << endl;
}

bool videoType::checkTitle(string title)
{
	return(videoTitle == title);
}

void videoType:: updateInStock(int num)
{
	copiesInStock += num;
}

void videoType::setCopiesInStock(int num)
{
	copiesInStock = num;
}

string videoType::getTitle() const
{
	return videoTitle;
}

videoType::videoType(string title, string star1,
					 string star2, string producer,
					 string director,
					 string productionCo, int setInStock)
{
	setVideoInfo(title, star1, star2, producer, director, productionCo, setInStock);
}

bool videoType::operator == (const videoType &other) const
{
	return (videoTitle == other.videoTitle);
}

ostream &operator << (ostream &osObject, const videoType &video)
{
	osObject << endl;
	osObject << "Video Title: " << video.videoTitle << endl;
	osObject << "Stars: " << video.movieStar1 << " and "
			 << video.movieStar2 << endl;
	osObject << "Producer: " << video.movieProducer << endl;
	osObject << "Director: " << video.movieDirector << endl;
	osObject << "Production Company: " 
			 << video.movieProductionCo << endl;
	osObject << "Copies in Stock: " << video.copiesInStock << endl;
	osObject << "_________________________________________"
			 << endl;
	return osObject;
}


#ifndef VIDEO_LIST_TYPE_H
#define VIDEO_LIST_TYPE_H

#include <string>
#include "unorderedLinkedList.h"
#include "videoType.h"

using namespace std;

class videoListType:public unorderedLinkedList<videoType>
{
public:
	bool videoSearch(string title) const;
	//function to search the list to see whether a
	//particular title, specified by the parameter title,
	//is in the store.
	//postCondition: returns true if the title is found,
	//and false otherwise.
	
	bool isVideoAvailable(string title) const;
	//function to determine whether a copy of a particular video
	//is in the store.
	//postCondition: returns true if at least one copy of the
	//video specified by title is in the store, and false otherwise
	
	void videoCheckOut(string title);
	//function to check out a video, that it, rent a video.
	//postCondition: copiesInStock is decremented by one.
	
	void videoCheckIn(string title);
	//function to check in a video returned by the customer.
	//postCondition: copiesInStock is incremented by one.
	
	bool videoCheckTitle(string title) const;
	//function to determine whether a particular video is in the store.
	//postCondition: returns true if the video's title is the same as
	//title, and false otherwise.
	
	void videoUpdateInStock(string title, int num);
	//function to update the number of copies of a video
	//by adding the value of the parameter num. the parameter
	//title specifies the name of the video for which the
	//number of copies is to be updated.
	//postCondition: copiesInStock = copiesInStock + num;
	
	void videoSetCopiesInStock(string title, int num);
	//function to reset the number of copies of a video.
	//the parameter title specifies the name of the video
	//for which the number of copies is to be reset, and the
	//parameter num specifies the number of copies.
	//postCondition: copiesInStock = num;
	
	void videoPrintTitle() const;
	//function to print the titles of all the videos in the store.

private:
	void searchVideoList(string title, bool &found, nodeType<videoType> * &current) const;
	//this function searches the video list for a particular video, specified by the parameter title.
	//postCondition: if the video is found, the parameter found is set to true, otherwise
	//it is set to false. the parameter current points to the node containing the video.
};

#endif


#include <iostream>
#include <string>

#include "videoListType.h"

using namespace std;

void videoListType::searchVideoList(string title, bool &found, nodeType<videoType>* &current) const
{
	found = false;		//set found to false

	current = first;	//set current to point to the first node in the list

	while(current != NULL && !found) //search the list
		if(current -> info.checkTitle(title)) //the item is found
			found = true;
		else
			current = current -> link; //advance current to the next node
}//end searchVideoList

bool videoListType::isVideoAvailable(string title) const
{
	bool found;
	nodeType<videoType> *location;

	searchVideoList(title, found, location);

	if(found)
		found = (location -> info.getNoOfCopiesInStock() > 0);
	else
		found = false;
	return found;
}

void videoListType::videoCheckIn(string title)
{
	bool found = false;
	nodeType<videoType> *location;

	searchVideoList(title, found, location); //search the list

	if(found)
		location -> info.checkIn();
	else
		cout << "The store does not carry " << title << endl;
}

void videoListType::videoCheckOut(string title)
{
	bool found = false;
	nodeType<videoType> *location;

	searchVideoList(title, found, location); //search the list

	if(found)
		location -> info.checkOut();
	else
		cout << "The store does not carry " << title << endl;
}

bool videoListType::videoCheckTitle(string title) const
{
	bool found = false;
	nodeType<videoType> *location;

	searchVideoList(title, found, location); //search the list

	return found;
}

void videoListType::videoUpdateInStock(string title, int num)
{
	bool found = false;
	nodeType<videoType> *location;

	searchVideoList(title, found, location); //search the list

	if(found)
		location -> info.updateInStock(num);
	else
		cout << "The store does not carry " << title << endl;
}

void videoListType::videoSetCopiesInStock(string title, int num)
{
	bool found = false;
	nodeType<videoType> *location;

	searchVideoList(title, found, location);

	if(found)
		location -> info.setCopiesInStock(num);
	else
		cout << "The store does not carry " << title << endl;
}

bool videoListType::videoSearch(string title) const
{
	bool found = false;
	nodeType<videoType> *location;

	searchVideoList(title, found, location);

	return found;
}

void videoListType::videoPrintTitle() const
{
	nodeType<videoType> *current;

	current = first;
	while(current != NULL)
	{
		current -> info.printTitle();
		current = current -> link;
	}
}




#include <iostream>
#include <fstream>
#include <string>

#include "videoType.h"
#include "videoListType.h"
using namespace std;

void createVideoList(ifstream &infile, videoListType &videoList)
{
	string title;
	string star1;
	string star2;
	string producer;
	string director;
	string productionCo;

	char ch;
	int inStock;

	videoType newVideo;

	getline(infile, title);

	while(infile)
	{
		getline(infile, star1);
		getline(infile, star2);
		getline(infile, producer);
		getline(infile, director);
		getline(infile, productionCo);
		infile >> inStock;
		infile.get(ch);
		newVideo.setVideoInfo(title, star1, star2, producer,
							  director, productionCo, inStock);
		videoList.insertFirst(newVideo);

		getline(infile, title);
	}//end while
}//end createVideoList

void displayMenu()
{
	cout << "Select from one of the following: " << endl;
	cout << "1: To check whether the store carries as particular video." << endl
		 << "2: To check out a video. " << endl
		 << "3: To check in a video." << endl
		 << "4: To check whether a particular video is in stock" << endl
		 << "5: To print only the titles of all the videos." << endl
		 << "6: To print a list of all the videos." << endl
		 << "7: To exit" << endl;
} //end displayMenu

int main()
{
	videoListType videoList;
	int choice;
	char ch;
	string title;

	ifstream infile;
	infile.open("videoDat.txt");//open input file
	if(!infile)
	{
		cout << "The input file does not exist. "
			 << "The program terminates!!!" << endl;
		return -1;
	}
	//create the video list
	createVideoList(infile, videoList);
	infile.close();

	//show the menu
	displayMenu();
	cout << "Enter your choice: ";
	cin >> choice;	//get the request
	cin.get(ch);
	cout << endl;

	while(choice != 7)
	{
		switch(choice)
		{
		case 1:
			cout << "Enter the title: ";
			getline(cin, title);
			cout << endl;
			
			if(videoList.videoSearch(title))
			cout << "The store cares "<< title << endl;

			break;
		case 2:
			cout << "Enter the title: " ;
			getline(cin, title);
			cout << endl;

			if(videoList.videoSearch(title))
			{
				if(videoList.isVideoAvailable(title))
				{
					videoList.videoCheckOut(title);
					cout << "Enjoy your movie: " << title << endl;
				}
				else
					cout << "Currently " << title << "is out of stock. " << endl;
			}
			else
				cout << "The store does not carry " << title << endl;
			break;
		case 3:
			cout << "Enter the title: ";
			getline(cin, title);
			cout << endl;

			if(videoList.videoSearch(title))
			{
				videoList.videoCheckIn(title);
				cout << "Thanks for returning " << title << endl;
			}

			else
				cout << "The store does not carry " << title << endl;
			break;
		case 4:
			cout << "Enter the title: ";
			getline(cin, title);
			cout << endl;

			if(videoList.videoSearch(title))
			{
					if(videoList.isVideoAvailable(title))
						cout << title<< " is currently in stock. " << endl;
					else
						cout << title << " is currently out of stock. " << endl;
			}
			else
				cout << "The store does not carry " << title << endl;
			break;
		case 5:
			videoList.videoPrintTitle();
			break;
		case 6:
			videoList.print();
			break;
		default:
			cout << "Invalid selection. " << endl;
		} //end switch
		
		displayMenu(); //display menu

		cout << "Enter your choice: ";
		cin >> choice;	//get the next request
		cin.get(ch);
		cout << endl;
	}//end while
	return 0;
}//end main



Is This A Good Question/Topic? 0
  • +

Replies To: Getting some errors I don't understand

#2 jimblumberg  Icon User is offline

  • member icon


Reputation: 4220
  • View blog
  • Posts: 13,227
  • Joined: 25-December 09

Re: Getting some errors I don't understand

Posted 22 November 2010 - 02:40 PM

Quote

linkedListIterator.o linkedListType.o unorderedLinkedList.o videoListType.o videoType.o videoStoremain.o -o videoStore
Undefined symbols:


Since the errors listed are linker errors, start by insuring the functions exist int the files above.

Exapmle: Does the linkedListType<videoType>::linkedListType() implementation exist in one of the listed cpp files?
Does the videoType::getNoOfCopiesInStock() const function exist?

Are you compiling and linking all of your source files?

A linker error usually means that you either have not written the function or the file with the function is not being linked.

Jim
Was This Post Helpful? 0
  • +
  • -

#3 woodpryan  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 65
  • Joined: 30-April 09

Re: Getting some errors I don't understand

Posted 22 November 2010 - 03:54 PM

all of the functions exist. I'm still lost. Here is the makefile I'm using:
CXX = g++

SOURCES = linkedListIterator.cpp linkedListType.cpp \
 unorderedLinkedList.cpp videoListType.cpp videoType.cpp\
 videoStoremain.cpp

OBJECTS = $(patsubst %.cpp,%.o,$(SOURCES))

PROGRAM = videoStore

$(PROGRAM): $(OBJECTS)
	$(CXX) $(OBJECTS) -o $(PROGRAM)
%.o: %.cpp
	$(CXX) -c $< -o $@
clean:
	rm -rf $(OBJECTS) $(PROGRAM)



I could also use this command to compile: g++ linkedListIterator.cpp linkedListType.cpp unorderedLinkedList.cpp videoType.cpp videoListType.cpp videoStoremain.cpp -o video
and it will generate the same errors. I created the makefile because it is easier to just say "make" rather than type out all that every time I want to compile this thing. But, yes, all the functions have been written. I'm using the correct commands to compile. I don't know what the deal is.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1