This high speed train reservation is created to help train station to handle their daily operation of recording data through a kiosk system. Users can buy a ticket, edit information, cancel reservation and display the details of the train from the reference number that is given. All of the transactions made by the user for every train will be recorded in a .txt file.
A set of string and integer data. Each string data is the name of the customer, name of destination, departure place and time of arrival and departure. Each integer data is the customer’s age, seat number, number of container and train number.
Modules | Requirements | Results |
---|---|---|
Train(string dest, string ori, string dest_time, string ori_time) | The train's origin, destination, depart time and arrival time must be given. A train ID variable is inside the instance which it will increment by 1 for every train instance created. A counter variable is also inside the instance for which it will calculate the total number of passengers that booked the seats in the train. | Constructor. Creates the profile of the customer. |
Customer(string fname, string lname, int age, string id, int, seat, customer* next) | Customer's first name, last name, age, id and seat must be given. A customer can make multiple reservations of seats. | Constructor. Creates the profile of the customer. |
Reference(string fname, string lname, int age, string id, int seat, int paid amount) | Customer's first name, last name, age, id and seat must be given. The total paid amount will be determine by what kind of seat/operation requested by the customer. If the seat?s number is in negative number, it means that the customer?s record has been edited before. There will be a refer_num variable inside the class to give a unique reference number for every record created for future reference. | Constructor. Creates the profile of the customer and act as a transaction history for future reference. |
void getDetails() | None | Display the details of train in the main menu. |
void addCustomer() | None | New customer's details are added to the system. |
void editCustomer() | Customers list is not empty. | Customer's details such as their name and change of seat is edited. |
void deleteCustomer (int refernum) | Customers and references lists are not empty. | Customer's booking is deleted if the customer decides to cancel the booking. The seats that are originally booked becomes empty and is available to others. |
void display() | Customers list is not empty. | All customers' details will be displayed. |
void displayReference() | Reference list is not empty. | All previous transaction history will be displayed. |
void searchCustomer (int refernum) | Customers and reference list is not empty. | A particular customer's details will be displayed. |
void sortCustomer() | Customers list is not empty. | Sorts customers in according to their seat numbers. |
void compareSeat (int compare) | Customers list is not empty. | Checks whether a seat is taken or not. |
void addFile(char x) | Reference list is not empty. | Output every transaction history into a .txt file for future reference. |
int getCounter() | None | Return the total amount of seats taken in the particular train as integer. |
void availableSeat() | Customer list is not empty. | Display which seats in the train are taken. If none of the seats are taken it will ask the user to enter whichever seat he/she likes varies from first, business and economy class. |
void enqueue(string first, string last, int umur, string id, int seat, int paid) | None | Adds a new reference node into the reference list as transaction history. |
void dequeue() | None | Removes all of the transaction history. |
void showBooking(int refernum) | None | A customer's booking will be displayed. |
The data structure that we use in our program are linked list, queue, and bubble sort.
-
Linked list
In our high-speed train reservation system, we create two linked list, which are lists of customer and reference. For the linked list of customers, we have a *next pointer in every customer node that points to the next node. In a customer node, there will be the personal details of the customer, seat number and the *next pointer. For the linked list of reference, there will be the details of the customers after making transactions, reference number and a *next pointer. We choose linked list over arrays to make both of the lists because it is easier to do any insertions or deletions at any point in the list. In arrays, we can only put one type of data type, but in linked list, we can insert a collection of different data types in a node such as string for first name and integer for age. So, to access the details of the customer, users have to key in the reference number, and the program will have a *curr pointer to search from the beginning of the list to get the details of the customer. -
Queue
Queue is used using pointers. Once we have added a customer in the program, the program will enqueue the customer in the linked list of reference that contains the transaction (buy ticket, edit details, delete details) of all of the customers. We also have a dequeue function that will dequeue the transactions before we exit the program to clear out the memory in the program. We use queue in our program because it operates in a First In First Out context. Queue can enqueue the customer’s references in ascending order and dequeue them ascendingly when the program is terminated. -
Bubble sort
For the sort function, we have implemented bubble sort in our program. In the sortCustomer() function, we will sort the customer based on their seat numbers. For example, if Customer A chooses seat 3 first and Customer B chooses seat 2 after that, the sort function will swap their positions to make sure Customer B is before Customer A. We choose bubble sort because it is easier to implement and understand.
This system only has one type of user, which is the person who is using the kiosk. The four functions that the user can use are:
- Purchase train ticket
- Cancel reservation
- Modify ticket information
- Display ticket details
-
If the user chooses the 'buy ticket' option, the system will show a list of the available train services. The user can then choose the train service that they want by entering the alphabet (A/B/C in this case).
-
After entering the user's train of choice, the user is prompted to enter personal details (name, age, ID number).
-
The user is then prompted to choose a seat. There are three choices, first class, business class and economy class. The system shows the user which seat is occupied/booked by others. In this case, train A has no passenger yet, so the user can choose any seat.
-
After choosing the seat, a summary of the booking is shown. A reference number is given to user for further usage (explained later). If the user wants to buy more tickets, press Y. If the user decides to return to the main menu, press N.
-
If the user chooses the 'cancel reservation' option, the user is asked to pay an extra fee to cancel the reservation. The user is then prompted to key in the train booked and the reference number.
-
The system shows a summary to show that the user has cancelled the booking. This seat number is intentionally set to 99 to show that the booking is cancelled.
-
If the user chooses the 'modify ticket information' option, the user is prompted to key in the train details followed by the reference number. The user can then choose to edit either the first name, last name, age, ID or seat.
-
If the user chooses the 'display ticket details' option, the reference number has to be entered followed by the train that is booked by the user. The details of the booking will then be shown.
Joey Lim, Y.F.,Tan, C.R.,Teh.
The program is built using Codeblocks V16.01. This project is made for my TDS 2111 Data Structure and Algorithm
subject. The original program of this assignment is modified and updated.