Question: C programming for a parking manager. I need help fixing and finishing my program with the following function: (thanks for the help) void printVehicle (vehicle*
C programming for a parking manager.
I need help fixing and finishing my program with the following function: (thanks for the help)
void printVehicle(vehicle* v) - prints all information about one vehicle void printAllVehicles() - prints all information for all vehicles in the system
void printGarageMap() - prints out a visual representation of the parking garage to the console
******************************************************************************************************************
/* 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] ; //number 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 < 9 ; 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 < torow ; r++ )
{
for ( c = 0 ; c < 10 ; 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 < torow ; r++ )
{
for ( c = 0 ; c < 10 ; 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 < 5 ; r++ )
{
if ( r == 2 )
printf ( "\xdb\xdbTrucks => " ) ;
if ( r == 4)
printf( "\xdb\xdbSUVs => ");
for ( c = 0 ; c < 10 ; c++ )
printf ( "%d\t", parkinfo[r][c] ) ;
printf ( " " ) ;
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
