University of Calgary

survey analysis

SURVEY ANALYSIS

Source: Katrin Becker, 1985

 
Write a program to read in survey results from a file whose name is to be provided by the user. The survey questionnaire (input) is as follows:
 SEX  AGE  ANNUAL INCOME
 M 25  24000
F 23 22000
M 35 52000
 F 32 20000
 F 28 38000
 etc.    
     
The header portion (SEX, AGE, ANNUAL INCOME) is not actually part of the input file.
 
A sample file will be provided, but you should test your program using smaller files of your own making. There will be a maximum of 200 survey results. All input will be of the correct type (sex will be a single letter, age some positive integer, and salary will also be some positive integer), but may not be reasonable. You will have to choose a reasonable range for each kind of value (an age of 2 seems unreasonable, as does a salary of 100 - in this country at least). If one value in the trio is invalid, then neither of the other two can be used. Because you are doing input from a file, it is not recommended to give the user a chance to re-enter. Simply print some message, and discard the values.Once you have read and saved the values, do the following:
 
1. count the number of males and females and print the counts
 
2. compute and print the following information both for AGE and SALARY:
a) mean (average)
b) mode (most common value)
c) minimum
d) maximum
e) range (maximum - minimum)
 
3. Separate the groups into male and female and compute the values named in [2] for each sub-group.
 
BONUS:
======
1. [2 points] Write the output to a file rather than the terminal and allow the user to specify the file name.
 
2. [2 points] Extend Bonus 1 by providing a default output file name (eg. if the input file name is given as SURVEY, then the default output file name should be SURVEY.OUT). The user can choose the default by typing nothing and hitting <return> when asked for the name of the output file.
 
3. [2 points] Give specific error messages that include the input file line number of the line where the error occurred.
 
4. [2+ points] Calculate and output other statistics (standard deviation, etc.)
 
5. [10 points] Plot a SCATTER GRAM for each group (males and females) of average income versus age.
 
EXAMPLE:
 
AGE:
65 | *
60 | *
55 | ***
50 | *
45 | *******
40 | *
35 | *
30 | *
25 | *
20 | *****************
---------------------------------------------------------
10-19 20-29 30-39 40-49 50-59 60-69 over
INCOME (in thousands)


Updated: August 6, 2005 10:41 AM