Vehicle Parking
Vehicle Parking
h>
#include <conio.h>
#define CAR 1
#define SCOOTER 2
Struct vehicle
Int num ;
Int row ;
Int col ;
Int type ;
};
Void display( ) ;
Void show( ) ;
Struct vehicle * add ( int t, int num, int row, int col )
Struct vehicle *v ;
V -> type = t ;
If ( t == CAR )
Carcount++ ;
Else
Scootercount++ ;
Vehcount++ ;
Parkinfo[row][col] = num ;
Return v ;
}
/* deletes the data of the specified
Int c ;
Carcount-- ;
Else
Scootercount-- ;
Vehcount-- ;
If ( type == SCOOTER )
Fromrow += 2 ;
Torow += 2 ;
}
For ( r = fromrow ; r < torow ; r++ )
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 */
If ( type == SCOOTER )
Fromrow += 2 ;
Torow += 2 ;
If ( parkinfo[r][c] == num )
Arr[0] = r ;
Arr[1] = c ;
Return ;
If ( r == 2 || r == 4 )
Arr[0] = -1 ;
Arr[1] = -1 ;
Void display( )
Int r, c ;
If ( r == 2 )
Printf ( “\n” ) ;
Void main( )
Int I, tarr[2] ;
Int finish = 1 ;
Struct vehicle *v ;
Clrscr( ) ;
While ( finish )
Clrscr( ) ;
Printf ( “\nCar Parking\n” ) ;
Switch ( choice )
Case 1 :
Clrscr( ) ;
Type = 0 ;
}
Printf ( “Enter vehicle number: “ ) ;
Row = tarr[0] ;
Col = tarr[1] ;
If ( type == CAR )
Else
Else
If ( type == CAR )
Else
Else
Getch( ) ;
Break ;
Case 2 :
Clrscr( ) ;
Getch( ) ;
Break ;
Case 3 :
Clrscr( ) ;
Getch( ) ;
Break ;
Case 4 :
Clrscr( ) ;
Break ;
Case 5 :
Clrscr( ) ;
Printf ( “Display\n” ) ;
Display( ) ;
Getch( ) ;
Break ;
Case 6 :
Clrscr( ) ;
Printf ( “Departure\n” ) ;
Type = 0 ;
If ( type == CAR )
Car[row][i] = car[row][I + 1] ;
Changecol ( car[row][i] ) ;
Free ( car[row][i] ) ;
Car[row][i] = NULL ;
/* if a vehicle is scooter */
Else
Row = tarr[0] – 2 ;
If ( ! ( row < 0 ) )
Del ( scooter[row][col] ) ;
For ( I = col ; I < 9 ; i++ )
Scooter[row][i] = scooter[row][I + 1] ;
Changecol ( scooter[row][col] ) ;
Scooter[row][i] = NULL ;
Else
If ( type == CAR )
Printf ( “\nInvalid car number, or a car with such number has not been parked
here.\n” ) ;
Else
Printf ( “\nInvalid scooter number, or a scooter with such number has not been parked
here.\n” ) ;
Getch( ) ;
Break ;
Case 7 :
Clrscr( ) ;
{
For ( col = 0 ; col < 10 ; col++ )
Free ( car[row][col] ) ;
Free ( scooter[row+2][col] ) ;
Finish = 0 ;
Break ;