Question #62701

If there is a space to park the vechiles then some n number of vechiles are parked there and then count how many are of cars, and how many of are scooters and note the arrival time and the departure time, display the order of parked vechiles, and the color of vechile,if he wants to take the vehicle from the parking he has to tell the number of vehicle if the number is wrong he can’t able to take the vehicle from parking in that case he has to tell the car model and the color of vehicle and also the rc book of vehicle and also he has to calculate the parking fees based on time he kept.

Expert's answer

#include<stdio.h>
struct Vechile //struct for item car and scooter
{
int personal_number;
int rc_number;
char model [30];
char color [30];
int time Arrival;
int time_departure;
}array_car [100];//, array_scooter[100];
int space_car = 0;
//int space_scooter = 0;
int number_car = 0;
//int number_scooter = 0;
void show_item() //function for showing what you can do with car and scooter
{
printf ("1 - Add car to park\n");
printf ("2 - Take car from park\n");
printf ("3 - Show all car in park\n");
printf ("0 - Exit\n");
}
void add_car() // function adding car to park
{
system("cls");
if (number_car == space_car)
{
printf ("The park is full\n");
return;
}
printf ("Enter the personal number of car: ");
scanf ("%i", &array_car [number_car ]. personal_number);
printf ("Enter the rc_book of car: ");
scanf ("%i", &array_car [number_car ]. rc_number);
printf ("Enter the model of car: ");
scanf ("%s", &array_car [number_car ]. model);
printf ("Enter the color of car: ");
scanf ("%s", &array_car [number_car ]. color);
printf ("Enter when you arrive in park: ");
scanf ("%i", &array_car [number_car ]. time Arrival);
printf ("Enter when you will depart from park: ");
scanf ("%i", &array_car [number_car ]. time_departure);
number_car++;
}
int compare(char a[], char b[]) // compare two arrays if they are the same
{
int i = 0;
for (i; i < 20; ++i)
{
if (a[i] != b[i])
return 0;
}
return 1;
}
void take_car() //function taking car from park(you will have number_car-1)
{
system("cls");
if (number_car == 0)
{
printf ("The park is empty!\n");
return;
}
printf ("Enter number of car which you want to take: ");
int number = 0;
scanf ("%i", &number);
}
int i = 0;
int index = -1;
for (i; i < number_car; ++i)
{
if (number == array_car[i].personal_number)
{
index = i;
break;
}
}
if (index != -1)
{
printf("You take %ith car\n", index + 1);
{
i = index + 1;
int n_car = index;
for (i; i < number_car; ++i)
{
array_car[n_car] = array_car[i];
n_car++;
}
number_car--;
}
else
{
printf("You enter number of car incorrectly!\n");
printf("Enter the rc book of car: ");
int rc = 0;
scanf("%i",&rc);
printf("Enter the model of car: ");
char mod[20] = {0};
scanf("%s",&mod);
printf("Enter the color of car: ");
char col[20] = {0};
scanf("%s",&col);
int i = 0;
int index = -1;
for (i; i < number_car; ++i)
{
if (rc == array_car[i].rc_number &&
compare(mod, array_car[i].model) &&
compare(col, array_car[i].color))
{
index = i;
break;
}
}
if (index != -1)
{
printf("You take %ith car\n", index + 1);
{
i = index + 1;
int n_car = index;
for (i; i < number_car; ++i)
{
array_car[n_car] = array_car[i];
n_car++;
}
number_car--;
}
else
{
printf("You enter incorrect data! You can't take car!\n");
}
}
}
void show_car() //function for showing all car which you have in park
{
system("cls");
if (number_car == 0)
{
printf("Park is empty!\n");
return;
}
else
if (number_car == 1)
{
printf("There are 1 car in park:\n");
}
else
{
printf("There are %i cars in park:\n", number_car);
}
int i = 0;
for (i; i < number_car; ++i)
{
printf("%d\n", array_car[i].personal_number);
printf("%d\n", array_car[i].rc_number);
printf("%s\n", array_car[i].model);
printf("%s\n", array_car[i].color);
printf("%d\n", array_car[i].time_arrival);
printf("%d\n", array_car[i].time_departure);
printf("\n");
}
}
void menu() // general function for take choice
{
show_item();
int choice = 0;
scanf("%i",&choice);
switch (choice)
{
case 1:
add_car();
break;
case 2:
take_car();
break;
case 3:
show_car();
break;
case 0:
return;
default:
printf("Bad inputting! try again!\n");
}
menu();
}
void input_count_vechile() // function for input numbers of...
{
printf("Input number of free places for car in park: ");
scanf("%i",&space_car);
//&struct("Input number of free places for scooter in park: ");
//&input("%i",&space_scooter);
menu();
}
int main()
{
input_count_vechile();
return 0;
}
http://www.AssignmentExpert.com

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS