LabAssignment7B V2
LabAssignment7B V2
Lab Assignment 7
Lab Instructions
printf("==========================================\n");
printf("==========================================\n");
3. During the lab, you are allowed to ask for help from one of our TAs and Instructors.
4. You can discuss the tasks with your classmates and friends during the lab, but you are NOT
allowed to do the tasks instead of each other.
5. During the lab you are not allowed to work on anything else. Don’t disturb others!
6. The deadline for submission is October 20, Thursday, at 10:00 pm.
Lab Exercises
1. Movies search. Given movies list in different cinemas (at most 5 cinemas). Each list represents a
struct array, each structure of it includes a movie name (for simplicity a movie name is given
without whitespaces and with a length of at most 25 symbols), time of the movie (for simplicity
we assume time to be an integer in the range from 0 to 100). The user enters a movie name and
the algorithm should find an appropriate availability of the given movie in all the cinemas. The
movie list contains at most 5 movies. The user inputs the number of movies M and the number
of cinemas C in the main function. It should match the file contents, i.e. in the file number of
movies will be exactly equal to M and the number of cinemas to C. The input data should be read
from a file that should include a list of movies in the following format (see Figure 1):
The only libraries you can use are stdio.h and string.h. From string.h you can only use the strlen()
function. You are not allowed to use global variables.
CinemaName
Implement 4 functions, where for each function you can use up to 4 parameters:
1) Display all movies that will start after a certain date. The input parameter should be a date
(integer value in the range from 0 to 100). You should display movie names, dates and prices with
already applied discounts.
2) Compare two character arrays, and return true if they are identical and false otherwise. For
this purpose, you can use strlen() function from string.h library.
3) Search for the cheapest ticket price with a discount for the given movie.
4) Display all cinemas, their movies, dates, and prices with already applied discounts.
Test each function on at least 3 different inputs in the main function of the C program, exception
for function 3, you can test it only once.
2. Circles and points. Given an array of points Pts on a 2D plane, where each point represents a
structure of the following type:
typedef struct {
char label;
double x;
double y;
} Point ;
a) Open file points.txt , provided on Moodle. Read the coordinates for the points into some
temporary variables and count the number of points.
b) Close the file and create the array of Points for the amount you just counted.
c) Reopen the file and read the coordinates for the points into the array of Points.
d) Write a function to find a point x that has the most points located exactly at the distance
of the radius of R from the given point x.
The function may accept up to 4 arguments, among which you should have an array of points
(1), the size of that array (2), the radius R (3), and the last parameter is up to your choice,
which can be omitted.
The function should return the label of the found point. You can use sqrt and pow from
math.h library.
Figure 2. Example of an array of points and the radius (1) for points A and D.
In figure 2, the point that has the most points at the distance of the exact radius of 1 is point
D. In case of multiple possible correct points, you can show any of the correct points.
To receive credit for this lab exercise, you should submit the solution to these problems to Moodle
before the deadline. However, you can also demonstrate your solutions during the lab whenever you
finished and submit to Moodle. You also will have some extra (2) hours after the lab session to finish
and submit your work as a .c file to Moodle. Do not wait until the last minute!