Академический Документы
Профессиональный Документы
Культура Документы
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.
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.
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.
Use printf and switch case control structure to implement the option.
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.
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.
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.
---------