Hello, are there any C programmers that would be willing to help me figure some things out for my assignment?

As the title states, I'm currently working on assignment for my Computer Science class (due tomorrow) and I'm kind of lost as to what I should do next. Usually I wouldn't reach out for help but I'm kind of in a hole right now and I can't seem to climb out.

Anyways, essentially it's just a gradebook program that uses structures as a way to store the data. I have a little bit of the code written so far but it's nowhere near finished. In the end the data should be stored through dynamic memory allocation or through linked lists but I'm nowhere near that point. This assignment is a continuation of another assignment that I had last week (which I was unable to finish as well) so I can't fail to turn this one in as well. Any help would be greatly appreciated!

Now I don't want to sound like I am condescending you or anything, but your post has me worried. Mainly because I myself have been through higher education and currently further.

It sounds like you are struggling. If you are, ask for help, tutors and lecturers will always lend a hand, its their job. They're not there to simply pass stuff off to you, because if someone fails it looks bad on them, so it is in their best interest to get as many to pass as possible.

Although it is better for a person to learn than to be told, which exact C language are you using?

yeah really , what exactly does this program do?

Well the class I'm in is a weed-out class (as told to me by my lab TA) so it's definitely a lot harder than it should be. And the language is C itself, not any other variant. Also, it's really hard to see a lot of the tutors and stuff because they're always busy with other students. Also, I don't think it's C itself that I'm struggling with, its just this specific assignment because I've been making 90's and 100's on all of the labs as well as the weekly quizzes.

It's a gradebook program. You have to be able to add a new course, add a new student, add students to courses, add grades for a student in a course, print a list of all the grades for a student in a course, print a list of all students in a course, compute the average for a student in a course, print a list of all courses, print a list of all the students, compute the average for a course, store grade book (to a disk file), and load grade book (from disk file). The only times I can use statically called arrays is for the names of the different things (i.e. students & course names), otherwise the data all has to be dynamically allocated.

What I'm struggling with is being able to associate the different parts of the data with each other and being able to efficiently call that data so I can use it for the different functions in the program (how am I supposed to associate a student with a course and then associate grades with both the student and the course while still being able to have separate grades for the students that are in different courses?).

Also, I'm sorry if this is a little scattered. My brain is a bit fried at the moment.

Well book meetings, chase them down. If not, converse with other students as you may find other people are having issues understanding the set papers as well.

Anyway, working on a response to below reply.

Think of databases and Primary keys, with unique ID for each entry being linked via foreign keys.

So say you have a course, student and grade database. Each course will have a unique identifier.  eg:

So as we can see from our "Grades" table, in the course "Applied Computing" (3) student "Bill Gates" (4) scored 69%.

Hopefully this makes things a bit clearer in terms of what data you are dealing with.

Oh okay, this makes a bunch more sense. Does this mean that I'm going to associate the grade with both the student and the course?

You are associating the grade with a student and what course that student is on.

I understand what you are going through.  In most CS curricula, the first few classes are weed out classes.  I went through this myself at my undergrad Comp Sci program, many, many years ago.

But you really should have asked for help sooner, having just a few things done the night before the project is due is a difficult place to be in, and it is going to be very hard to complete by tomorrow. 

I will give you some advice, as soon as you get a programming assignment, you have to start it that night.  Otherwise, you will not be able to complete the assignment.  They usually give you a couple of weeks per assignment, and between learning the new concepts they throw at you and learning the syntax of the language, you will need every night to not only complete the assignment, but get a good grade on it.

I will try to point you in the right direction, but if you cannot get an extension for the project, you may have to drop the class and retake it next semester.

Assuming that all you need to keep track of is courses and students in each course and there is no correlation between the same student in multiple courses, probably the easiest approach is to have a linked list for courses and inside each element of the courses linked list have a linked list of students in the course.

So your element structures will look something like this:

typedef struct studentElement

{

   char *studentName;

   int grade;

   struct studentElement *next;

}student;

typedef struct courseElement

{

   char *name;

   struct studentElement *list;

   struct courseElement *next;

}course;

to allocate a student element:

