CProgramming – INTRODUCTION TO SCIENTIFIC AND (Solution)

$ 29.99
Category:

Description

ENGINEERING COMPUTATION Assignment 3
Objective: Finding the best parking slot for the car.
Description
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 nds the safest slot for his Ferrari. Your job is to guide Joey as the best as you can.
Assignment
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 rst 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 lled with 1 if the grid’s xth and yth 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 all cars.
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 di erent locations.
Below is an example run based on this gure:
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
• 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.
Rules
• 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.

Reviews

There are no reviews yet.

Be the first to review “CProgramming – INTRODUCTION TO SCIENTIFIC AND (Solution)”

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