Homework 1

CS18

40 pts., due Feb. 16

Develop a top-down design and write a program to produce a bar chart of gourmet-popcorn production for a cooperative farm group on a farm-by-farm basis. The input to the program is a series of data sets, one per line, with each set representing the production of one farm. The output is a bar chart that identifies each farm and display its production in pints of corn per acre.

Each data set (stored in a file) consists of the name of a farm, followed by a comma and one or more spaces, a float number representing acres planted, one or more spaces, and an int number representing pint jars of popcorn produced.

The output is a single line for each farm, with the name of the farm starting in the first column on a line and the bar chart starting in column 30. Each mark in the bar chart represents 250 pint jars of popcorn per acre. The production goal for the year is 5,000 jars per acre. A vertical bar should appear in the chart for farms with lower production, and a special mark is used for farms with production greater than or equal to 5,000 jars per acre. For example, given the input file

Orville's Acres,  114.8  43801
Hoffman's Hills,  77.2  36229
Jiffy Quick Farm,  89.4  24812
Jolly Good Plantation,  183.2  104570
Organically Grown Inc.,  45.5  14683
the output would be
                   Pop Co-Op
Farm Name                    Production in
                             Thousands of
                             Pint Jars per Acre
                                1   2   3   4   5   6
                             ---|---|---|---|---|---
Orville's Acres              ***************    |
Hoffman's Hills              *******************|
Jiffy Quick Farm             ***********        |
Jolly Good Plantation        *******************#***
Organically Grown Inc.       *************      |

This problem should decompose neatly into several functions. You should write your program in proper programming style, with plenty of comments and no global variables. It should handle data errors (such as a farm name longer than 29 characters) without crashing.

Turn in a copy of your source code and an example run with the input and output.

(N. Dale, C. Weems, and M. Headington, Programming and Problem Solving with C++, Heath, 1996.)



Thomas P. Kelliher
Thu Feb 8 08:20:09 EST 1996
Tom Kelliher