student  *newStudent;

newStudent = (student *) malloc(sizeof(student));

to allocation a course element:

course *newCourse;

newCourse = (course *) malloc(sizeof(course));

For the course linked list, you will need to have a pointer to the head of the list that will always point to the first element of the list.  You will also need another pointer that will start out pointing at the head of the list and be used to traverse the list to search for the list elements to update and print.  If sort order of the list does not matter, you probably want to have a tail pointer that will point to the last element of the course list so you can quickly and easily add a new element to the list. 

course *head, *tail, *current;

Repeat this functionality for the student list contained in each course element. 

To get data in the the course and student lists, the quick and dirty approach would be to have your main method prompt the user to add a new course, add a new student to course, or add a grade to a student.  You can use 1, 2, and 3, for user choices, so if the user enters 1 prompt for all of the information needed for the course, create the course node, and add it to the course linked list.  Get this course part working first, then move on to the harder part of adding students to each course.  Depending on what your requirements are, you may need to throw exceptions if the user enters duplicate data or invalid data.  Be sure to check for this.

Good luck!

as soon as you get a programming assignment, you have to start it that night.

That really goes for anything. You know the cliche of the solution to a problem coming to someone when they are in the shower? That happens because you brain works on problems you are stuck on in the background (very often in your sleep). In order to maximise you "background processing" time you need to get to the point where you would be stuck sooner rather than later. 

Yeah, I have the add course and add student functions down, they're just not dynamically storing the data (which is a big part of this assignment). I think at this point I'm just going to give up and aim for a perfect score on the rest of the homework assignments. Maybe I'll try to get the functions that I have now to dynamically store the data that they're receiving so I can at least get some points for turning in a program that compiles and has some sort of functionality to it.

As for the part about starting the homework as soon as I get it, I've always been really bad at that. I'm a terrible procrastinator and it's only gotten worse now that I'm working 30-40 hours a week to pay for rent and stuff. Along with having a total of 3 labs, homework just seems to be piling up! Anyways, thanks a bunch for your response (this goes for everyone that respond) it really helped. Even though I'm probably not going to finish this assignment, I feel like I gained an understanding of structs and I feel like I at least know the theory of how linked lists work (I'm not entirely sure how I implement them but I'm sure I'll figure that out too). Honestly, I don't really care too much about the grades, I just really care about the knowledge. Anyways, thanks again and next time I'll make sure to start earlier on my next assignment. I would love to post what I have so far just so I can get you guys' (or gals') opinions on what I should have done differently.

Yep, that's absolutely right.  Even if you just read through a problem and do nothing but think through it.  When you come back to work out a solution, you will do it faster and come up with a better solution than if you try to cram through it.

 

Believe me I understand procrastination and it sucks having to work and go to school at the same time.  I had to do that for my last four semesters of undergrad and for the whole time I was in grad school.  It really leaves you zero free time.  If you want to post your code on pastebin, I would be happy to look through your solution.

The key points to understanding linked lists are:

  1. Each element in the list has a pointer to the next element in the list, except for the last, which points to null.  And within a given element in the list, you can access the next element in the list using the pointer to the next element, and you can access the element after that by using that element’s next pointer, and so on, until you reach the end of the list.
  2. You allocate memory (malloc) for new elements as you need them.  When you want to add a new element to the list, you read in the data, create a new element, and either insert it somewhere in the list—if order matters—or add the new element to the end of the list.  If you are adding the new element to the end of the list, you set the old last element’s next point to the new element and set the new element’s next point to null.  If you are inserting a new element in the middle of the list, the insertion process is a little more complicated, but not much.  You set the next point of the element that should be before the new element to the new element, then set the new element’s next pointer to where the next pointer of the element before the new element used to point.
  3. To perform operations against elements of the list, you use a traversing pointer that starts at the top (head) of the list and step through each element until you locate the element you want to update, print, or delete, or you can traverse the whole list if you need to print the entire list or perform some aggregate function against list data.

Those are the main points of a linked list.  There are other and there are other types of linked listed, like double linked lists, circular linked links, and skip lists, just to name a few.