Convert the pseudocode below to a C program to solve the fol

Convert the pseudocode below to a C program to solve the following problem

Jurassic Park consists of a dinosaur museum and a park for safari tiding. There are n passengers and m single-passenger cars. Passengers wander around the museum for a while, then line up to take a ride in a safari car. When a car is available, it loads the one passenger it can hold and rides around the park for a random amount of time. If the m cars are all out riding passenger around, the passenger who wants to ride waits; if a car is ready to load but there are no waiting passengers, then the car waits. Use semaphores to synchronize the n passenger threads/processes and the m car threads/processes.


resource Jurassic_Park()

sem car_avail := 0, car_taken := 0, car_filled := 0, passenger_released := 0
process passenger(i := 1 to num_passengers)
do true -> nap(int(random(1000*wander_time)))
P(car_avail); V(car_taken); P(car_filled)
P(passenger_released)
od
end passenger
process car(j := 1 to num_cars)
do true -> V(car_avail); P(car_taken); V(car_filled)
nap(int(random(1000*ride_time)))
V(passenger_released)
od
end car
end Jurassic_Park

Solution

Input

The input to this program is the total number of safari cars available in the park n (0 n 50). The number of passengers wandering in the museum m (0 m 5000) and the number of passengers q (0 q 100) in the park gate ready to take a ride in the park at time zero. The other inputs are the values of p (1 p 100), r (1 r 100) and k (r k 100000). Note that there can be no negative or fractional inputs.

Input Format

First line contains an integer N (1 N 100) indicating number of test cases. Each of the following N lines contains input data, separated by single space, for different test cases in the given order:

No. of Safari Cars, No. passengers in Museum at time zero, No. of passengers at park gate ready for ride at time zero, p, r, k

Output

The output of this program is the number of cars waiting at the park gate, the number of passengers who have completed taking one ride in the park, the number of passengers still waiting at the park gate to take a ride and the number of passengers still wandering in the museum, respectively, after k units of time.

Output Format

Output for each test case will be on separate lines. Each line will contain:

No. of cars waiting at the park gate, No. of passengers completed the park ride, No. of passengers wandering in the museum, No. of passengers still waiting to take a ride, respectively.
The output parameters should be in the above order with one space gap.

Convert the pseudocode below to a C program to solve the following problem Jurassic Park consists of a dinosaur museum and a park for safari tiding. There are n

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site