CS211 Programming Exercise 2
Fall 2005 - 100 Points
Due: Lesson 20 (Tues/Wed, 4/5 Mar 2008 )

Objectives:

Due Date/Time: 

Help Policy:

AUTHORIZED RESOURCES: 

      Any, except another cadet’s program.

NOTES: 

Requirements For Documentation:

Problem Overview:

Large amounts of data can become useful information if it is organized and presented visually. And speaking of large amounts of data, the US government gathers enormous amounts of data about the United States population. One such source of data is the Social Security Administration. And now, through the Internet, much of that data is available almost instantly. For example, you can get information about the names for new babes from http://www.ssa.gov/OACT/babynames/. Your task in this assignment is to analyze and visually display data downloaded from this web site.

Have you ever wondered why some people's names are so popular, while other people's names fade out of common use? There may be some sociological explanation for it, but that is outside the scope of this assignment. Your assignment is to create a MATLAB program that will track the popularity of names over the last century (1900 to 2000). An example screen shot from such a program is shown below. The x axis represents time, in years. The y axis represents the ranking of a name's usage for new babies. If a name is ranked number 1 for a specific year, it was used more than any other name in that year. If a name is ranked 126th, then there were 125 more popular names in that year. Since small rankings represent higher usage, the y axis is drawn inverted, with larger ranking values toward the bottom of the graph. The curves shown in the screen shoot represent the 5 names in Dr. Brown's family. As you can see from the graph, the name "Wayne" was a fairly popular name during the first half of the century, but its usage has declined significantly over the last 30-40 years. When you finish your program, you will be able to create such a graph for your family. Pretty exciting, don't you think!

 

Program Description:

Your MATLAB program will be a command-line, menu driven program. A "driver" program that prompts for user input and calls appropriate functions to perform the requested actions is not complex. To save you development time, a driver program is provided for you (PEX2.m). This file contains the following functions:

Function name Description
PEX2() Reads in the baby names data by calling Read_names_data() (see below) and then enters a loop that does not exit until the user selects the "quit" option.
Get_user_option() Displays a set of user options and prompts the user for a selection, which is returned.
 
Read_names_data() We have not yet studied how to read data from a data file. We will cover these issues in lessons 23-26 later in the semester. Therefore, the code required to read the baby name data is provided for you. This function is called as the beginning of the PEX2 function and reads data from a file named "names-data.txt." You must have this data file in the same folder as you PEX2.m file when your program executes. This function returns data in two arrays:
  • Baby_names - a 2D array of characters, where each row contains a unique name
  • Name_rankings - a 2D array with 1 row and 11 columns for each baby name; the 11 columns are the rankings for years 1900, 1910, 1920, .. , 2000 respectively.

You should study the code provided in the PEX2.m file and make sure you understand its basic structure. The code in the primary function PEX2() and the sub-function Get_user_option() should be completely understandable from your current knowledge of MATLAB. You do not need to understand the Read_names_data() code.

Your task is to add code and appropriate sub-functions that will perform the actions described in the Get_user_option() function. Specifically, you must add code to PEX2.m that performs the following tasks:

1: Plot a single name's rankings
2: Plot a set of similar name rankings
3: Clear graph
4: Calculate name statistics
5: Display a bar chart describing the changes in names from census to census
0: Quit

Each of these tasks is explained in detail below. In addition, the HINTS section gives you specific help on some of the harder implementation issues. The code that you add should conform to good program design. If you can accomplish a task using only a few lines of code, then you can place these statements in the appropriate case block of the switch statement in PEX2(). If a task requires more than a few lines of code, then it should be performed in a separate sub-function, with a call to this function placed in the appropriate case block of the PEX2() switch statement. It is sometimes a "judgment call" on whether to make a group of statements a separate function. If you are unsure whether a particular group of code should be a separate sub-function or not, discuss it with your instructor.

Tasks 1 and 2 below will plot lines into a line graph. For full credit on this assignment, you must create a sub-function that will plot a single line into the graph. The input and output arguments required for this sub-function are shown below. This function should then be called with appropriate input arguments to accomplish the plotting for tasks 1 and 2. (PLEASE NOTE: There is flexibility in how this sub-function is implemented. If you need to modify the input and/or output arguments to match your program design, you may do so.)

%==========================================================================
function Names_plotted = Plot_name(Name, Rankings, Names_plotted, Max_ranking)
%--------------------------------------------------------------------------
% DESCRIPTION: Given a baby name and its rankings, plot the rankings
%
% INPUTS:  Name          - A vector of characters; the baby name.
%          Rankings      - A vector of rankings; 11 census values
%          Names_plotted - The previous names that have already been plotted.
%          Max_ranking   - The maximum ranking of any name in the data.
%
% OUTPUTS: Names_plotted - The "Name" is appended to the last row.
%
%--------------------------------------------------------------------------

1) Plot a single name's rankings

2) Plot a set of similar name rankings

3) Clear graph

4) Calculate name statistics

5) Display a bar chart describing the changes in names from census to census

 

Helpful Hints:

General comments:

Task specific comments:

1) Plot a single name's rankings

2) Plot a set of similar name rankings

3) Clear graph

4) Calculate name statistics

5) Display a bar chart describing the changes in names from census to census

The purpose of these "helpful" hints is to address issues you may potentially face while working on this assignment. It is not possible to anticipate all potential problems you may face. Please start early on this assignment and consult with your instructor when you get stuck.
 

Grading Information:

Proper Documentation Statement (-5 pts)?                               

Criteria

Pts

Good programming practice and design

35

Standard header comment block for the file with all elements appropriately filled in

5

Header comment block for each function with all elements appropriately filled in

5

Appropriate commenting in the program body (section comments, variable descriptions)

5

Meaningful and consistently formatted variable names

5

Easy-to-read program formatting (appropriate use of spaces within lines, similar statements grouped and separated with a blank line)

5

The code is grouped into appropriate sub-functions with appropriate arguments passed

10

Program correctness

65

Plots a single name's rankings into the graph correctly

20

Finds a matching name and plots it

5

Finds multiple matching names and plots accordingly

8

Clears graph correctly

2

Calculates statistics correctly

15

Creates correct Bar chart

15

Totals

100

Late Penalties (-25, -50, -75 -100)

 

 

References

This assignment is a modified version of a Computer Science assignment first created by Nick Parlante (http://nifty.stanford.edu/2005/NameSurfer/).