0% found this document useful (0 votes)
10 views

Vehicle Parking

vehical parking msbte project

Uploaded by

girish desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Vehicle Parking

vehical parking msbte project

Uploaded by

girish desai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

#include <stdio.

h>

#include <conio.h>

#define CAR 1

#define SCOOTER 2

/* to store vehicle number, and its

Row-col position in an array */

Struct vehicle

Int num ;

Int row ;

Int col ;

Int type ;

};

Int parkinfo[4][10] ; /* a 2-D array to store number of vehicle parked */

Int vehcount ; /* to store total count of vehicles */

Int carcount ; /* stores total count of cars */

Int scootercount ; /* stores total count of scooters */

Void display( ) ;

Void changecol ( struct vehicle * ) ;

Struct vehicle * add ( int, int, int, int ) ;

Void del ( struct vehicle * ) ;

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 * add ( 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

Scootercount++ ;

Vehcount++ ;

Parkinfo[row][col] = num ;

Return v ;

}
/* deletes the data of the specified

Car from the array, if found */

Void del ( 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

Scootercount-- ;

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 == SCOOTER )

Fromrow += 2 ;

Torow += 2 ;

}
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 == SCOOTER )

Fromrow += 2 ;
Torow += 2 ;

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 ->\n” ) ;


For ( r = 0 ; r < 4 ; r++ )

If ( r == 2 )

Printf ( “Scooters ->\n” ) ;

For ( c = 0 ; c < 10 ; c++ )

Printf ( “%d\t”, parkinfo[r][c] ) ;

Printf ( “\n” ) ;

Void main( )

Int choice, type, number, row = 0, col = 0 ;

Int I, tarr[2] ;

Int finish = 1 ;

Struct vehicle *v ;

/* creates a 2-D array of car and scooter class */

Struct vehicle *car[2][10] ;

Struct vehicle *scooter[2][10] ;

Clrscr( ) ;

/* displays menu and calls corresponding functions */

While ( finish )

Clrscr( ) ;
Printf ( “\nCar Parking\n” ) ;

Printf ( “1. Arrival of a vehicle\n” ) ;

Printf ( “2. Total no. of vehicles parked\n” ) ;

Printf ( “3. Total no. of cars parked\n” ) ;

Printf ( “4. Total no. of scooters parked\n” ) ;

Printf ( “5. Display order in which vehicles are parked\n” ) ;

Printf ( “6. Departure of vehicle\n” ) ;

Printf ( “7. Exit\n” ) ;

Scanf ( “%d”, &choice ) ;

Switch ( choice )

Case 1 :

Clrscr( ) ;

Printf ( “\nAdd: \n” ) ;

Type = 0 ;

/* check for vehicle type */

While ( type != CAR && type != SCOOTER )

Printf ( “Enter vehicle type (1 for Car / 2 for Scooter ): \n” ) ;

Scanf ( “%d”, &type ) ;

If ( type != CAR && type != SCOOTER )

Printf ( “\nInvalid vehicle type.\n” ) ;

}
Printf ( “Enter vehicle number: “ ) ;

Scanf ( “%d”, &number ) ;

/* add cars’ data */

If ( type == CAR || type == SCOOTER )

Getfreerowcol ( type, tarr ) ;

If ( tarr[0] != -1 && tarr[1] != -1 )

Row = tarr[0] ;

Col = tarr[1] ;

If ( type == CAR )

Car[row][col] = add ( type, number, row, col ) ;

Else

Scooter[row – 2][col] = add ( type, number, row, col ) ; ;

Else

If ( type == CAR )

Printf ( “\nNo parking slot free to park a car\n” ) ;

Else

Printf ( “\nNo parking slot free to park a scooter\n” ) ;

Else

Printf ( “Invalid type\n” ) ;


Break ;

Printf ( “\nPress any key to continue…” ) ;

Getch( ) ;

Break ;

Case 2 :

Clrscr( ) ;

Printf ( “Total vehicles parked: %d\n”, vehcount ) ;

Printf ( “\nPress any key to continue…” ) ;

Getch( ) ;

Break ;

Case 3 :

Clrscr( ) ;

Printf ( “Total cars parked: %d\n”, carcount ) ;

Printf ( “\nPress any key to continue…” ) ;

Getch( ) ;

Break ;

Case 4 :

Clrscr( ) ;

Printf ( “Total scooters parked: %d\n”, scootercount ) ;

Printf ( “\nPress any key to continue…” ) ;


Getch( ) ;

Break ;

Case 5 :

Clrscr( ) ;

Printf ( “Display\n” ) ;

Display( ) ;

Printf ( “\nPress any key to continue…” ) ;

Getch( ) ;

Break ;

Case 6 :

Clrscr( ) ;

Printf ( “Departure\n” ) ;

Type = 0 ;

/* check for vehicle type */

While ( type != CAR && type != SCOOTER )

Printf ( “Enter vehicle type (1 for Car / 2 for Scooter ): \n” ) ;

Scanf ( “%d”, &type ) ;

If ( type != CAR && type != SCOOTER )

Printf ( “\nInvalid vehicle type.\n” ) ;

Printf ( “Enter number: “ ) ;


Scanf ( “%d”, &number ) ;

If ( type == CAR || type == SCOOTER )

Getrcbyinfo ( type, number, tarr ) ;

If ( tarr[0] != -1 && tarr[1] != -1 )

Col = tarr [1] ;

/* if the vehicle is car */

If ( type == CAR )

Row = tarr [0] ;

Del ( car [row][col] ) ;

For ( I = col ; I < 9 ; i++ )

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” ) ;

Printf ( “\nPress any key to continue…” ) ;

Getch( ) ;

Break ;

Case 7 :

Clrscr( ) ;

For ( row = 0 ; row < 2 ; row++ )

{
For ( col = 0 ; col < 10 ; col++ )

If ( car[row][col] -> num != 0 )

Free ( car[row][col] ) ;

If ( scooter[row][col] -> num != 0 )

Free ( scooter[row+2][col] ) ;

Finish = 0 ;

Break ;

You might also like