This assignment is worth 30 points.
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:
Operation | Name | Type | Action |
---|---|---|---|
c | Count | Any | Count the number of items in the file. |
x | Max | Any | Find the maximum value in the file. |
n | Min | Any | Find the minimum value in the file. |
a | Average | Integer | Find the average value. Print as a float to three decimal places. |
s | Sum | Integer | Find the sum of all values in the file. |
l | Longest | String | Find the longest string in the file. If multiple strings are the same length, report the first encountered. |
t | Shortest | 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:
Error: Could not open data file badfile.missing.
Error: File contains no data.
Error: Unknown type float.
Error: Unknown command q.
Max: 5
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.
-g -O3 -Wpedantic -Wall -Wextra -Wmisleading-indentation -Wunused -Wuninitialized -Wshadow -Wconversion
To create tar file, follow the Working with the Tape Archive Utiltiy (tar)