The rodent lab in the psychology department is collecting data from their experiments. They have files containing data about the choices that squirrels have made in their experiments, collecting food from different foraging sites. They need your help to write a program that summarizes their data.
The Problem
The files of data from the squirrel experiments contain lines with the following form:
squirrel# trial# site# found-food?
Where squirrel# is the integer number assigned to that squirrel in the experiment. trial# is an integer that refers to the number of the trial. Each squirrel forages in the experimental apparatus several times, each time with some of the sites baited with various numbers of food items. Each time the squirrel goes on the maze is a separate trial. site# is the integer number that is assigned to the foraging site for purposes of the experiment. found-food? is an integer and is 1 if the squirrel found food when he/she went to the particular foraging site on this trial, and 0 if the squirrel did not find food when he/she went to the foraging site on this trial.
Your problem is to produce a summary of the data from the squirrels in the experiment. For each squirrel, you are going to give the number of trials (which is also the total number of site choices), the number of different foraging site choices, and the performance of the squirrel (number of times food found divided by total # of site choices). You will output this summary per squirrel.
Use a 2D array (a matrix) to store all the data in the file, and then use this array to produce the summary of the data.
Sample Input and Output
Sample Input
This gives the contents of a sample input file for data on five squirrels numbered 0, 1, 2, 4, and 6. Squirrel 0 has three rows in the file (the first three rows in the file), squirrel 1 has seven rows in the file (the next seven rows) etc. Notice that while the file ends on squirrel number 6 (a single row at the end of the file), there is no data for squirrel 3 and none either for squirrel 5.
0 1 8 1 0 2 0 1 0 3 8 1 1 1 2 0 1 2 8 1 1 3 5 1 1 4 5 0 1 5 3 1 1 6 5 0 1 7 3 1 2 1 1 1 2 2 4 1 2 3 0 1 4 1 6 1 4 2 2 0 4 3 6 1 4 4 2 0 4 5 3 1 6 1 9 0
Sample Output
Here is the output that should be produced by your program with the above input in your file. The output first gives the number of rows read from the file. (Note that the above file has 19 lines in it). The output then gives the number of the last squirrel in the file (the number of the squirrel on the last line of the file), and prints out the data summary for the squirrels in the file.
Read 19 rows from squirrel data file Last squirrel having data in file: 6 Squirrel Num Trials Unique Sites Food consumed Performance (%) ___________________________________________________________________________ 0 3 2 3 100.0 (3/3) 1 7 4 4 57.1 (4/7) 2 3 3 3 100.0 (3/3) 3 No data for squirrel. 4 5 3 3 60.0 (3/5) 5 No data for squirrel. 6 1 1 0 0.0 (0/1) Press return to exit program
Some Details
1) The numbers on each line in the file can be separated by any number of blanks. A newline should terminate each line.
2) Do not use global variables and do not use global arrays! You may receive multiple points off for using global variables or global arrays. Pass variables and arrays as parameters to functions when you need to have access to the data from these items in your functions.
3) Assume that each collection of data for a particular squirrel# is contiguous in the file. That is, all data for a particular squirrel occurs in a sequence of rows in the file, and once you have started on another squirrel number in the file, the data is completed for that prior squirrel.
4) Use #define'd constants for the dimensions of the array(s) when you declare the arrays and when you are processing the array(s).
5) Assume some constant maximum number of squirrels and also some constant maximum number of trials per squirrel. For example:
#define MAX_NUMBER_SQUIRRELS 20 #define MAX_NUMBER_TRIALS_PER_SQUIRREL 30
6) Assume that the squirrel numbers in the file (the first column of data in the file) are >= 0, and also that the squirrels are consecutively numbered (0, 1, 2, ...). If any squirrel number in the sequence is missing, print a message saying so. For example, if squirrels numbered 0, 1, and 3 are in the file, then print the data summaries for squirrels 0, 1, and 3 and print a message saying no data was present for squirrel number 2.
1) A good method to determine how many different site choices the squirrel made is to use a separate array (different from your data matrix). Each time you find a site number in your current squirrel's site choices, place this site into the array. Start entering these site numbers at 0 in this array. Now, when you get a new site number, first check to see if that site number is in this array of site numbers, and if it is, don't increment your counter that is keeping track of the number of different sites; if it is not, then increment your counter for the number of different sites, and also put that site into your array of site choices that the squirrel has made. Remember to start at the beginning of this site choice array for each different squirrel.
2) While you are free to design your program any way you wish, you must follow good top-down design principles. Make sure you modularize your program using functions. Do not use one large "main" function!! A function to read the file into the matrix would be a good idea. A function to print the summaries of the squirrels given the matrix would also be a good idea. Other functions will be useful too.
3) You should test your programs with small files initially, and gradually work your way up to larger input files. Start with a file containing a single trial for a single squirrel. Then use a file containing a single squirrel, but multiple trials, then use a file containing multiple squirrels but a single trial for each. Etc.
Hand in a lab report with a copy of each of your test data files and the output for each.
EXTRA CREDIT (Only do one of the following, you will not get credits for both)
4 points After doing the other output from your program, also draw a horizontal bar graph giving the performance of each squirrel. Draw the bar's with '*' characters.
8 points After doing the other output from your program, also draw a vertical bar graph for the performance of each squirrel. Draw the bar's with '*' characters.
For example, to draw the bar with these extra credit parts of the assignment, if the squirrel does 100%, output 10 '*' characters. If the squirrel does 90%, output 9 '*' characters etc.