Week 08 Tutorial Questions

    Multi-file programs

  1. What is a Header file? What is its purpose?

  2. What is an Implementation file? What is its purpose?

  3. How do we compile a multi-file project?

  4. Implement the functions detailed in letters.h in a file called letters.c. Once complete, compile together with the provided main.c.

    Download the files below:

  5. Malloc

  6. What is malloc?
  7. What is sizeof? What does it give us?
  8. Create an int * variable that points to memory allocated using malloc.
  9. For this question, the following struct is defined:
    struct student {
        int zID;
        double mark;
        char name[MAX_NAME_LENGTH];
    };
    
    Write a function struct student *create_student(int zID, double mark, char *name) that creates a new struct student and returns a pointer to it.
  10. Linked Lists

    The following questions will make use of the struct student defined in the malloc section as well as the create_student() function.

  11. What is a linked list? How does it relate to structs in C?
  12. How can we modify struct student to contain a pointer to another struct student?
  13. Why does this new member have to be a pointer?
  14. Create two struct student *'s using the create_student() function from the malloc exercise. These students will have the following information:
    • struct student *harry points at a struct student with:
      • Name: Harry
      • zID: 5000000
      • Mark: 71.3
    • struct student *lucy points at a struct student with:
      • Name: Lucy
      • zID: 5111111
      • Mark: 62.9
  15. Now that we have two struct students, we can create our first linked list! How would we now link these structs such that harry contains a pointer to lucy? What value should the next pointer in the lucy struct have?

    Afterwards, the linked list should look like this (visually):

    Linked list of 2 students
  16. How would we print out the zID of lucy by only using the harry variable?
  17. Having a linked list with 2 nodes is great, but what if we wanted to do 5? Add 3 more students to the linked list after the lucy node.

    Afterwards, the linked list should look similar to this (visually):

    Linked list of 5 students
  18. If we wanted to print the name of all these students, how could that be done through only the harry variable?

  19. CS Pizzeria

    CS Pizzeria is your second assignment this term! The theme of the assignment is managing a pizzeria. Have fun and if you have any questions about the assignment, feel free to ask in your lab, on the forum and in help sessions!

  20. The assignment specification is found on the top bar - just click the button that says "Assignment 2"!

    Have you read the specification?

  21. Have you marked Sasha's lecture in your calendar or watched Sasha’s lecture detailing the assignment?

  22. Have you downloaded the starter code and have it ready to work on in your coding environment?