EECS 2031 Software Tools, Winter 2014
Lab 7b (closed in labtest mode), for Tuesday section
Cellphones and other electronic devices must be off while you are in the lab.
Background Scenario
This lab uses the same bathroom scale data transmission scenario as lab2 to lab6.
In this lab, you are building a solution relative to lab5.
However, this time you have to adapt your solution to enable a command to delete
all records for a given user ID.
Moreover, you have to handle time stamps that are given in an minute/second format
In the following and for ease of reading, the changes relative to lab5
have been marked below with '***'.
As before, each line of input contains the following information:
timestamp userID weight
There are one more space characters separating the three pieces of information, except that
the userID itself may now contain one or more spaces (as in "1000 John Jack Smith 123.45").
The fields are defined as follows:
- The timestamp is an integer with the number of seconds since 00:00, Jan 1, 1970 UTC,
which conforms to the standard specification of time in Unix/Linux systems.
*** If the timestamp is directly (without space) followed by an lowercase 'm', the number before it specifies a number of minutes. Moreover, if the 'm' is again directly (without space) followed by another number, this timestamp specifies both minutes and seconds. ***
- The userID is a string, which may contain spaces.
- The weight as a floating point number, specified to mean the weight in kilograms.
This protocol can be parsed deterministically,
as the weight is the first numeric field after a sequence of text fields, e.g. as in
timestamp userIDa userIDb userIDc userIDd weight and none of the parts of
the userID can start with a digit or '.'.
Objective
- Write an ANSI-C program called lab7b.c that reads lines from standard input,
parses them, and classifies the input according to the context set out above and the requirements
specified below.
- Test that your program correctly implements the required functionality
- Finally, submit your solution electronically before the end of
the lab test using the command
submit 2031 lab7b lab7b.c
- You may submit your solution more than once. Additional documentation about the submit
command can be viewed by typing man submit.
Now create a new ANSI-C program that does the following.
Requirements
Your program must the input read line by line from standard input.
- If the timestamp field is missing, is not an integer, or is zero,
you must print Invalid time, followed by a newline character.
- The userID consists of a sequence of text strings each of which cannot start with a
digit or '.' character.
If the userID is missing, or if the userID is longer than 179 characters (including single spaces in between the parts of the userID), you must print
Illegal userID, followed by a newline character.
- If the weight field is missing, or is less than 30.0 or more than 300.0 kilograms,
you must print Illegal weight, followed by a newline character.
- *** If the timestamp is a negative number, you must delete all records for the userID
given in that line of input and print the confirmation Deleted user followed
by a newline character.
- If the timestamp of a record not larger than the previous timestamp,
i.e., the current is in the past relative to the previous one or identical to it,
you must print Nonmonotonic timestamps, followed by a newline character.
- Additional text on the line after the last field should be silently ignored.
- If there are multiple problems with the line of input, you must print only
the message for the first field that does not follow the specification. Processing should
then continue with the next line. All rules need to be applied in the order specified here.
- Data from lines that pass all above criteria are considered valid records.
-
If the information supplied in each line is otherwise fine,
and the userID is new, i.e., has not been seen before, you must print OK newuser
followed by a newline character.
Different amounts of whitespace
between the parts of a userID should be ignored in the test for equality of userID's.
- Otherwise, the userID has been seen before.
If the weight change between the current record and the most recent valid record
for the same userID exceeds 10 kg/day,
you must print Suspiciously large weight change, followed by a newline character.
Otherwise, you must print OK, followed by a newline character.
-
When the processing reaches the end of the input, i.e., upon EOF, the program
must output a bar chart, using ASCII characters.
This bar chart must contain vertical and horizontal axes drawn with '|' and '-' characters,
respectively. The origin must be represented as a '+' character.
The "length" of the horizontal dimension needs to match the amount of data that can be shown,
as specified below.
The bar chart must always be 10 lines "high" (plus the line for the horizontal axis).
-
The bar chart must show the change of weight over time for the userID with the last valid record.
For this, you must scale the information so that
30kg and 300kg are represented by 1 and 10 '*' characters respectively as vertical bars.
You must truncate weight values, i.e., a weight of 59.999kg will still yield only a single star.
To simplify the lab, the time dimension on the horizontal axis must correspond only
to the sequence of weight records, and must not be spaced according to the time stamps themselves.
Thus, each record should be respresented by a single character in the horizontal dimension.
-
You are required to use a dynamically allocated 2D array for your solution.
- No other output must be produced.
For the purpose of this lab, you do not need to worry about numeric overflow. In other words, you
can safely assume that timestamps are guaranteed to fit in 32 bit integers, and floating point numbers will fit into a ANSI-C float variable.
You can also safely assume that there is always at least one (or more) space characters
between the fields and between each part of the userID.
***
You can also safely assume that there will not be records with equal time stamps.
Here is an example input, also provided as a file, input.txt.
3600 godzilla's kid 30.0
36000 godzilla 299
-1 godzilla's kid 30.0
36001 godzilla's kid 30.1
600m2 godzilla's kid 30.2
46002 godzilla's kid 30.1
46999 godzilla 30.1
60000 john jack andrew wolfgang jiang rami tom bob robert frank richa
rd smith 123.5
500000 godzilla's kid 60
1000000 godzilla's kid 100
3000000 godzilla's kid 300
5000000 godzilla's kid 89
If you start your program with this, you should get the following output, also provided as
a file, expectedoutput.txt.
OK newuser
OK newuser
Deleted user
OK newuser
Suspiciously large weight change
OK
Suspiciously large weight change
OK newuser
OK
OK
OK
OK
| *
| *
| *
| *
| *
| *
| *
| **
| ****
|*******
+-------
Hints:
-
- The scanf() family of functions parses the input line according to the sequence
of format specifiers in the format string. E.g., a string of "%dy%d" will match "123y123"
as expected. The scanf function can also read single characters via
a "%c" format specifier.
- It is usually easier to address each individual requirement to your code only after
you have verified that the previous requirement is met by your program.
- Many of the test cases for previous labs are still valid for the lab.
You can use those test cases to test if your submission deals correctly with the
unchanged aspects of the specification.
Additional hints:
- Make sure that you handle the cases of deleting a record at the beginning of the list,
in the middle, as well as at the end correctly.