C programming for a parking manager. I need help fixing and finishing my program
ID: 3903044 • Letter: C
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* 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 <stdio.h>
#include <conio.h>
#include <windows.h>
#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 ( "ÛÛ Cars => " ) ;
for ( r = 0 ; r < 5 ; r++ )
{
if ( r == 2 )
printf ( "ÛÛTrucks => " ) ;
if ( r == 4)
printf( "ÛÛSUVs => ");
for ( c = 0 ; c < 10 ; c++ )
printf ( "%d ", parkinfo[r][c] ) ;
printf ( " " ) ;
}
}
Explanation / Answer
For void printGarageMap() implementation, you would need to provide a little explanation of how the visual representation should look like.
Hence, for the time being, I am providing the implementation of the first two function. You can update the question later and I will try to answer the third part too.
void printVehicle(vehicle* v) {
printf("The vehicle details are : ");
printf("Vehicle number : %d ", v->num);
printf("Vehicle parking location : [%d, %d] ", v->row, v->col);
printf("Vehicle Type : %d ", v->type);
}
void printAllVehicles() {
for(int i=0; i < 6; i++) {
for(int j=0; j<10; j++) {
if(parkinfo[i][j] != 0){
printVehicle(vehicles[i][j]);
}
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.