Assessment Tool

Lecture 18:  Structures

Content Tested: When to use structs versus arrays

Lecture Content:

Goals:

Assessment Technique:  Categorizing Grids

Purpose:

This activity allows instructors to see if students understand appropriate uses of arrays and structs.
 

Activity:

This activity will give you the opportunity to decide on appropriate tools for a task.  For each of the following scenarios, please indicate if you should use an array or a struct.  After deciding on the appropriate data structure, please describe the contents of the data structure as it applies to each situation.
 
 
Situation Array or Struct? Contents of data structure
1.  Keeping track of rainfall data for a year    
2.  Creating a record for a person in your e-mail address book    
3.  Sorting high temperatures for the previous month    
4.  Finding the median score of your last 20 bowling scores    
5.  Keeping track of the current state of a crossword puzzle    
6.  Keeping track of a day's weather -- rainfall, high temperature, low temperature, average pressure, percent humidity    
7.  Storing a customer profile with their  account number, current balance, expiration date of charge account    
8.  Keeping track of 2 players' positions on a 2-dimensional grid    

Possible Solutions:

Situation Array or Struct? Contents of data structure
1.  Keeping track of rainfall data for a year Array An array of double values where each value represents a single day's rainfall 
2.  Creating a record for a person in your e-mail address book Struct  The struct would contain the person's name (character array) and their e-mail address (character array) and possible a nickname (character array) 
3.  Sorting high temperatures for the previous month Array  An array of ints (temperatures usually recording as ints) where each integer is a high temperature from the previous month 
4.  Finding the median score of your last 20 bowling scores Array  To find the median, we'll need to sort the scores.  The array contains ints where each int represents one of the 20 bowling scores 
5.  Keeping track of the current state of a crossword puzzle Array  Probably a 2-D array of characters where ' ' represents a non-filled in square and 'X' (capital X) represents a black square.  Other lowercase characters represent the current words. 
6.  Keeping track of a day's weather -- rainfall, high temperature, low temperature, average pressure, percent humidity Struct  The struct contains the following fields:  rainfall (double), high_temp (int), low_temp (int), pressure (double), and humidity (int). 
7.  Storing a customer profile with their  account number, current balance, expiration date of charge account Struct  The struct contains the following fields:  account_number (int), current_balance (double), month_exp (int), and year_exp (int) 
8.  Keeping track of 2 players' positions on a 2-dimensional grid Struct or Parallel Arrays The struct would keep track of the x and y coordinates of a player.  With 2 players, we would have two variables of this new type.  OR we could store the x coordinates of both players in an array and the y coordinates of both players in a different array. 

 
 

Possible Uses of Activity: