Вы находитесь на странице: 1из 3

1)

A vehicle park has 20 parking slots. Parking slots are numbered from 0 to 19. Vehicles are parked
first in 0 slot, second in first slot etc until parking slot 19.The car park is full when all slots are
filled. Another vehicle can park to the vacant slot after a vehicle is left. When a vehicle entered to
the vehicle park, vehicle number, vehicle type and in time are recorded.

* Write a C program to record above data when a vehicle entered to the vehicle park and remove
vehicle details when the vehicle left.

When you write the C program, follow the below instructions.


a) Initially, define the global constant parkslot as 20.
b) create a struct called vehicle as follows.

struct vehicle
{
int slot_no;
char v_no[8];
char v_type[12];
float in_time;
};
Where slot_no is slot number fro 0 to 19, v_no is vehicle number, v_type is vehicle type (car, van
etc.), in_time is entered time.

c) create an struct vehicle array called ar_vehicle that has a length of number of parking slots in
main program.

You can use following statement to create ar_vehicle


struct vehicle ar_vehicle[parkslot]; Here parkslot is maximum number of parking slots.

d) initialize the the above vehicle structure slot_no=0, v_no as ””, v_type as ””,in_time=0 in main
program. When initializing char variables use strcpy.
e) add following to the main program to display following options (1 or 2 or 3 or 4) in the terminal
and enter option number as shown in fig.1.

fig. 1. option list

Use printf and switch case control structure to implement the option.

When the option 1 entered (case 1), call function addvehicle.

suc1=addvehicle(ar_vehicle); where input parameter is ar_vehicle and return value assigned to


suc1 Boolean variable. If the suc1 is true print “Vehicle parking OK”, else print " Vehicle parking
not success”.
When the option 2 entered (case 2), call function display_carpark.

display_carpark(ar_vehicle); where input parameter is ar_vehicle.


When the option 3 entered (case 3), call function deletevehicle

suc1=deletevehicle(ar_vehicle); where input parameter is ar_vehicle and return value assigned to


suc1 Boolean variable. If the suc1 is true print “Vehicle left ok”, else print " Vehicle not found”.

When the option 4 entered case default, system should exit to the terminal.

f) Now write the following function to find first empty slot and return slot number of the empty
slot. When the first empty slot is found, return to the main program with the empty slot number. If
vehicle park is full then return -1 value.

int emptyslot(struct vehicle ar_v[])

Input parameter to the function is struct vehicle -array vehicle. In this function, find whether vehicle
no in specified slot_no is zero or not within a for loop. You can use strlen function to check vehicle
no.

g) Now write the following function to enter records when a vehicle entered to the vehicle park.
bool addvehicle(struct vehicle ar_v[])

Input parameter to the function is struct vehicle -array vehicle. In this function, call emptyslot
function to check which slot is empty, then enter details of vehicle to fill the emptyslot. Boolean
return value is “true”, when a vehicle is entered to the parking slot successfully. If the vehicle park
is full, function return “false” value.

First create an integer variable named p_slot and call the function emptyslot and return value should
store in p_slot.
p_slot=emptyslot(ar_v);
Now check the p_slot using if else control statement.
If p_slot=-1
then vehicle park ful, return false
else
input details in to relevant place in array struct
return true

h) call the function addvehicle from the option vehicle IN option list (fig. 1). Give a massage
success if the return value is true else message is not success.

i) write the following function to display all the vehicle park details.

void display_carpark(struct vehicle ar_v[])


There is no output pass to the main program, therefore, return value is void.
Display slot number, vehicle number, vehicle type and in time. If the slot is empty display only slot
number.

This function is called from option 2 in option list in main program.

j) Write a function to delete vehicle details when a vehicle left.


bool deletevehicle(struct vehicle ar_v[])

Return value of this function is Boolean. In this function, user should enter vehicle number and if it
is available in vehicle parking list then remove all details except slot number and return true value.
If the number is not available, then return false value.

k) The function deletevehicle is called from the option list 3 in the main program. Print success if
return value is true and print not success if return value is false.

Note: You may need strcpy and strcmp when you write string functions. Read and practice session
13 and 13.3.3 Structures in C in your text book 1.

---------

Вам также может понравиться