BUS Management System
BUS Management System
pseudocode: -
1. START
- integer bus_id
- string driver_name
- integer total_seats
- integer booked_seats
4. DECLARE integer i
8. MAIN:
b. LOOP:
- PRINT menu options (Add Bus, View Buses, Book a Seat, Exit)
c. IF choice is 1 THEN:
- CALL addBus()
- CALL viewBuses()
- CALL bookSeat()
g. ELSE:
9. FUNCTION addBus:
c. GET bus_id
e. GET driver_name
g. GET total_seats
h. SET booked_seats to 0
d. GET bus_id
- IF bus_id matches:
- SET found to 1
- PRINT "Enter number of seats to book:"
- GET seats_to_book
- ELSE:
k. IF found THEN:
l. ELSE:
- DELETE "temp.txt"
12. END
Snippets: -
1. Login Function
Purpose: Allows the user to add a bus with its ID, driver’s name, and total seats to the system.
Key Operations:
Prompts the user to input bus details (ID, driver name, total seats).
Initializes the number of booked seats to 0 since the bus is newly added.
Opens the file (buses.txt) in append mode (ab) to add the bus details.
Uses fwrite() to save the bus data to the file.
Closes the file and notifies the user of the successful addition.
2. Viewing All Buses (viewBuses function)
Purpose: Displays the details of all buses currently stored in the system.
Key Operations:
Key Operations:
Purpose: Allows a user to book seats on a specific bus.
Prompts the user for the bus ID and number of seats to book.
Searches for the bus with the provided ID in the file.
Checks if there are enough available seats on the bus.
If the bus exists and there are enough seats, updates the number of booked seats.
Creates a temporary file (temp.txt) to write the updated bus records,
including the newly updated bus.
After processing, deletes the original file and renames the temporary file to the original file name.
Handles errors (like no buses found or insufficient seats) and cleans up if needed.
4. Main Menu Loop (main function)
Purpose: Displays the main menu and allows the user to choose an action.
Key Operations:
Displays a menu with four options: Add Bus, View Buses, Book a Seat, and Exit.
Takes input from the user to determine the next action.
Uses a switch statement to call the appropriate function based on the user’s choice.
Handles invalid input by asking the user to try again.
Exits the program if the user selects the "Exit" option.
CODE: -
INPUT AND OUTPUT: -