Hey all. I have worked on this in a previous post, but because of the huge difference in work needed, i have reposted it here.

First off, i created a project that would input data from keyboard of a student, this student had name,ssn,dob,school id information that was needed. After inputting this data, you could add classes for this singly student... into an array of objects that included (course name, course semester, course year, and course grade). having done this with a basic array, i had set the array to be size 10 (very limiting if student has, say 11 classes!). Sooo..

For our second project we have to do a linked list of the course objects. Therefore, we can add classes to a single student for as long as we have the memory to store it all!

Here is an error i am getting in my class definition for the student (declaring a linked list):

1>driver.cpp
1>c:\users\tony\documents\visual studio 2008\projects\project2\student.h(27) : error C2143: syntax error : missing ';' before '<'
1>c:\users\tony\documents\visual studio 2008\projects\project2\student.h(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\tony\documents\visual studio 2008\projects\project2\student.h(27) : error C2238: unexpected token(s) preceding ';'
1>Student.cpp
1>c:\users\tony\documents\visual studio 2008\projects\project2\student.h(27) : error C2143: syntax error : missing ';' before '<'
1>c:\users\tony\documents\visual studio 2008\projects\project2\student.h(27) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\tony\documents\visual studio 2008\projects\project2\student.h(27) : error C2238: unexpected token(s) preceding ';'

This is using Visual Studio Pro 2008.

I will post all needed .h and .cpp files that are in the project. I had split them up for ease of read purposes, and per class requirements.

Please could someone explain what this error means? Am i declaring it incorrectly? Have i made a mistake elsewhere?

I have more questions to follow - but first off it would be good to get my linked list defined correctly first!

Thanks all

PS - the SinglyLinkedList.h file is the newest 'addition' to my project - i had this all working flawlessly previously (besides im sure my quirky programming!!!!)

could you post the code to the "student.h" file

That would help huh? Sorry! My apologies!

Should be 'working' now in terms of needed files to attempt a compile!

The error is on line 27 in students.h

SinglyLinkedList<CourseInfo> courses;

It doesn't know what a SinglyLinkedList is because you haven't defined it yet in your SinglyLinkedList.h

If you add

template<typename T>
class SinglyLinkedList
{


};

to your SinglyLinkedList.h it should compile fine!

I thought i did have it: (SinglyLinkedList.h)

template <class ItemType>
class SinglyLinkedList
{
	public:
		SinglyLinkedList() { head = tail = 0;}
		~SinglyLinkedList();
		int isEmpty() {return head == 0} // checks to see if list is empty
		void addToHead(ItemType);
		void delteNode(ItemType);
		bool isInList(ItemType) const;

	private:
		int count; // variable stores # of elements in list
		nodeSLL<ItemType> *head; //pointer to first node in list
		nodeSLL<ItemType> *tail; //pointer to last node in list
};

*** There is more to the .h - than what is listed here, but this is the class definition that you thought i was missing correct???***
This is correct right?

Am i missing something else --- i thought i had that and it was set up correctly!?!

Thanks for the help so far! Please keep helping if possible!

The above post is a big mistake. I was referencing the incorrect singlylinkedlist.h file when trying to compile. the file i was using at the time had no class definition...obvious mistake there! i will upload the new / updated singlylinkedlist.h file here.

new errors, only a couple of them i am getting now:

error C2955: 'nodeSLL' : use of class template requires template argument list
see declaration of 'nodeSLL'
hile compiling class template member function 'SinglyLinkedList<ItemType>::~SinglyLinkedList(void)'
1> with
1> [
1> ItemType=CourseInfo
1> ]
hile compiling class template member function 'SinglyLinkedList<ItemType>::~SinglyLinkedList(void)'

Attached is full error log:

thanks in advance

The errors are coming from the for loop in this

template <class ItemType>
SinglyLinkedList<ItemType>::~SinglyLinkedList() 
{

	for (nodeSLL *p; !isEmpty(); )
	{
		p = head->next;
		delete head;
		head = p;
	}
}

so you might want to check out some information on for loops.
Also, nodeSLL* p should be nodeSLL<ItemType>* p

An easier way of doing the destructor is to use a while loop instead of a for loop

template <class ItemType>
SinglyLinkedList<ItemType>::~SinglyLinkedList() 
{
	while(head != 0)
	{
		nodeSLL<ItemType>* p = head->next;			
		delete head;
		head = p;
	}
}

Hey guys - thanks a ton for all the help so far. Im getting there, at least so i think.

My next question concerns my input. I have to read in from a file and create the student object, and set the students class list all from a given text file. I have done this (at least the namessn,dob,gender, etc) in the cxase 0 of my driver.cpp file.

input file:

John Smith 333222333 01/01/80 M z11119
CS240 Fall 2009 A
CS333 Spring 2009 B
HIST450 Fall 2009 C

My problem is that i unsure how to read my class list - i think a while loop like this would work:

while (inFile)
		{
			//read in class info (courseName, courseYear, courseSemester, courseGrade)
			// be able to read in as many as needed - and add them to the linked list set up in Student.h
		}

But how would i this work? I would have to create a new node at the start of the loop, and then i would send a function each value... but would i still be using my setSemester etc methods? Because i will now be using my linked list...

So for example, i should have:

Start:
LinkedList ->
Node1--
Name = cs240
Semester = Spring
Year = 2009
Grade = A
Next -> Node2
Name = cs340
Semester = Fall
Year = 2008
Grade = C
Next -> Node 3....

etc ... is this my correct logic in thinking this would be possible the way i have set up my linked list?

If so, is it as simple as using my set methods?

Thanks for help and the ideas to you all

Alright guys - i have figured out my last question, and as always have come across a myriad of other things i am unsure of. First off, i am getting a couple of errors i am unsure to their meaning:

(this is a warning, not an error, but need to get it rid of anyway):
Student.h:14, from driver.cpp In file included from Student.h:14, from driver.cpp
\SinglyLinkedList.h [Warning] no newline at end of file

And here are my other errors ... i hope someone can understand what i am TRYING to do, and what my variable and stuff are:

47: SinglyLinkedList.h there are no arguments to `addToHead' that depend on a template parameter, so a declaration of `addToHead' must be available
47 SinglyLinkedList.h (if you use `-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
SinglyLinkedList.h In member function `nodeSLL<ItemType>* SinglyLinkedList<ItemType>::r_deleteNode(const ItemType&, nodeSLL<ItemType>*)':
83 SinglyLinkedList.h expected primary-expression before '*' token
83 SinglyLinkedList.h `next' undeclared (first use this function)

At the present time, i have worked on the following:

In driver.cpp:
I have worked on getting a case 0 so that i can read in from a text file (i will post this file with all data in it here). I have been able to read in and print the correct student name, ssn, etc. But i was hoping i could get input as to the way i did the classID, semester, grade, year, etc.
Case 0:
- i hope that you can see what i am doing by calling the addCourse() function, which i want to send a CourseInfo object to, this function will then call, addToHead() passing it the object, which will add the CourseInfo object to the head of my linked list. Is this possible do you think in what i have tried?

I appreciate all the help you can give me, and i hope you understand what i am trying to do!

- Please know you will have to change the location of my .txt file in the driver.cpp to your needs - as it curently lists my directory information.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.