CMSC104 Spring 2014

Programming Project 3

Body Mass Index

Out: Wednesday, May 7

Due: Friday, May 16, before 11:59 p.m.

The Objective

This project is designed to exercise all your C programming knowledge, with emphasis on file I/O, arrays, and functions.

The Background

The Body Mass Index (BMI) is a standard measure of relative weight and is used to classify individuals as underweight, normal, overweight, or obese. The BMI is a simple function of height (inches) and weight (pounds):

bmi = ( weight / height2 ) * 730

A 1993 growth survey in Hong Kong recorded the heights and weights of 25,000 children under the age of 18. The file proj3.dat contains 200 of the 25,000 height and weight records; the first line of the file indicates the number of records (200).

You can download proj3.dat to your Linux account using the following command:

linux3[10]% wget http://userpages.umbc.edu/~cmarron/proj3.dat

Your program must read the data file; compute the BMI for each of the 200 height and weight records; compute some basic statistics for heigh, weight, and BMI; write the statistics to an output file; write the height, weight, and BMI records to the output file.

The Task

Your program must accept the name of the input and output files on the command line, read the data from the input file (proj3.dat), compute the bmi values and statistics, and write the statistics and data to the output file.

Your program must include the functions with the following prototypes:

More Details

Hints

The program grade_stats.c (Lecture 20, sample code) is a good example of how to write this program -- some of the fuctions can even be copied verbatim (mean(), median(), and sort()). The function read_data() is very similar to read_scores() in grade_stats.c. Homework 5 shows you how to read the data size from the first line of the input file and the use of a defined constant to specify the maximum number of data lines.

Sample Output

linux3[1]% gcc -ansi -Wall proj3.c

linux3[2]% ./a.out proj3.dat proj3.report

linux3[3]% cat proj3.report

	BMI Calculator Report

	Height
		mean = 67.95	median = 67.93

	Weight
		mean = 127.22	median = 127.88

	BMI
		mean = 20.10	median = 20.01

	Height	Weight	BMI
	65.78	112.99	19.06
	71.52	136.49	19.48
	69.40	153.03	23.19
	68.22	142.34	22.33
	67.79	144.30	22.92
	68.70	123.30	19.07
	69.80	141.49	21.20
	70.01	136.46	20.32
	67.90	112.37	17.79
	66.78	120.67	19.75

        [...190 lines omitted...]

linux3[4]% ./a.out file_does_not_exist proj3.report
Error - unable to open input file.

linux3[5]% ./a.out only_one_file
Error - incorrect command line arguments.

Submitting the Program

Here is a sample submission command:

linux3[4]% submit cmsc104_cmarron proj3 proj3.c

To verify that your project was submitted, you can execute the following command at the Unix prompt. It will show the file that you submitted in a format similar to the Unix ls command.

linux3[5]% submitls cmsc104_cmarron proj3