Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C programming for a parking manager. I need help fixing and finishing my program with the following function: (thanks for the help) vehicle* allocVehicle (char*

C programming for a parking manager.

I need help fixing and finishing my program with the following function: (thanks for the help)

image text in transcribedimage text in transcribedimage text in transcribed

vehicle* allocVehicle(char* model, char* plate, VType type, double curFuel, double maxFuel ) - dynamically allocates space to store one vehicle record with the given model, plate, type, curFuel and maxFuel then initialize all its values sensibly (note: this function does not assign the vehicle a parking stall)

int deallocVehicle(vehicle* v) - deletes the given vehicle from the system and free up any allocated space that vehicles record was using

int assignStall(vehicle* v, int x, int y) - assigns the given vehicle the parking stall with the coor- dinates (x,y)

******************************************************************************************************************

/* Vehicle parking program */

//Parking Manager//

#include

#include

#include

#define CAR 1

#define TRUCK 2

#define SUV 3

/* to store vehicle number, and its

row-col position in an array */

struct vehicle

{

int num ;

int row ;

int col ;

int type ;

} ;

int parkinfo[6][10] ; /umber of vehicle parked

int vehcount ; // total vehicle parked

int carcount ; // total cars

int truckcount ; /* total trucks */

int suvcount ; /* total suv*/

void display( ) ;

void changecol ( struct vehicle * ) ; // no need

struct vehicle * allocVehicle( int, int, int, int ) ;

void deallocVehicle ( struct vehicle * ) ; //int deallocVehicle(vehicle* v);

void getfreerowcol ( int, int * ) ;

void getrcbyinfo ( int, int, int * ) ;

void show( ) ;

/* decrements the col. number by one

this fun. is called when the data is

shifted one place to left */

void changecol ( struct vehicle *v )

{

v -> col = v -> col - 1 ;

}

/* adds a data of vehicle */

struct vehicle* allocVehicle ( int t, int num, int row, int col )

{

struct vehicle *v ;

v = ( struct vehicle * ) malloc ( sizeof ( struct vehicle ) ) ;

v -> type = t ;

v -> row = row ;

v -> col = col ;

if ( t == CAR )

carcount++ ;

else if(t == TRUCK)

truckcount++ ;

else

suvcount++ ;

vehcount++ ;

parkinfo[row][col] = num ;

return v ;

}

/* deletes the data of the specified

car from the array, if found */

void deallocVehicle( struct vehicle *v )

{

int c ;

for ( c = v -> col ; c

parkinfo[v -> row][c] = parkinfo[v -> row][c+1] ;

parkinfo[v -> row][c] = 0 ;

if ( v -> type == CAR )

carcount-- ;

else if ( v -> type == TRUCK)

truckcount-- ;

else

suvcount-- ;

vehcount-- ;

}

/* get the row-col position for the vehicle to be parked */

void getfreerowcol ( int type, int *arr )

{

int r, c, fromrow = 0, torow = 2 ;

if ( type == TRUCK )

{

fromrow += 2 ;

torow += 2 ;

}

if(type == SUV)

{

fromrow += 4 ;

torow += 4 ;

}

for ( r = fromrow ; r

{

for ( c = 0 ; c

{

if ( parkinfo[r][c] == 0 )

{

arr[0] = r ;

arr[1] = c ;

return ;

}

}

}

if ( r == 2 || r == 4 )

{

arr[0] = -1 ;

arr[1] = -1 ;

}

}

/* get the row-col position for the vehicle with specified number */

void getrcbyinfo ( int type, int num, int *arr )

{

int r, c, fromrow = 0, torow = 2 ;

if ( type == TRUCK )

{

fromrow += 2 ;

torow += 2 ;

}

if(type == SUV)

{

fromrow += 4 ;

torow += 4 ;

}

for ( r = fromrow ; r

{

for ( c = 0 ; c

{

if ( parkinfo[r][c] == num )

{

arr[0] = r ;

arr[1] = c ;

return ;

}

}

}

if ( r == 2 || r == 4 )

{

arr[0] = -1 ;

arr[1] = -1 ;

}

}

/* displays list of vehicles parked */

void display( )

{

int r, c ;

printf ( "\xdb\xdb Cars => " ) ;

for ( r = 0 ; r

{

if ( r == 2 )

printf ( "\xdb\xdbTrucks => " ) ;

if ( r == 4)

printf( "\xdb\xdbSUVs => ");

for ( c = 0 ; c

printf ( "%d\t", parkinfo[r][c] ) ;

printf ( " " ) ;

}

}

???? ng Manager is an application used to track the rovement of vehicles within a single parking garage You could imagine that this application was commissioned by a customer looking for a more efficient way to manage their parking garages. Below are some clarifying statements regarding Parking Manager to help you better understand the requirements All information stored in Parking Manager will be 'volatile" - meaning that all data stored is lost when the program terminates. By consequence, every time the program starts, the user begins with an empty parking garage. . For simplicity, the parking garage being modeled will be in the shape of a rectangle and stalls will be organized as a grid. You should use a 2D array to model the parking garage. . Parking Manager will only be responsible for managing one parking garage at a time. The intention is that each parking garage the customer owns will run a separate instance of Parking Manager. The following data is tracked for each vehicle entering the parking garage: vehicle model, licence plate, vehicle type, current fuel level in litres and maximum fuel level in litres . In addition to the data above, you will need a way to track the position of each vehicle within the garage. A vehicle can be one of three types: Car, Truck or SUV. . We can safely assume that every vehicle in the parking garage has been assigned its own parking stall Vehicles are added dynamically by the user - initially there will be no vehicles in the system The maximum number of vehicles which can be stored in the parking garage should be hard-coded in the source code, not determined by the user. When reporting on the current fuel level of a vehicle, you should report it as a percentage. This can be calculated from the current fuel level in litres and the maximun fuel level in litres ???? ng Manager is an application used to track the rovement of vehicles within a single parking garage You could imagine that this application was commissioned by a customer looking for a more efficient way to manage their parking garages. Below are some clarifying statements regarding Parking Manager to help you better understand the requirements All information stored in Parking Manager will be 'volatile" - meaning that all data stored is lost when the program terminates. By consequence, every time the program starts, the user begins with an empty parking garage. . For simplicity, the parking garage being modeled will be in the shape of a rectangle and stalls will be organized as a grid. You should use a 2D array to model the parking garage. . Parking Manager will only be responsible for managing one parking garage at a time. The intention is that each parking garage the customer owns will run a separate instance of Parking Manager. The following data is tracked for each vehicle entering the parking garage: vehicle model, licence plate, vehicle type, current fuel level in litres and maximum fuel level in litres . In addition to the data above, you will need a way to track the position of each vehicle within the garage. A vehicle can be one of three types: Car, Truck or SUV. . We can safely assume that every vehicle in the parking garage has been assigned its own parking stall Vehicles are added dynamically by the user - initially there will be no vehicles in the system The maximum number of vehicles which can be stored in the parking garage should be hard-coded in the source code, not determined by the user. When reporting on the current fuel level of a vehicle, you should report it as a percentage. This can be calculated from the current fuel level in litres and the maximun fuel level in litres

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

3. Evaluate your listeners and tailor your speech to them

Answered: 1 week ago