Assignment 3 Finding the best parking slot for the car.


Rate this product

Assignment 3
Objective: Finding the best parking slot for the car.
Joey loves his new Ferrari and he is very careful while driving around the city and
parking in big shopping mall’s parking areas. Whenever he enters into a parking area,
he searches for a slot that is the furthest away from the existing cars. He drives in the
parking area, looks for all the slots occupied by other cars and finds the safest slot for
his Ferrari. Your job is to guide Joey as the best as you can.
Write a C program that will get the size of the parking area, the number of cars parked,
and a sequence of locations occupied by the cars. The user will first input the size of
the parking area such as 20 which represents a 20 x 20 grid. Second, the user will give
the number of cars parked in this area, such as 15 indicating that there are 15 cars
parked in this area. Finally, the user will input each car’s location in X and Y axis, such
as 3 5 indicating that a car is parked at location X=3 and Y=5.
Your program will keep a two dimensional array that represents the grid, and the
array will be filled with 1 if the grid’s x
th and y
th position has a car parked, and 0
otherwise. Then it should calculate each empty slot’s distance to the surrounding
cars, and return the empty slot which has the LARGEST distance to the NEAREST car.
You are required to calculate the distance between two locations using Manhattan
distance (search how it is computed). If there are two locations that can potentially
be the best slots (based on these slots’ distances to the other cars),
Figure 1: A parking area of 5 x 5 in which x indicates the cars parked.
your program should return the one with the smaller X value. If they both have the
same X value, then your program should return the one with the smaller Y value.
Figure 1 represents a parking area of 5 x 5 and the cars parked in different locations.
Below is an example run based on this figure:
Size: 5
Cars: 5
Locations: 3 2
Locations: 5 2
Locations: 5 3
Locations: 4 3
Locations: 2 2
Best Slot Found In: 1 5
• Maximum size of a parking area can be 50 x 50.
• Make sure to properly document your functions (purpose, parameters, etc) as
shown in the class and the slides.
• You need error checking on user input, e.g. the user cannot enter the number
of cars that exceed the limits of the parking area grid. In a parking area of 5 x 5,
a maximum of 25 cars can be parked.
• You also need error checking when there is no available slot in the parking area.
In such a case, the output should be 0 0.
• Your source code le has to have the name assignment3.c .
• Your program will be compiled using the following command on a Linux system.
If it cannot be compiled and linked using this command, it will not be graded
(failed submission).
gcc -std=c99 -Wall -Werror assignment3.c -o assignment3
• Your program will be checked using an automatic checker. Therefore, make
sure you print the messages exactly as given in the example runs.
• Do NOT use any construct that hasn’t been covered in the course before this
week, pointers. Also use no C++ features such as cout and cin.
• Do NOT use any external functions except for printf and scanf.
• Make sure your coding style is proper and consistent. Use the clang-format tool
if necessary. Don’t use any variable names in a language other than English.
• This is an individual assignment. Collaboration in any form is NOT allowed. No
working together, no sharing code in any form including showing code to your
classmates to give them ideas.
• All the code you submit must be your own. Don’t copy/paste any piece of code
from any resource including anything you’ve found on the Internet.
• The assignments will be checked for plagiarism using both automated tools and
manual inspection. Any assignment involving plagiarism and/or infringement of
intellectual property will be not be graded and is subject to further disciplinary


There are no reviews yet.

Be the first to review “Assignment 3 Finding the best parking slot for the car.”

Your email address will not be published. Required fields are marked *

Scroll to Top