2023-05-04 23:55:11 +02:00
|
|
|
---
|
2023-05-07 20:50:52 +02:00
|
|
|
slug: cams
|
2023-05-04 23:55:11 +02:00
|
|
|
title: Practice exam C
|
|
|
|
description: |
|
|
|
|
Stalking cars…
|
2023-08-15 17:27:16 +02:00
|
|
|
last_update:
|
|
|
|
date: 2023-05-07
|
2023-05-04 23:55:11 +02:00
|
|
|
---
|
|
|
|
|
|
|
|
# Watching Cams
|
|
|
|
|
|
|
|
:::caution Exam environment
|
|
|
|
|
2023-11-24 16:00:45 +01:00
|
|
|
- During the exam you will be provided with a barebone _exam session_ on the
|
2023-05-04 23:55:11 +02:00
|
|
|
_faculty computers_.
|
2023-11-24 16:00:45 +01:00
|
|
|
- In browser you are only allowed to have the following tabs open:
|
|
|
|
- [C documentation](https://en.cppreference.com)
|
|
|
|
- page containing the assignment
|
|
|
|
- You **are not** allowed to use your own source code, e.g. prepared beforehand
|
2023-05-04 23:55:11 +02:00
|
|
|
or from the seminars.
|
2023-11-24 16:00:45 +01:00
|
|
|
- You have **5 minutes** to read through the assignment and ask any follow-up
|
2023-05-04 23:55:11 +02:00
|
|
|
questions should be there something unclear.
|
2023-11-24 16:00:45 +01:00
|
|
|
- You have **60 minutes** to work on the assignment, afterward your work will be
|
2023-05-04 23:55:11 +02:00
|
|
|
discussed with your seminar tutor.
|
|
|
|
|
|
|
|
:::
|
|
|
|
|
|
|
|
Your task is to write a program `cams` that will be processing input from the
|
|
|
|
cams that are capable of identifying license plates on the cars and then
|
2023-05-07 20:50:52 +02:00
|
|
|
print out summary based on the input data. Your contributions to the society are
|
2023-05-04 23:55:11 +02:00
|
|
|
very much appreciated and may (or may not) be used for (each or none) of the
|
2023-05-07 20:50:52 +02:00
|
|
|
following purposes[^1]:
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-11-24 16:00:45 +01:00
|
|
|
- stalking people leaving and coming back home,
|
|
|
|
- retroactively making people pay for the parking,
|
|
|
|
- providing evidence of people speeding on highways,
|
|
|
|
- tracking people that don't pay tolls, or
|
|
|
|
- convict employees leaving the work prematurely.
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
## Format of the input file
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
Input for your program consists of the data from the cameras. You will be given
|
|
|
|
the data from the cameras as a path to a file and user should also be able to
|
|
|
|
specify `-` (i.e. `stdin`) as the path.
|
2023-05-04 23:55:11 +02:00
|
|
|
|
|
|
|
Each “scan” (i.e. reading) of the cameras consists of the following data:
|
|
|
|
|
2023-11-24 16:00:45 +01:00
|
|
|
- _camera ID_: non-negative integer identifying a camera
|
|
|
|
- _plate_: string of unknown length that can consist of any characters apart
|
2023-05-04 23:55:11 +02:00
|
|
|
from whitespace
|
2023-11-24 16:00:45 +01:00
|
|
|
- _timestamp_: date and time of the scan as an unsigned integer (represented as
|
2023-05-07 20:50:52 +02:00
|
|
|
a UNIX time)
|
2023-05-04 23:55:11 +02:00
|
|
|
|
|
|
|
:::tip
|
|
|
|
|
|
|
|
When programming on UN\*X(-like) systems, you can assume that the `time_t`
|
|
|
|
structure from the system header `time.h` **is** the `unsigned int` that you
|
|
|
|
are provided in the input file.
|
|
|
|
|
|
|
|
:::
|
|
|
|
|
|
|
|
And they are compiled into one reading such as:
|
|
|
|
|
|
|
|
camera_ID: plate timestamp
|
|
|
|
|
|
|
|
There should be always **at least one** space in between each part of the
|
2023-05-07 20:50:52 +02:00
|
|
|
reading. Readings are separated by the commas, which may, but don't have to, be
|
2023-05-04 23:55:11 +02:00
|
|
|
accompanied by whitespace around.
|
|
|
|
|
|
|
|
#### Examples
|
|
|
|
|
|
|
|
Few examples of the data from the cameras follow
|
|
|
|
|
|
|
|
```
|
|
|
|
10: ABC-12-34 1664608712, 289: XYZ-98-76 1665416417,
|
|
|
|
25: ABC-12-34 1633078256 , 42: TryToCatchMe 1671602419,
|
|
|
|
11: EL9-987 1679541338 ,2 : Foo-666 1683170082,42: YourMum 1683170082,
|
|
|
|
42: TryToCatchMe 1671602419 , 1234: TryToCatchMe 1671602419,
|
|
|
|
19: ABC-12-34 1664659649, 69:YouShould-not-pLaCe-4ny-expectations%on^the(input 1680307994,
|
2023-05-07 20:50:52 +02:00
|
|
|
9 : 9B9-161 1665416417 , 10: 1a1-999 1671602419,1:lmao 1633078256,
|
|
|
|
16: ABC-12-34 1664609012
|
2023-05-04 23:55:11 +02:00
|
|
|
```
|
|
|
|
|
|
|
|
## Format of the output
|
|
|
|
|
|
|
|
:::info
|
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
All the examples consider using data from the example of the input.
|
2023-05-04 23:55:11 +02:00
|
|
|
|
|
|
|
:::
|
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
You are expected to print out the dates and cameras that has captured the
|
|
|
|
license plate for each of them (in a sorted fashion).
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
If there are multiple scans present and the timespan (i.e. time difference
|
|
|
|
between the scans is bigger than 60 minutes, you should separate them by a
|
|
|
|
newline). For example:
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
```
|
|
|
|
*** ABC-12-34 ***
|
|
|
|
25: Fri Oct 1 10:50:56 2021
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
10: Sat Oct 1 09:18:32 2022
|
|
|
|
16: Sat Oct 1 09:23:32 2022
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
19: Sat Oct 1 23:27:29 2022
|
|
|
|
```
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
:::tip
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
Since you are given the timestamp in a `time_t` compatible type on UN\*X, you
|
|
|
|
can safely use `ctime(3)` for printing the timestamp as a _human readable_ time
|
|
|
|
when outputting the date and time.
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
:::
|
2023-05-04 23:55:11 +02:00
|
|
|
|
|
|
|
:::tip
|
|
|
|
|
|
|
|
For a better readability you can include one more newline after the last line
|
|
|
|
of the output.
|
|
|
|
|
|
|
|
:::
|
|
|
|
|
|
|
|
## Example usage
|
|
|
|
|
|
|
|
You can also have a look at example usage of your program. We can run your
|
|
|
|
program from the shell like
|
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
$ ./cams example_1.txt
|
2023-05-04 23:55:11 +02:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
And it will produce an output:
|
2023-05-04 23:55:11 +02:00
|
|
|
|
|
|
|
*** ABC-12-34 ***
|
|
|
|
25: Fri Oct 1 10:50:56 2021
|
2023-11-24 16:00:45 +01:00
|
|
|
|
2023-05-04 23:55:11 +02:00
|
|
|
10: Sat Oct 1 09:18:32 2022
|
2023-05-07 20:50:52 +02:00
|
|
|
16: Sat Oct 1 09:23:32 2022
|
2023-11-24 16:00:45 +01:00
|
|
|
|
2023-05-04 23:55:11 +02:00
|
|
|
19: Sat Oct 1 23:27:29 2022
|
2023-11-24 16:00:45 +01:00
|
|
|
|
2023-05-04 23:55:11 +02:00
|
|
|
*** EL9-987 ***
|
|
|
|
11: Thu Mar 23 04:15:38 2023
|
2023-11-24 16:00:45 +01:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
*** Foo-666 ***
|
|
|
|
2: Thu May 4 05:14:42 2023
|
2023-11-24 16:00:45 +01:00
|
|
|
|
2023-05-04 23:55:11 +02:00
|
|
|
*** TryToCatchMe ***
|
|
|
|
42: Wed Dec 21 07:00:19 2022
|
|
|
|
42: Wed Dec 21 07:00:19 2022
|
|
|
|
1234: Wed Dec 21 07:00:19 2022
|
2023-11-24 16:00:45 +01:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
*** XYZ-98-76 ***
|
|
|
|
289: Mon Oct 10 17:40:17 2022
|
2023-11-24 16:00:45 +01:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
*** YouShould-not-pLaCe-4ny-expectations%on^the(input ***
|
|
|
|
69: Sat Apr 1 02:13:14 2023
|
2023-11-24 16:00:45 +01:00
|
|
|
|
2023-05-07 20:50:52 +02:00
|
|
|
*** YourMum ***
|
|
|
|
42: Thu May 4 05:14:42 2023
|
2023-05-04 23:55:11 +02:00
|
|
|
|
|
|
|
## Requirements and notes
|
|
|
|
|
2023-11-24 16:00:45 +01:00
|
|
|
- Define **structures** (and **enumerations**, if applicable) for the parsed
|
2023-05-04 23:55:11 +02:00
|
|
|
information from the files.
|
2023-11-24 16:00:45 +01:00
|
|
|
- For keeping the “records”, use some **dynamic** data structure.
|
|
|
|
- Don't forget to consider pros and cons of using _specific_ data structures
|
2023-05-04 23:55:11 +02:00
|
|
|
before going through implementing.
|
2023-11-24 16:00:45 +01:00
|
|
|
- You **are not required** to produce 1:1 output to the provided examples, they
|
2023-05-04 23:55:11 +02:00
|
|
|
are just a hint to not waste your time tinkering with a user experience.
|
2023-11-24 16:00:45 +01:00
|
|
|
- If any of the operations on the input files should fail,
|
2023-05-04 23:55:11 +02:00
|
|
|
**you are expected to** handle the situation _accordingly_.
|
2023-11-24 16:00:45 +01:00
|
|
|
- Failures of any other common functions (e.g. functions used for memory
|
2023-05-04 23:55:11 +02:00
|
|
|
management) should be handled in **the same way** as they were in the
|
|
|
|
homeworks and seminars.
|
2023-11-24 16:00:45 +01:00
|
|
|
- Your program **must free** all the resources before exiting.
|
2023-05-07 20:50:52 +02:00
|
|
|
|
|
|
|
[^1]: Subject to NDA.
|