-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
129 lines (107 loc) · 3.06 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_SEATS 30
#define MAX_NAME_LENGTH 50
struct Booking {
char name[MAX_NAME_LENGTH];
int seatNo;
// Add more fields as needed
};
struct Booking bookings[MAX_SEATS];
int bookedSeats = 0;
void bookSeat() {
if (bookedSeats >= MAX_SEATS) {
printf("No more seats available.\n");
return;
}
struct Booking newBooking;
printf("Enter name: ");
scanf("%s", newBooking.name);
printf("Enter seat number: ");
scanf("%d", &newBooking.seatNo);
// Add more input fields as needed
bookings[bookedSeats++] = newBooking;
printf("Seat booked successfully.\n");
}
void viewReservations() {
if (bookedSeats == 0) {
printf("No reservations made yet.\n");
return;
}
printf("All reservations:\n");
printf("Seat No.\tName\n");
for (int i = 0; i < bookedSeats; ++i) {
printf("%d\t\t%s\n", bookings[i].seatNo, bookings[i].name);
}
}
void editReservation() {
int seatToEdit;
printf("Enter seat number to edit: ");
scanf("%d", &seatToEdit);
int found = 0;
for (int i = 0; i < bookedSeats; ++i) {
if (bookings[i].seatNo == seatToEdit) {
printf("Enter new name: ");
scanf("%s", bookings[i].name);
// Add more fields to edit as needed
printf("Reservation edited successfully.\n");
found = 1;
break;
}
}
if (!found) {
printf("Reservation not found.\n");
}
}
void printTicket() {
int seatToPrint;
printf("Enter seat number to print ticket: ");
scanf("%d", &seatToPrint);
int found = 0;
for (int i = 0; i < bookedSeats; ++i) {
if (bookings[i].seatNo == seatToPrint) {
printf("Ticket for Seat No. %d\n", bookings[i].seatNo);
printf("Passenger Name: %s\n", bookings[i].name);
// Add more fields to print as needed
found = 1;
break;
}
}
if (!found) {
printf("Reservation not found.\n");
}
}
int main() {
int choice;
do {
printf("\nMini Bus Booking System\n");
printf("1. Book a seat\n");
printf("2. View reservations\n");
printf("3. Edit a reservation\n");
printf("4. Print a ticket\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
bookSeat();
break;
case 2:
viewReservations();
break;
case 3:
editReservation();
break;
case 4:
printTicket();
break;
case 5:
printf("Exiting...\n");
break;
default:
printf("Invalid choice. Please enter a valid option.\n");
}
} while (choice != 5);
return 0;
}