0

Im working on a c++ project for my data structures class, using nested linked lists.

I am supposed to write a program that reads student names from a file, and creates a linked list out of them. Each entry in the linked list should have the student's name, a pointer to the next student, and a pointer to a linked list of grades for that student. This program allows teachers to input grades for each student.

As for now, Im worried about finding the right way to get started.

The book provided a diagram which shows an example of how the data structure should be: diagram

struct Grade{
 float score;
};

struct GradeNode{
 Grade grade_ptr; //points to Grade above 
 GradeNode *next_gnode; //points to next Grade NODE
};

struct StudentNode {
 string name; //holds Student name 
 GradeNode *grades;  //points to linked list of grades for this student
 StudentNode *next_snode; //points to next student 
};

StudentNode* head = nullptr; //head of student linked list (set to nullptr)

I believe how I have this layed out makes sense but when I run code below:

void appendNode(string n){

StudentNode *node;   //new node

node = new StudentNode;
node->name = n;
node->next_snode = nullptr;

//i just want to print out this node to see if value is initialized correctly
cout<<node->name<<endl; //this student's name prints out 

};

It returns an error saying "linker command failed". I feel like im initializing the node wrong but dont know how to fix it.

If someone has tips on how to find a solution, or a different approach for this task using linked lists, i would really appreciate it.

here is photo of error log enter image description here

17
  • if someone can tell me how to upload photos from a mac photo gallery, I'll upload the diagram for more clarity! :) Commented Jan 31, 2019 at 4:43
  • 1
    Is all code in one file or in multiple files? Commented Jan 31, 2019 at 4:45
  • 1
    Please add the entire error text to your question. It sounds to me like you need to tell the linker to include the C++ standard library. In that respect, this appears to be an issue compiling your program and therefore almost all the background reading you provided is irrelevant. Either that or another symbol in your program is referenced but not available. @Yang is probably on the right track there. Commented Jan 31, 2019 at 4:50
  • Try to drag n' drop the image into the question box. Commented Jan 31, 2019 at 4:51
  • 1
    For future reference, even though error messages might look like a bunch of nonsense to the unpracticed eye, your life will become immeasurably easier if you learn to read and interpret them. Commented Jan 31, 2019 at 6:32

2 Answers 2

2

From image it appears you have declared and used a function buildList(std::string) (in main) but never provide a definition to this function.

Solution: Give a body to buildList function.

Sign up to request clarification or add additional context in comments.

Comments

0

The error occurs when a function has been used in main without providing the function definition. Define the function before usage.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.