# 18 January 2017

# Fondamenti di Informatica - Compito A

### Prof. Marco Gavanelli

### 18 January 2017

## Exercise 1 (16 points)

In the game "bingo", the numbers from 1 to 90 are used; they are drawn randomly in a sequence, and they are announced.

Each player has a card containing a table with 15 numbers.

When a number is announced, each player checks if his table contains such number; if the announced number is present, the player deletes it.

The first player that deletes all his numbers wins the game (it is said that he does "bingo").

You are given

- a text file
`cartella.txt`that contains the data of a card, i.e.,- the name of the player (string containing at most 20 characters, without spaces)
- an array of 15 integer numbers, that are all different and comprised between 1 and 90

- a text file
`estratti.txt`that contains the sequence of the drawn numbers

Write a C program that computes after how many drawn numbers the player does "bingo".

For instance, if the file `cartella.txt` contains

`Calogero 1 3 78 32 5 34 75 23 57 49 32 57 10 73 59`

and the file `estratti.txt` contains

`3 2 5 78 30 15 1 75 44 32 57 10 11 73 59 34 50 23 49 22 23 73 47`...

then the player should print:

```
```Calogero does bingo after 22 numbers have been drawn

because the first 22 numbers of the file `estratti.txt` contain all the numbers in the card.

Organize the program as follows:

- in the
`main`

, call a function that reads the file`cartella.txt`(to be implemented at point 2), one that reads the file`estratti.txt`(to be developed in point 3) and one that computes the number of draws (to be implemented in point 4), finally print the result (in the`main`

) - read the file
`cartella.txt`into a suitable data structure. Show on the screen the content of the structure. - read file
`estratti.txt`into a suitable array. Show on the screen its content. - write the function that computes after how many draws the player does "bingo". to do that it is
**absolutely necessary**to use (and then implement) at least other 2 functions. It is**mandatory**to structure the algorithms into functions in this point, and it is forbidden to develop the whole algorithm in just one function.

It is mandatory to organize the program into functions and procedures; it is highly advisable to add other procedures/functions to those explicitly required in the text.

## Exercise 2 (4 points)

Suppose now that there are more players, each with his own card. The cards are at most 100 and their content is reported in file `cartelle.txt` , where each card is, again, represented as

- the name of the player (string containing at most 20 characters, without spaces)
- an array of 15 integer numbers, that are all different and comprised between 1 and 90

Extend the program in such a way that it shows which player is the first that does "bingo".

Moreover, compute which player does one row as first. One player does one row if

- either the first five numbers of his table have been drawn
- or the second group of 5 numbers (i.e., the elements from the sixth place to the tenth in the card) have been drawn
- or the last group of 5 numbers (i.e., the numbers from the eleventh to the fifteenth in the cart) have been drawn