Help with my C++ Assignment

Discussion in 'Programming' started by NFreak, Feb 26, 2009.

  1. #1
    I am in an data structures course right now and my latest assignment is a student registration system, where a list of students is stores in a singly linked list, and the students themselves also have a singly linked list for their courses. So there is basically linked lists within each linked list.

    There is also to be a binary search tree to search through the courses ordered by grade ascending. I haven't gotten that far yet. Right now the issue is with creating the linked lists.

    It seems that I get a segmentation fault after I try and create the first student. It is almost as if only one linked list can be active, and something may be interfering with the nested linked lists.

    http://www.nfreak.net/archives/assign4

    That is a list of the files in my project. Run from the assign4.cc program and enter "input.txt" as your input and you will see that it builds the student and prints it out, but then it seg faults after it tries adding that student tot he mani linked list.
     
    NFreak, Feb 26, 2009 IP
  2. Vooler

    Vooler Well-Known Member

    Messages:
    1,146
    Likes Received:
    64
    Best Answers:
    4
    Trophy Points:
    150
    #2
    Assignments are for assessment of studetns. And I would like you should proceed upto you can, and inform your teacher about what is possible and what is impossible for you, so that he can enhance your knowledge.

    Besides I just compiled your source and application crashed after showing contents of input.txt. What I think is problem resides somewhere in dynamic memory allocation and/or deallocation. If you are using Microsoft compiler then compile in debug version to better view the bugs better way when it crashes.

    What exactly the file function "readStudentsFromFile" resides in?

    regards
     
    Vooler, Feb 27, 2009 IP
  3. NFreak

    NFreak Peon

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I worked on the project all night and my issue was in the fact that the constructor was not being called when I created just a pointer, so I started using the "new" keyword to fix that issue. The program is almost done, but now I am having some scope issues.


    CourseInfo.h
    =======================================================

    class CourseInfo{
    friend class Student;
    friend ostream & operator<<(ostream & object, CourseInfo & rightOp);

    private:
    string courseId;
    string yearTake;
    string semesterTake;
    string score;

    public:
    CourseInfo();
    ~CourseInfo();

    void setCourseId(string);
    void setYearTake(string);
    void setSemesterTake(string);
    void setScore(string);

    string getCourseId();
    string getYearTake();
    string getSemesterTake();
    string getScore();
    string getZid();

    bool operator==(CourseInfo &); // allows comparisons of CourseInfo's
    //CourseInfo & operator=(const CourseInfo & rightOp);

    };

    Students.h
    =================================================


    class Student:public Person{

    friend class RegistrationSystem;
    friend class CourseInfo;

    private:
    string zid;

    public:
    LinkedList<CourseInfo> courses;

    Student();
    ~Student();

    void infoPrint();
    void addToTree();
    int loadInfoFromFile(fstream& in, BSTree<CourseInfo> *);

    void addCourse(string, CourseInfo);
    CourseInfo deleteCourse(string, CourseInfo);
    CourseInfo checkCourseTaken(string, CourseInfo);

    string getZ();
    void setZ(string);

    };

    ##########################################

    My issue is this: Each CourseInfo object belongs to a student, but when I am in the student class, I cannot seem to access any of the functions from within the CourseInfo class. I have them friending each other, but I am still getting a compiler error using Quincy that says "getZ was not declared in this scope", when being called from the CourseInfo class.

    Any help?
     
    NFreak, Feb 27, 2009 IP
  4. NFreak

    NFreak Peon

    Messages:
    38
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I decided to just take the easy way out of this one and use the four data fields that are actually *available* in my scope and use them wiser.

    I had course, semester, year, and score. I needed to grab the students ID number and their name, but that was out of scope, so instead, when creating this object I made:

    course = course + " " + semester + " " + year;

    That way i still had the *REAL* semester and year variables open for my own use. I kept score the same because that is how my BSTree was sorted.

    I used the open semester and year variables to store the name and id number, so that was kind of my way of getting around the scope issues. I hope whoever grades this doesn't notice, or at least doesn't kill my score too badly if it is noticed. Oh well.

    Cheers!
     
    NFreak, Feb 27, 2009 IP