Homework 2, Some Easy Stats.

Short Description:

Write a program which will compute simple statistics about the contents of a file.

This assignment is worth 30 points.

Goals

When you finish this homework, you should have:

Formal Description

Write a program which will compute some simple statistics on a number of different types of files.

The program should start by prompting the user for the name of the master file.This prompt should be Enter the name of the master file => with a space after the >. The program should read the file name and attempt to open the file. If the program fails to open the file, it should produce the error message Error: Unable to open the master file filename. and exit.

Enter the name of the master file => nofile.txt

Error: Unable to open the master file nofile.txt.
In the above example, nofile.txt does not exist, so the program produced an error message and exited. The blank line between the prompt and the output is produced by inserting an endl into the stream after the user provides input.

If the program successfully opens the master file, you program should process the commands stored in this file. These commands consist of three parts, a file name, a type, and an operation. The following is an example of a command. The file is intfile.dat, the type is integer and the operation is s.

intfile.dat integer s

For each line in the command file, the program should open the file and process the data of the given type with the operation listed.

The types of data supported are integer and string. For integer types use the c++ type long. A string is defined as a set of characters on a line. These characters are terminated by a newline character (\n). All data in the file will match the given type.

The operations are:
OperationName Type Action
cCount AnyCount the number of items in the file.
xMax AnyFind the maximum value in the file.
nMin AnyFind the minimum value in the file.
aAverage IntegerFind the average value. Print as a float to three decimal places.
sSum IntegerFind the sum of all values in the file.
lLongest StringFind the longest string in the file. If multiple strings are the same length, report the first encountered.
tShortest String Find the shortest string in the file. If multiple strings are the same length, report the first encountered.

For each command, perform the following tasks:

  1. Attempt to open the file.
  2. Read the data from the file and compute the required statistic.

The commands in the master file should be processed as independent operations. Do not attempt to store the data across commands. Other than the errors noted in the above description, there will be no errors in the format or values of the data as specified.

Test Files

The following files can be used for testing.

Other Requirements

Required Files

A single tar file containing the source code and makefile for this program. Your tar file should not contain executable code (hw1) or any object files (*.o).

To create tar file, follow the Working with the Tape Archive Utiltiy (tar)

Submission

Email your tar file as an attachment to dbennett@edinboro.edu. Make sure that the title indicates that this is homework 2 and that your name and section are included in the body of the message.