hi all. in a recent project i created a linked list to store a students course data...such as course ID, year taken, semester taken, and final grade. This program worked without any problems. now, my next project is to create a stack to store the data, instead of a linked list.

BUT, my assumption is that a stack uses a linked list, so why delete my linked list set up, when i could create a new class and give it the extra functionality needed for a stack, and keep the old linked list class...

So i have done this, and i have come across a slight / large problem. I am getting the following errors when trying to compile my code:

driver.cpp(23) : error C2039: 'linkedStack' : is not a member of 'Student'
student.h(10) : see declaration of 'Student'
driver.cpp(23) : error C2228: left of '.isFull' must have class/struct/union
driver.cpp(32) : error C2039: 'linkedStack' : is not a member of 'Student'
student.h(10) : see declaration of 'Student'
driver.cpp(32) : error C2228: left of '.pop' must have class/struct/union
driver.cpp(56) : error C2039: 'linkedStack' : is not a member of 'Student'
student.h(10) : see declaration of 'Student'
driver.cpp(56) : error C2228: left of '.isFull' must have class/struct/union
driver.cpp(63) : error C2039: 'linkedStack' : is not a member of 'Student'
student.h(10) : see declaration of 'Student'
driver.cpp(63) : error C2228: left of '.pop' must have class/struct/union
1>proj3 - 8 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

So i understand that my driver.cpp doesn't realize that the linkedStack IS a member of student (at least i think i set this correctly). My question is... should i be doing this:

Student.h - line 20:

linkedStack<CourseInfo> courseList;

Changed to this:

SinglyLinkedList<courseInfo> courseList;

but if i do that, then i dont include the information within the linkedStack class, so my function calls to pop/push will not work?!

is there something that i could do that would help make this work? Any ideas? I will post a .zip file with all my code files inside (there are 9+ files, so it is just much easier than you having to download 9+ files seperately!).

Thanks!

Tony

Stacks can be based on a variety of other data structures, of which lists are one possibility. Since I don't feel like wading through 9 files of code to answer the question for your specific purposes my response will be a template for a plan to create a stack to hold the course information for a Student wherein the stack is based on a list which can only hold type CourseInfo items.

class CourseInfo  
{
     string name;
     char grade;
     //etc;
};

class SinglyLinkedListOfCourseInfo
{
    public:
       CourseInfo * head;
       void addToFront(CourseInfo c)//etc
    //etc
};

class StackofCourseInfo
{
   private:
      SinglyLinkedListOfCourseInfo list;  
   public:
       void push(CourseInfo c){list.addToFront(c);}
   //etc;
};

class Student
{
    private:
        StackOfCourseInfo ciStack;
    //etc
};
 
//scheme to use above code     
Student s;  //declare a Student object
CourseInfo ci; //declare a CourseInfo object
ci.setName("CS222"); //get information for the CourseInfo object
ci.setGrade('A');
s.ciStack.push(ci);//associate the CourseInfo object with the Student object

In essence the stack class calls a method from the list class member variable to do what is needed. Since the list class member variable is a private member of the stack class, then only methods/variables of the list class that can be accessed by the user are those which are accessable from the public methods in the stack class.

If this is what you are doing, then posting specific relevant sections of code similar to the above rather than asking someone to review all the files would likely lead to more responses.

In the ZIP file, student.h still contains: SinglyLinkedList<CourseInfo> courseList; so the student does NOT contain a linkedStack.

If you want it to contain a linkedStack, you have to tell the compiler by changing the line.

This article has been dead for over six months. Start a new discussion instead.