IT Program Design

301 - Structures

  • Module Overview
  • File Link: module-overview.pdf
  • This module will introduce you to defining your own data types.
  • Reading - Textbooks
  • For this module, you should read the following sections of the textbook;
    • Chapter #10: User-defined Data Types
  • Arrays of Structures
  • File Link: a01.pdf a01.mp4
  • In this exercise, we are going to take our structs and, based on the fact they introduce a new data type in the language, use them everywhere we have been using elementary data types;
    • As parameters to functions
    • As return values
    • As elements of an array
    • As elements of a dynamically allocated array
    Then only, we will examine how they might be used as "pseudo-classes". This first exercise will illustrate how we may manipulate arrays of struct elements. You will see that everything we learned about arrays still applies and what you read about structs nicely integrates with it.
  • Dynamical Array of Structures
  • File Link: a02.pdf a02.mp4
  • Same overall objective than our previous exercise but we now illustrate how structs might be stored inside a dynamically allocated array which brings us to playing with pointers on structs data types.
  • Resizable Int Arrays
  • File Link: a03.pdf a03.mp4 a04.pdf a04.mp4 ria.mp4
  • Beyond using structs as a new data type, which may therefore be leverage in arrays and dynamical arrays by the use of pointers, it is also frequent to use structs to represent a new type of application-domain's "object". This is very similar to the ideas you've been already exposed to in languages such as Java or C++ when dealing with Classes and their Instances. Unlike real object-oriented languages, we do not have the luxury of packing together functions and structs. Instead, we may write a struct representing the data-aspect of things and then write a bunch of functions, each taking as first parameter an instance of such a struct. If we name this first parameter "this" some of you might see better how it relates to what C++ does auto-magically for you. Regardless of such efforts, we are not using an object oriented languages so we won't be able to get polymorphism or inheritance. This, however, doesn't mean we should not structure our projects in a rationale and even "objects-like" manner. This folder will show you how it is done in an exercise meant to define a new type of "objects" - re-sizable arrays of ints.
  • PA301 - Instructions
  • File Links: instructions.pdf
  • This PA will allow you to work on a more elaborate data structure. By doing so, you will review recursion, pointers & dynamic memory handling.
  • Video Lecture - Getting started with this PA
  • File Links: PA301-intro.mp4
  • This video should help you visualize the data structure used in PA301, give you an idea of how you may trace through your work more easily, and give you a head start on both the dictionary_build and dictionary_free functions.
  • PA301 - Templates
  • File Links: templates.zip
  • If you are using the Student Linux Box virtual machine, you do not need to download this material. As usual, starting project folder is provided for the Code::Block IDE.