**I. 142.** The file `I142in.txt` contains a few thousand words of length between 5 and 8 characters, one word per line. No two words have the same number of letters of each kind.

The file `I142rnd.txt` contains 10 words from the previous file, separated by spaces, but with letters of each word arranged in a random order.

Prepare your program to unscramble the words in the file `I142rnd.txt`. The output file `I142out.txt` should contain the 10 original words separated by spaces. The file names are fixed, so the program is run without parameters. The data, the program and the output files are (and should be) stored in the same folder.

The source code and an appropriate documentation should be submitted.

(10 points)

**I. 143.** The spread of an epidemic in a city of population 0<*V*<1 million is modelled. The following is known about affected people:

- the latency period is 0<*L*<15 days during which infected people are asymptomatic and do their daily routine work

- infected but still asymptomatic people meet other people, so each infected person infects 0<*F*<10 other people each day on the average, who should be considered infected from the next day

- after the latency period, each infected person stays at home for 0<*B*<15 days and avoids contact with others

- once a patient is recovered, he or she begins working again, but can not infect others and can not be infected in the future

- the epidemic originated from a single person, entering the city on the first day of the latency period (that is, he or she was infected on the previous day)

- sooner or later everyone in the city gets infected. The epidemic ends when everyone is recovered.

Prepare your spreadsheet with input parameters *V*, *L*, *B* and *F *

- giving the number of days (*J*) the epidemic lasted

- giving on which day (*O*) the city had the maximum number of infected people, and how many of them (*H*) stayed at home then

- plotting the number of latent, ill and recovered people, in the same diagram, from the outbreak to the end of the epidemic.

The spreadsheet in default format and with default extension (*e.g.* `i143.xls`, `i143.xsc`, ...) should be submitted.

One of the sheets should contain

- the names and modifiable values of the parameters of the epidemic in cells `A1:B4 `

- the answers to the questions above in cells `C1:D3 `

- other cells should contain the actual computations.

Another sheet should contain a diagram showing the evolution of the epidemic.

(10 points)

**S. 21.** The motion of a billiard ball (*i.e.* a point mass with completely elastic collisions) is studied. The ball moves on a rectangular table with some polygons blocking its way. The ball starts from a given boundary point of the table with a given initial velocity and moves along a straight line until it touches a side or a vertex of a polygon. Upon collision with a side, the velocity component perpendicular to the side changes sign. Collisions with a vertex are considered as if the ball collided with both sides meeting at the vertex. The simulation ends when the ball hits a side of the table.

The input text file of the program contains the coordinates of the table and the polygons. The first line of the file determines the sides of the table, the second line contains the initial position and velocity of the ball, while every other line describes the integer coordinates of the polygons. The input file does not contain empty lines or other data. All coordinates are integers between -1000 and 1000.

*Example:* the sides of the table are lines *x*=-200, *x*=+100, *y*=-150, *y*=300, hence the first line of the input file is `-200 100 -150 300` (integers separated by spaces). The initial position of the ball is (-200,0) with velocity vector (5,12), so the second line of the input file contains numbers `-200 0 5 12`.

The table contains a triangle with coordinates (-20,50), (0,-40) and (50,30), so one further line of the input file is `-20 50 0 -40 50 30`. The sides of polygons are formed by connecting subsequent vertices. The polygon is closed by connecting the last vertex with the first one.

The name of the input file is read from the standard input, so we start the program, for example, by typing `S21 input.txt`. Your program should graphically display the path of the ball and give the coordinates of the point where it first hits the boundary of the table.

The source code of your program (`S21.pas`, `S21.cpp`, and a short documentation `S21.txt` should be submitted.

(10 points)