Assessment Tool

Lecture 17:  Structures

Content Tested:  Applications of Structures

Lecture Content:

Goals:

Assessment Technique:  Application Cards

Purpose:

Instructors can find out how well students understand possible applications of structures and defining new types.

Activity:



In today's lecture we saw how to define a new type using a struct.  Please give examples of applications that might use structs.  After giving the examples, please write the C code for defining structures of these types.

Here are two examples:

A complex number type containing a real part and an imaginary part.

typedef struct {
    double real;     /* real part */
    double imag;     /* imaginary part */
} complex_t;         /* One convention is to name new types with name_t */

A student record type containing an ID, a grade point average, and year in school.

typedef struct {
    int id;          /* id number unique for each student */
    double gpa;      /* grade point average */
    int year;        /* year in school (1 = freshman, 2 = sophomore,
                        3 = junior, 4 = senior, 5 = other */
} student_t;


Possible Uses of Activity: