├── .github ├── FUNDING.yml ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── feature_request.yml └── workflows │ └── codeql.yml ├── .gitignore ├── CMakeLists.txt ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── screenshots ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png └── 6.png └── src ├── Bus.cpp ├── Bus.h ├── Reservation.cpp ├── Reservation.h ├── main.cpp └── utils.h /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: nixrajput 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: File a bug report 3 | title: "[Bug]: " 4 | labels: ["bug", "triage"] 5 | assignees: ["nixrajput"] 6 | body: 7 | - type: input 8 | id: contact 9 | attributes: 10 | label: Contact Details 11 | description: How can we get in touch with you if we need more info? 12 | placeholder: ex. email@example.com 13 | validations: 14 | required: false 15 | - type: textarea 16 | id: what-happened 17 | attributes: 18 | label: What happened? 19 | description: Also tell us, what did you expect to happen? 20 | placeholder: Tell us what you see! 21 | validations: 22 | required: true 23 | - type: dropdown 24 | id: devices 25 | attributes: 26 | label: What devices are you seeing the problem on? 27 | multiple: true 28 | options: 29 | - Windows 30 | - Mac 31 | - Linux 32 | validations: 33 | required: true 34 | - type: input 35 | id: os 36 | attributes: 37 | label: OS Version 38 | description: On what version of OS is your device running? 39 | placeholder: Windows 11 40 | validations: 41 | required: true 42 | - type: textarea 43 | id: logs 44 | attributes: 45 | label: Relevant log output 46 | description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 47 | render: shell 48 | - type: checkboxes 49 | id: terms 50 | attributes: 51 | label: Code of Conduct 52 | description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/nixrajput/flutter_carousel_widget/CODE_OF_CONDUCT.md). 53 | options: 54 | - label: I agree to follow this project's Code of Conduct 55 | required: true 56 | - type: markdown 57 | attributes: 58 | value: "## Thanks for taking the time to fill out this bug report!" 59 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature request 2 | description: Suggest an idea for this project 3 | title: "[Feature Request]: " 4 | labels: ["enhancement"] 5 | assignees: 6 | - nixrajput 7 | body: 8 | - type: input 9 | id: contact 10 | attributes: 11 | label: Contact Details 12 | description: How can we get in touch with you if we need more info? 13 | placeholder: ex. email@example.com 14 | validations: 15 | required: false 16 | - type: textarea 17 | id: feature 18 | attributes: 19 | label: Is your feature request related to a problem? Please describe. 20 | description: A clear and concise description of what the problem is. 21 | placeholder: Write here 22 | validations: 23 | required: true 24 | - type: textarea 25 | id: solution 26 | attributes: 27 | label: Describe the solution you'd like 28 | description: A clear and concise description of what you want to happen. 29 | placeholder: Write here 30 | validations: 31 | required: true 32 | - type: textarea 33 | id: alternatives 34 | attributes: 35 | label: Describe alternatives you've considered 36 | description: A clear and concise description of any alternative solutions or features you've considered. 37 | placeholder: Write here 38 | validations: 39 | required: true 40 | - type: textarea 41 | id: additional-context 42 | attributes: 43 | label: Additional context 44 | description: Add any other context or screenshots about the feature request here. 45 | placeholder: Write here 46 | - type: checkboxes 47 | id: terms 48 | attributes: 49 | label: Code of Conduct 50 | description: By submitting this issue, you agree to follow our [Code of Conduct](https://github.com/nixrajput/flutter_carousel_widget/CODE_OF_CONDUCT.md). 51 | options: 52 | - label: I agree to follow this project's Code of Conduct 53 | required: true 54 | - type: markdown 55 | attributes: 56 | value: "## Thanks for taking the time to fill out this feature request form!" 57 | -------------------------------------------------------------------------------- /.github/workflows/codeql.yml: -------------------------------------------------------------------------------- 1 | name: C++ Code Analysis 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | pull_request: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | build-and-analyze: 13 | runs-on: ubuntu-latest 14 | 15 | steps: 16 | - name: Checkout code 17 | uses: actions/checkout@v4 18 | 19 | - name: Install C++ tools 20 | run: sudo apt-get update && sudo apt-get install -y clang clang-tidy cppcheck cmake 21 | 22 | - name: List directory contents 23 | run: ls -R 24 | 25 | - name: Check for CMakeLists.txt 26 | run: | 27 | if [ ! -f ./CMakeLists.txt ]; then 28 | echo "CMakeLists.txt not found in the root directory." 29 | exit 1 30 | fi 31 | 32 | - name: Create build directory 33 | run: mkdir build 34 | 35 | - name: Run CMake 36 | run: cmake -S . -B build 37 | 38 | - name: Build project 39 | run: cmake --build build 40 | 41 | - name: Run cppcheck 42 | run: cppcheck --enable=all --inconclusive --xml --xml-version=2 . 2> cppcheck-result.xml 43 | 44 | - name: Run clang-tidy 45 | run: find . -name '*.cpp' | xargs clang-tidy -p build 46 | 47 | - name: Upload cppcheck results 48 | uses: actions/upload-artifact@v3 49 | with: 50 | name: cppcheck-result 51 | path: cppcheck-result.xml 52 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ 2 | data/ 3 | out/ 4 | 5 | # Prerequisites 6 | *.d 7 | 8 | # Compiled Object files 9 | *.slo 10 | *.lo 11 | *.o 12 | *.obj 13 | 14 | # Precompiled Headers 15 | *.gch 16 | *.pch 17 | 18 | # Compiled Dynamic libraries 19 | *.so 20 | *.dylib 21 | *.dll 22 | 23 | # Fortran module files 24 | *.mod 25 | *.smod 26 | 27 | # Compiled Static libraries 28 | *.lai 29 | *.la 30 | *.a 31 | *.lib 32 | 33 | # Executables 34 | *.out 35 | *.app 36 | *.dat 37 | *.exe -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | # Set the project name and version 4 | project(BusReservationSystem VERSION 1.0) 5 | 6 | # Specify the C++ standard 7 | set(CMAKE_CXX_STANDARD 11) 8 | set(CMAKE_CXX_STANDARD_REQUIRED True) 9 | 10 | # Add the executable 11 | add_executable(BusReservationSystem src/main.cpp) 12 | 13 | # Include directories if needed 14 | include_directories(${PROJECT_SOURCE_DIR}/src) 15 | 16 | # Link libraries if needed 17 | # target_link_libraries(BusReservationSystem ) 18 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | We as members, contributors, and leaders pledge to participate in our 6 | community a harassment-free experience for everyone, regardless of age, body 7 | size, visible or invisible disability, ethnicity, sex characteristics, gender 8 | identity and expression, level of experience, education, socio-economic status, 9 | nationality, personal appearance, race, religion, or sexual identity 10 | and orientation. 11 | 12 | We pledge to act and interact in ways that contribute to an open, welcoming, 13 | diverse, inclusive, and healthy community. 14 | 15 | ## Our Standards 16 | 17 | Examples of behavior that contributes to a positive environment for our 18 | community includes: 19 | 20 | * Demonstrating empathy and kindness toward other people 21 | * Being respectful of differing opinions, viewpoints, and experiences 22 | * Giving and gracefully accepting constructive feedback 23 | * Accepting responsibility and apologizing to those affected by our mistakes, 24 | and learning from the experience 25 | * Focusing on what is best not just for us as individuals, but for the 26 | overall community 27 | 28 | Examples of unacceptable behavior include: 29 | 30 | * The use of sexualized language or imagery, and sexual attention or 31 | advances of any kind 32 | * Trolling, insulting or derogatory comments, and personal or political attacks 33 | * Public or private harassment 34 | * Publishing others' private information, such as a physical or email 35 | address, without their explicit permission 36 | * Other conduct that could reasonably be considered inappropriate in a 37 | professional setting 38 | 39 | ## Enforcement Responsibilities 40 | 41 | Community leaders are responsible for clarifying and enforcing our standards of 42 | acceptable behavior and will take appropriate and fair corrective action in 43 | response to any behavior that they deem inappropriate, threatening, offensive, 44 | or harmful. 45 | 46 | Community leaders have the right and responsibility to remove, edit, or reject 47 | comments, commits, code, wiki edits, issues, and other contributions that are 48 | not aligned to this Code of Conduct, and will communicate reasons for moderation 49 | decisions when appropriate. 50 | 51 | ## Scope 52 | 53 | This Code of Conduct applies within all community spaces and also applies when 54 | an individual is officially representing the community in public spaces. 55 | Examples of representing our community include using an official e-mail address, 56 | posting via an official social media account, or acting as an appointed 57 | representative at an online or offline event. 58 | 59 | ## Enforcement 60 | 61 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 62 | reported to the community leaders responsible for enforcement at 63 | . 64 | All complaints will be reviewed and investigated promptly and fairly. 65 | 66 | All community leaders are obligated to respect the privacy and security of the 67 | reporter of any incident. 68 | 69 | ## Enforcement Guidelines 70 | 71 | Community leaders will follow these Community Impact Guidelines in determining 72 | the consequences for any action they deem in violation of this Code of Conduct: 73 | 74 | ### 1. Correction 75 | 76 | **Community Impact**: Use of inappropriate language or other behavior deemed 77 | unprofessional or unwelcome in the community. 78 | 79 | **Consequence**: A private, written warning from community leaders, providing 80 | clarity around the nature of the violation and an explanation of why the 81 | behavior was inappropriate. A public apology may be requested. 82 | 83 | ### 2. Warning 84 | 85 | **Community Impact**: A violation through a single incident or series 86 | of actions. 87 | 88 | **Consequence**: A warning with consequences for continued behavior. No 89 | interaction with the people involved, including unsolicited interaction with 90 | those enforcing the Code of Conduct, for a specified period of time. This 91 | includes avoiding interactions in community spaces as well as external channels 92 | like social media. Violating these terms may lead to a temporary or 93 | permanent ban. 94 | 95 | ### 3. Temporary Ban 96 | 97 | **Community Impact**: A serious violation of community standards, including 98 | sustained inappropriate behavior. 99 | 100 | **Consequence**: A temporary ban from any sort of interaction or public 101 | communication with the community for a specified period of time. No public or 102 | private interaction with the people involved, including unsolicited interaction 103 | with those enforcing the Code of Conduct, is allowed during this period. 104 | Violating these terms may lead to a permanent ban. 105 | 106 | ### 4. Permanent Ban 107 | 108 | **Community Impact**: Demonstrating a pattern of violation of community 109 | standards, including sustained inappropriate behavior, harassment of an 110 | individual, or aggression toward or disparagement of classes of individuals. 111 | 112 | **Consequence**: A permanent ban from any sort of public interaction within 113 | the community. 114 | 115 | ## Attribution 116 | 117 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], 118 | version 2.0, available at 119 | . 120 | 121 | Community Impact Guidelines were inspired by [Mozilla's code of conduct 122 | enforcement ladder](https://github.com/mozilla/diversity). 123 | 124 | [homepage]: https://www.contributor-covenant.org 125 | 126 | For answers to common questions about this code of conduct, see the FAQ at 127 | . Translations are available at 128 | . 129 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to the Bus Reservation System Management 2 | 3 | We appreciate your interest in contributing to the Bus Reservation System Management developed using Object Oriented Programming (OOP) and File Handling concepts in C++. By contributing, you help make this project better and more accessible for others. Please take a moment to review the following guidelines to ensure a smooth and collaborative development process. 4 | 5 | ## Code of Conduct 6 | 7 | Please review and adhere to our [Code of Conduct](CODE_OF_CONDUCT.md). We expect all contributors to be respectful, considerate, and inclusive when interacting with the project and its community. 8 | 9 | ## How to Contribute 10 | 11 | Here are the steps to contribute to this project: 12 | 13 | 1. Fork the Repository: Click the "Fork" button at the top right of this repository to create a copy in your GitHub account. 14 | 15 | 2. Clone the Repository: Clone your forked repository to your local machine using the following command: 16 | 17 | ```bash 18 | git clone https://github.com/nixrajput/bus-reservation-system-cpp.git 19 | ``` 20 | 21 | 3. Create a Branch: Create a new branch for your contributions. Make sure to choose a descriptive branch name that reflects the changes you intend to make. 22 | 23 | ```bash 24 | git checkout -b feature/your-feature-name 25 | ``` 26 | 27 | 4. Make Changes: Implement your changes and improvements in your local repository. Follow the coding style and best practices of the project. 28 | 29 | 5. Test Your Changes: Ensure that your changes do not introduce any errors or regressions. Test the website locally to verify that it functions as expected. 30 | 31 | 6. Commit Changes: Commit your changes with a clear and descriptive commit message. 32 | 33 | ```bash 34 | git commit -m "Add feature/fix: Describe your changes here" 35 | ``` 36 | 37 | 7. Push Changes: Push your changes to your forked repository on GitHub. 38 | 39 | ```bash 40 | git push origin feature/your-feature-name 41 | ``` 42 | 43 | 8. Create a Pull Request: Go to the original repository on GitHub and click the "New Pull Request" button. Provide a concise description of your changes, why they are necessary, and any relevant information. 44 | 45 | 9. Review and Collaboration: Contributors and maintainers will review your Pull Request. Be prepared to address any feedback or make additional changes as necessary. 46 | 47 | 10. Merge: Once your Pull Request is approved and passes all checks, a maintainer will merge it into the main branch. Congratulations, your contribution is now part of the project! 48 | 49 | ## Development Guidelines 50 | 51 | - Follow the project's coding style and guidelines. 52 | - Write clear and concise code with comments where necessary. 53 | - Test your changes thoroughly before submitting a Pull Request. 54 | - Keep Pull Requests focused on a single feature or bug fix. 55 | - Be responsive to feedback and be willing to make improvements as requested. 56 | 57 | ## Reporting Issues 58 | 59 | If you encounter any issues or bugs while using the Portfolio Website, please report them on the [Issues](https://github.com/nixrajput/bus-reservation-system-cpp/issues) page of the repository. Provide as much detail as possible to help us understand and address the problem. 60 | 61 | ## Thank You 62 | 63 | Thank you for contributing to the Portfolio Website project. Your contributions help make this project better and more valuable to its users. We appreciate your time and effort in making this project a success! 64 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Nikhil Rajput 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bus Reservation System Management with OOP and File Handling in C++ 2 | 3 | This repository contains the Bus Reservation System Management project developed using Object Oriented Programming (OOP) and File Handling concepts in C++. 4 | 5 | [![Stars](https://img.shields.io/github/stars/nixrajput/bus-reservation-system-cpp?label=Stars&style=flat)][repo] 6 | [![Forks](https://img.shields.io/github/forks/nixrajput/bus-reservation-system-cpp?label=Forks&style=flat)][repo] 7 | [![Watchers](https://img.shields.io/github/watchers/nixrajput/bus-reservation-system-cpp?label=Watchers&style=flat)][repo] 8 | [![Contributors](https://img.shields.io/github/contributors/nixrajput/bus-reservation-system-cpp?label=Contributors&style=flat)][repo] 9 | 10 | [![GitHub last commit](https://img.shields.io/github/last-commit/nixrajput/bus-reservation-system-cpp?label=Last+Commit&style=flat)][repo] 11 | [![GitHub issues](https://img.shields.io/github/issues/nixrajput/bus-reservation-system-cpp?label=Issues&style=flat)][issues] 12 | [![GitHub pull requests](https://img.shields.io/github/issues-pr/nixrajput/bus-reservation-system-cpp?label=Pull+Requests&style=flat)][pulls] 13 | [![GitHub Licence](https://img.shields.io/github/license/nixrajput/bus-reservation-system-cpp?label=Licence&style=flat)][license] 14 | 15 | ## Table of Contents 16 | 17 | - [Bus Reservation System Management with OOP and File Handling in C++](#bus-reservation-system-management-with-oop-and-file-handling-in-c) 18 | - [Table of Contents](#table-of-contents) 19 | - [Features](#features) 20 | - [Sceenshots](#sceenshots) 21 | - [Getting Started](#getting-started) 22 | - [Prerequisites](#prerequisites) 23 | - [Installation](#installation) 24 | - [Compilation](#compilation) 25 | - [Running the Application](#running-the-application) 26 | - [Admin Credentials](#admin-credentials) 27 | - [File Structure](#file-structure) 28 | - [Classes and Methods](#classes-and-methods) 29 | - [Bus Class](#bus-class) 30 | - [Reservation Class](#reservation-class) 31 | - [File Handling](#file-handling) 32 | - [How to Use](#how-to-use) 33 | - [Contributing](#contributing) 34 | - [License](#license) 35 | - [Sponsor Me](#sponsor-me) 36 | - [Connect With Me](#connect-with-me) 37 | - [Activities](#activities) 38 | 39 | ## Features 40 | 41 | - **Bus Management**: Add, view, and remove bus details. 42 | - **Reservation System**: Book, view, and cancel reservations. 43 | - **File Handling**: Persist bus and reservation data using file handling techniques. 44 | - **User Interface**: Command-line based user interface for interacting with the system. 45 | 46 | ## Sceenshots 47 | 48 | - Welcome Screen 49 | 50 | ![Screenshot 1](screenshots/1.png "Welcome Screen") 51 | 52 | - Main Menu 53 | 54 | ![Screenshot 2](screenshots/2.png "Main Menu") 55 | 56 | - User Menu 57 | 58 | ![Screenshot 3](screenshots/3.png "User Menu") 59 | 60 | - Book Ticket 61 | 62 | ![Screenshot 4](screenshots/4.png "Book Ticket") 63 | 64 | - Admin Menu 65 | 66 | ![Screenshot 5](screenshots/5.png "Admin Menu") 67 | 68 | - Bus List 69 | 70 | ![Screenshot 6](screenshots/6.png "Bus List") 71 | 72 | ## Getting Started 73 | 74 | To get started with the development or usage of this project, follow the instructions below: 75 | 76 | ### Prerequisites 77 | 78 | - A C++ compiler (such as g++, clang++) 79 | - A suitable development environment (such as Visual Studio, Code::Blocks, or a text editor with command line tools) 80 | 81 | ### Installation 82 | 83 | 1. Clone this repository to your local machine: 84 | 85 | ```bash 86 | git clone https://github.com/nixrajput/bus-reservation-system-cpp.git 87 | ``` 88 | 89 | 2. Navigate into the cloned repository directory: 90 | 91 | ```bash 92 | cd bus-reservation-system-cpp 93 | ``` 94 | 95 | ### Compilation 96 | 97 | To compile the project, you can use the following command in the terminal: 98 | 99 | ```bash 100 | g++ -o BusReservationSystem main.cpp Bus.cpp Reservation.cpp 101 | #or 102 | clang++ main.cpp -o BusReservationSystem.exe 103 | ``` 104 | 105 | This command assumes you have `main.cpp`, `Bus.cpp`, and `Reservation.cpp` files. Modify it according to your actual file names. 106 | 107 | ### Running the Application 108 | 109 | After successfully compiling the project, you can run the application using the command: 110 | 111 | ```bash 112 | ./BusReservationSystem 113 | ``` 114 | 115 | ### Admin Credentials 116 | 117 | Username : `admin` 118 | Password : `pass` 119 | 120 | ## File Structure 121 | 122 | The project directory typically contains the following files: 123 | 124 | - `main.cpp`: The main entry point of the application. 125 | - `Bus.h` and `Bus.cpp`: Bus class definition and implementation. 126 | - `Reservation.h` and `Reservation.cpp`: Reservation class definition and implementation. 127 | - `data/`: A directory containing data files for buses and reservations. 128 | - `utils.h`: A file contains required utility functions. 129 | 130 | ## Classes and Methods 131 | 132 | ### Bus Class 133 | 134 | This class manages bus details and includes the following methods: 135 | 136 | - `void addBus()`: Adds a new bus. 137 | - `void displayBuses()`: Displays all buses. 138 | - `void removeBus()`: Removes a bus by ID. 139 | 140 | ### Reservation Class 141 | 142 | This class manages reservations and includes the following methods: 143 | 144 | - `void bookTicket()`: Books a new ticket. 145 | - `void viewReservations()`: Displays all reservations. 146 | - `void cancelReservation()`: Cancels a reservation by ID. 147 | 148 | ### File Handling 149 | 150 | Data persistence is achieved using file handling concepts. The bus and reservation data are stored in separate files within the `data/` directory. 151 | 152 | ## How to Use 153 | 154 | 1. **Add a Bus**: Select the option to add a bus and enter the required details. 155 | 2. **View Buses**: Select the option to view all available buses. 156 | 3. **Remove a Bus**: Select the option to remove a bus and provide the bus ID. 157 | 4. **Book a Ticket**: Select the option to book a ticket and enter the required details. 158 | 5. **View Reservations**: Select the option to view all reservations. 159 | 6. **Cancel a Reservation**: Select the option to cancel a reservation and provide the reservation ID. 160 | 161 | ## Contributing 162 | 163 | If you would like to contribute to this project, feel free to fork the repository, make your changes, and submit a pull request. Please follow the guidelines in the [CONTRIBUTING.md](CONTRIBUTING.md) file. 164 | 165 | ## License 166 | 167 | This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. 168 | 169 | ## Sponsor Me 170 | 171 | By sponsoring my efforts, you're not merely contributing to the development of my projects; you're investing in its growth and sustainability. 172 | 173 | Your support empowers me to dedicate more time and resources to improving the project's features, addressing issues, and ensuring its continued relevance in the rapidly evolving landscape of technology. 174 | 175 | Your sponsorship directly fuels innovation, fosters a vibrant community, and helps maintain the project's high standards of quality. Together, we can shape the future of the projects and make a lasting impact in the open-source community. 176 | 177 | Thank you for considering sponsoring my work! 178 | 179 | [![Sponsor](https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86)](https://github.com/sponsors/nixrajput) 180 | 181 | [![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/nixrajput) 182 | 183 | [!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/nixrajput) 184 | 185 | ## Connect With Me 186 | 187 | [![GitHub: nixrajput](https://img.shields.io/badge/nixrajput-EFF7F6?logo=GitHub&logoColor=333&link=https://www.github.com/nixrajput)][github] 188 | [![Linkedin: nixrajput](https://img.shields.io/badge/nixrajput-EFF7F6?logo=LinkedIn&logoColor=blue&link=https://www.linkedin.com/in/nixrajput)][linkedin] 189 | [![Instagram: nixrajput](https://img.shields.io/badge/nixrajput-EFF7F6?logo=Instagram&link=https://www.instagram.com/nixrajput)][instagram] 190 | [![Twitter: nixrajput07](https://img.shields.io/badge/nixrajput-EFF7F6?logo=X&logoColor=333&link=https://x.com/nixrajput)][twitter] 191 | [![Telegram: nixrajput](https://img.shields.io/badge/nixrajput-EFF7F6?logo=Telegram&link=https://telegram.me/nixrajput)][telegram] 192 | [![Gmail: nkr.nikhi.nkr@gmail.com](https://img.shields.io/badge/nkr.nikhil.nkr@gmail.com-EFF7F6?logo=Gmail&link=mailto:nkr.nikhil.nkr@gmail.com)][gmail] 193 | 194 | ## Activities 195 | 196 | ![Alt](https://repobeats.axiom.co/api/embed/5d7dc395d3509bb6c43c35cc6d1ef043e1ae6e2f.svg "Repobeats analytics image") 197 | 198 | [github]: https://github.com/nixrajput 199 | [twitter]: https://twitter.com/nixrajput07 200 | [instagram]: https://instagram.com/nixrajput 201 | [linkedin]: https://linkedin.com/in/nixrajput 202 | [telegram]: https://telegram.me/nixrajput 203 | [gmail]: mailto:nkr.nikhil.nkr@gmail.com 204 | 205 | [repo]: https://github.com/nixrajput/bus-reservation-system-cpp 206 | [issues]: https://github.com/nixrajput/bus-reservation-system-cpp/issues 207 | [pulls]: https://github.com/nixrajput/bus-reservation-system-cpp/pulls 208 | [license]: https://github.com/nixrajput/bus-reservation-system-cpp/blob/master/LICENSE 209 | -------------------------------------------------------------------------------- /screenshots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixrajput/bus-reservation-system-cpp/1246555a084f55a4020bdf1f01525f16769e64dd/screenshots/1.png -------------------------------------------------------------------------------- /screenshots/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixrajput/bus-reservation-system-cpp/1246555a084f55a4020bdf1f01525f16769e64dd/screenshots/2.png -------------------------------------------------------------------------------- /screenshots/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixrajput/bus-reservation-system-cpp/1246555a084f55a4020bdf1f01525f16769e64dd/screenshots/3.png -------------------------------------------------------------------------------- /screenshots/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixrajput/bus-reservation-system-cpp/1246555a084f55a4020bdf1f01525f16769e64dd/screenshots/4.png -------------------------------------------------------------------------------- /screenshots/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixrajput/bus-reservation-system-cpp/1246555a084f55a4020bdf1f01525f16769e64dd/screenshots/5.png -------------------------------------------------------------------------------- /screenshots/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/nixrajput/bus-reservation-system-cpp/1246555a084f55a4020bdf1f01525f16769e64dd/screenshots/6.png -------------------------------------------------------------------------------- /src/Bus.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Bus.h" 8 | #include "Reservation.h" 9 | #include "utils.h" 10 | 11 | using namespace std; 12 | 13 | // Initialie variables in constructor 14 | Bus::Bus() 15 | { 16 | strlcpy(busNo, ""); 17 | maxSeats = 32; 18 | bookedSeats = 0; 19 | busFare = 0.0; 20 | strlcpy(source, ""); 21 | strlcpy(destination, ""); 22 | strlcpy(sourceTime, ""); 23 | strlcpy(destinationTime, ""); 24 | } 25 | 26 | // Display bus details 27 | void Bus::_displayBusDetails() 28 | { 29 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 30 | cout << "\t\t\t\t\t\t\t\t\t\t Bus No:-> " << getBusNo(); 31 | cout << "\n\t\t\t\t\t\t\t\t\t\t Source:-> " << getSource(); 32 | cout << "\n\t\t\t\t\t\t\t\t\t\t Destination:-> " << getDestination(); 33 | cout << "\n\t\t\t\t\t\t\t\t\t\t Time:-> " << getSourceTime() << " - " << getDestinationTime(); 34 | cout << "\n\t\t\t\t\t\t\t\t\t\t Total Seats:-> " << getMaxSeats(); 35 | cout << "\n\t\t\t\t\t\t\t\t\t\t Seats Remaining:-> " << (getMaxSeats() - getBookedSeats()); 36 | cout << fixed << setprecision(2); 37 | cout << "\n\t\t\t\t\t\t\t\t\t\t Bus Fare:-> " << getBusFare(); 38 | cout << "\n\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 39 | cout << "\n"; 40 | } 41 | 42 | // Add a bus 43 | void Bus::addBus() 44 | { 45 | fstream busFileStream; 46 | 47 | system("cls"); 48 | 49 | printHeading("ADD BUS"); 50 | 51 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Bus Number:-> "; 52 | cin.ignore(); 53 | cin.getline(busNo, 10); 54 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Source:-> "; 55 | cin.getline(source, 20); 56 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Destination:-> "; 57 | cin.getline(destination, 20); 58 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Source Time:-> "; 59 | cin.getline(sourceTime, 20); 60 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Destination Time:-> "; 61 | cin.getline(destinationTime, 20); 62 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Bus Fare:-> "; 63 | cin >> busFare; 64 | 65 | busFileStream.open("../data/buses.dat", ios::out | ios::app | ios::binary); 66 | busFileStream.write((char *)this, sizeof(*this)); 67 | busFileStream.close(); 68 | 69 | cout << "\n\t\t\t\t\t\t\t\t\t\tBus Added Successfully...!!!:-> \n"; 70 | } 71 | 72 | // Display all buses 73 | void Bus::displayBuses() 74 | { 75 | system("cls"); 76 | 77 | fstream busFileStream; 78 | 79 | busFileStream.open("../data/buses.dat", ios::in | ios::app | ios::binary); 80 | 81 | if (!busFileStream) 82 | cout << "\n\t\t\t\tFile Not Found...!!!"; 83 | else 84 | { 85 | printHeading("BUSES"); 86 | 87 | busFileStream.read((char *)this, sizeof(*this)); 88 | 89 | while (!busFileStream.eof()) 90 | { 91 | _displayBusDetails(); 92 | busFileStream.read((char *)this, sizeof(*this)); 93 | } 94 | 95 | busFileStream.close(); 96 | } 97 | } 98 | 99 | // Display bus details by bus number 100 | void Bus::displayBusDetailsByNo() 101 | { 102 | system("cls"); 103 | 104 | char bNo[10]; 105 | int chk = 0; 106 | fstream busFileStream; 107 | 108 | printHeading("VIEW BUS INFO"); 109 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Bus Number:-> "; 110 | cin.ignore(); 111 | cin.getline(bNo, 10); 112 | 113 | system("cls"); 114 | printHeading("BUS INFO"); 115 | 116 | busFileStream.open("../data/buses.dat", ios::in | ios::app | ios::binary); 117 | 118 | if (busFileStream.fail()) 119 | { 120 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 121 | } 122 | else 123 | { 124 | busFileStream.read((char *)this, sizeof(*this)); 125 | while (!busFileStream.eof()) 126 | { 127 | if (strcmp(getBusNo(), bNo) == 0) 128 | { 129 | _displayBusDetails(); 130 | chk = 1; 131 | } 132 | busFileStream.read((char *)this, sizeof(*this)); 133 | } 134 | if (chk == 0) 135 | { 136 | cout << "\n\t\t\t\t\t\t\t\t\t\tBus Not Found...!!\n"; 137 | } 138 | 139 | busFileStream.close(); 140 | } 141 | } 142 | 143 | // Edit a bus details 144 | void Bus::editBus() 145 | { 146 | system("cls"); 147 | 148 | char bNo[10]; 149 | int chk = 0; 150 | 151 | fstream busFileStream, tempFileStream; 152 | 153 | printHeading("EDIT BUS"); 154 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Bus Number:-> "; 155 | cin.ignore(); 156 | cin.getline(bNo, 10); 157 | 158 | busFileStream.open("../data/buses.dat", ios::in | ios::app | ios::binary); 159 | 160 | if (busFileStream.fail()) 161 | { 162 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 163 | } 164 | else 165 | { 166 | tempFileStream.open("../data/temp.dat", ios::out | ios::app | ios::binary); 167 | busFileStream.read((char *)this, sizeof(*this)); 168 | 169 | while (!busFileStream.eof()) 170 | { 171 | if (strcmp(getBusNo(), bNo) == 0) 172 | { 173 | system("cls"); 174 | printHeading("EDIT BUS"); 175 | 176 | _displayBusDetails(); 177 | char s[20], d[20], sTime[20], dTime[20]; 178 | double fare; 179 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Source:-> "; 180 | cin.getline(s, 20); 181 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Destination:-> "; 182 | cin.getline(d, 20); 183 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Source Time:-> "; 184 | cin.getline(sTime, 20); 185 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Destination Time:-> "; 186 | cin.getline(dTime, 20); 187 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Bus Fare:-> "; 188 | cin.ignore(); 189 | cin >> fare; 190 | setSource(s); 191 | setDestination(d); 192 | setSourceTime(sTime); 193 | setDestinationTime(dTime); 194 | setBusFare(fare); 195 | tempFileStream.write((char *)this, sizeof(*this)); 196 | 197 | chk = 1; 198 | } 199 | else 200 | { 201 | tempFileStream.write((char *)this, sizeof(*this)); 202 | } 203 | 204 | busFileStream.read((char *)this, sizeof(*this)); 205 | } 206 | 207 | if (chk == 1) 208 | { 209 | cout << "\n\t\t\t\t\t\t\t\t\t\tBus Updated Successfully...!!\n"; 210 | } 211 | else 212 | { 213 | cout << "\n\t\t\t\t\t\t\t\t\t\tBus Not Found...!!\n"; 214 | } 215 | 216 | busFileStream.close(); 217 | tempFileStream.close(); 218 | remove("../data/buses.dat"); 219 | rename("../data/temp.dat", "../data/buses.dat"); 220 | } 221 | } 222 | 223 | // Remove a bus 224 | void Bus::removeBus() 225 | { 226 | system("cls"); 227 | 228 | char bNo[10]; 229 | int chk = 0; 230 | fstream busFileStream, tempFileStream; 231 | 232 | printHeading("DELETE BUS"); 233 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Bus No:-> "; 234 | cin.ignore(); 235 | cin.getline(bNo, 10); 236 | 237 | busFileStream.open("../data/buses.dat", ios::in | ios::app | ios::binary); 238 | 239 | if (busFileStream.fail()) 240 | { 241 | cout << "\n\\t\t\t\t\t\t\t\t\t\tCan't Open File...!!"; 242 | system("pause"); 243 | } 244 | else 245 | { 246 | tempFileStream.open("../data/temp.dat", ios::out | ios::app | ios::binary); 247 | busFileStream.read((char *)this, sizeof(*this)); 248 | 249 | while (!busFileStream.eof()) 250 | { 251 | if (strcmp(getBusNo(), bNo) != 0) 252 | { 253 | tempFileStream.write((char *)this, sizeof(*this)); 254 | } 255 | else 256 | { 257 | chk = 1; 258 | } 259 | busFileStream.read((char *)this, sizeof(*this)); 260 | } 261 | 262 | if (chk == 0) 263 | { 264 | cout << "\n\t\t\t\t\t\t\t\t\t\tBus Not Found...!!\n"; 265 | } 266 | else 267 | { 268 | cout << "\n\t\t\t\t\t\t\t\t\t\tBus Deleted...!!\n"; 269 | } 270 | 271 | busFileStream.close(); 272 | tempFileStream.close(); 273 | remove("../data/buses.dat"); 274 | rename("../data/temp.dat", "../data/buses.dat"); 275 | } 276 | } 277 | -------------------------------------------------------------------------------- /src/Bus.h: -------------------------------------------------------------------------------- 1 | #ifndef BUS_H 2 | #define BUS_H 3 | 4 | #include 5 | 6 | #include "utils.h" 7 | 8 | using namespace std; 9 | 10 | // BUS CLASS 11 | class Bus 12 | { 13 | private: 14 | // Variables 15 | int maxSeats, bookedSeats; 16 | double busFare; 17 | char busNo[10], source[20], destination[20], sourceTime[20], destinationTime[20]; 18 | 19 | public: 20 | // Constructor 21 | Bus(); 22 | 23 | // Methods 24 | void _displayBusDetails(); 25 | void addBus(); 26 | void displayBuses(); 27 | void displayBusDetailsByNo(); 28 | void removeBus(); 29 | void editBus(); 30 | 31 | // Getters 32 | char *getBusNo() 33 | { 34 | return busNo; 35 | } 36 | 37 | char *getSource() 38 | { 39 | 40 | return source; 41 | } 42 | 43 | char *getDestination() 44 | { 45 | return destination; 46 | } 47 | 48 | char *getSourceTime() 49 | { 50 | return sourceTime; 51 | } 52 | 53 | char *getDestinationTime() 54 | { 55 | return destinationTime; 56 | } 57 | 58 | int getBookedSeats() 59 | { 60 | return bookedSeats; 61 | } 62 | 63 | int getMaxSeats() 64 | { 65 | return maxSeats; 66 | } 67 | 68 | double getBusFare() 69 | { 70 | return busFare; 71 | } 72 | 73 | // Setters 74 | void setBookedSeats() 75 | { 76 | bookedSeats++; 77 | } 78 | 79 | void setCancelTicket() 80 | { 81 | bookedSeats--; 82 | } 83 | 84 | void setSource(char *s) 85 | { 86 | if (s && s[0]) 87 | strlcpy(source, s); 88 | } 89 | 90 | void setDestination(char *d) 91 | { 92 | if (d && d[0]) 93 | strlcpy(destination, d); 94 | } 95 | 96 | void setSourceTime(char *s) 97 | { 98 | if (s && s[0]) 99 | strlcpy(sourceTime, s); 100 | } 101 | 102 | void setDestinationTime(char *d) 103 | { 104 | if (d && d[0]) 105 | strlcpy(destinationTime, d); 106 | } 107 | 108 | void setBusFare(double f) 109 | { 110 | if (f) 111 | busFare = f; 112 | } 113 | }; 114 | 115 | #endif // BUS_H 116 | -------------------------------------------------------------------------------- /src/Reservation.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "Reservation.h" 8 | #include "Bus.h" 9 | #include "utils.h" 10 | 11 | using namespace std; 12 | 13 | // Initialie variables in constructor 14 | Reservation::Reservation() {} 15 | 16 | // Generate a ticket 17 | void Reservation::_generateTicket(char *n, Bus b) 18 | { 19 | strlcpy(name, n); 20 | strlcpy(pnrNo, generatePNR(99999).c_str()); 21 | strlcpy(date, getCurrentDate().c_str()); 22 | bus = b; 23 | } 24 | 25 | // Display the reservation details 26 | void Reservation::_displayReservationDetails() 27 | { 28 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 29 | cout << "\t\t\t\t\t\t\t\t\t\t Name:-> " << getName(); 30 | cout << "\n\t\t\t\t\t\t\t\t\t\t PNR No:-> " << getPnrNo(); 31 | cout << "\n\t\t\t\t\t\t\t\t\t\t Bus No:-> " << bus.getBusNo(); 32 | cout << "\n\t\t\t\t\t\t\t\t\t\t Seat No.:-> " << bus.getBookedSeats(); 33 | cout << "\n\t\t\t\t\t\t\t\t\t\t Date:-> " << getDate(); 34 | cout << "\n\t\t\t\t\t\t\t\t\t\t From:-> " << bus.getSource(); 35 | cout << "\n\t\t\t\t\t\t\t\t\t\t To:-> " << bus.getDestination(); 36 | cout << "\n\t\t\t\t\t\t\t\t\t\t Source Time:-> " << bus.getSourceTime(); 37 | cout << "\n\t\t\t\t\t\t\t\t\t\t Destination Time:-> " << bus.getDestinationTime(); 38 | cout << fixed << setprecision(2); 39 | cout << "\n\t\t\t\t\t\t\t\t\t\t Bus Fare:-> " << bus.getBusFare(); 40 | cout << "\n\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 41 | cout << "\n"; 42 | } 43 | 44 | // Book a ticket 45 | void Reservation::bookTicket() 46 | { 47 | system("cls"); 48 | 49 | char from[20], to[20]; 50 | int chk = 0; 51 | 52 | Bus b; 53 | fstream busFileStream, reservationsFileStream, busTempFileStream; 54 | 55 | printHeading("BOOK TICKET"); 56 | 57 | busFileStream.open("../data/buses.dat", ios::in | ios::app | ios::binary); 58 | 59 | if (busFileStream.fail()) 60 | { 61 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 62 | } 63 | else 64 | { 65 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Source:-> "; 66 | cin.ignore(); 67 | cin.getline(from, 20); 68 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Destination:-> "; 69 | cin.getline(to, 20); 70 | 71 | system("cls"); 72 | printHeading("AVAILABLE BUSES"); 73 | 74 | busFileStream.read((char *)&b, sizeof(b)); 75 | 76 | while (!busFileStream.eof()) 77 | { 78 | if (strcmp(b.getSource(), from) == 0 && strcmp(b.getDestination(), to) == 0) 79 | { 80 | b._displayBusDetails(); 81 | chk = 1; 82 | } 83 | 84 | busFileStream.read((char *)&b, sizeof(b)); 85 | } 86 | 87 | busFileStream.close(); 88 | 89 | if (chk == 0) 90 | { 91 | cout << "\n\t\t\t\t\t\t\t\t\t\tNo Buses Found...!!\n"; 92 | } 93 | else 94 | { 95 | char bNo[10]; 96 | int booked = 0; 97 | 98 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Bus Number:-> "; 99 | cin.getline(bNo, 10); 100 | 101 | busFileStream.open("../data/buses.dat", ios::in | ios::app | ios::binary); 102 | busTempFileStream.open("../data/temp.dat", ios::out | ios::app | ios::binary); 103 | 104 | busFileStream.read((char *)&b, sizeof(b)); 105 | 106 | while (!busFileStream.eof()) 107 | { 108 | if (strcmp(b.getSource(), from) == 0 && strcmp(b.getDestination(), to) == 0 && strcmp(b.getBusNo(), bNo) == 0) 109 | { 110 | if (b.getBookedSeats() >= 32) 111 | { 112 | cout << "\n\t\t\t\t\t\t\t\t\t\tSeat not available...!!\n"; 113 | break; 114 | } 115 | else 116 | { 117 | system("cls"); 118 | printHeading("BOOK TICKET"); 119 | char n[20]; 120 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Customer Name :-> "; 121 | cin.getline(n, 20); 122 | b.setBookedSeats(); 123 | _generateTicket(n, b); 124 | 125 | reservationsFileStream.open("../data/reservations.dat", ios::out | ios::app | ios::binary); 126 | reservationsFileStream.write((char *)this, sizeof(*this)); 127 | reservationsFileStream.close(); 128 | busTempFileStream.write((char *)&b, sizeof(b)); 129 | 130 | booked = 1; 131 | system("cls"); 132 | printHeading("BOOKING DETAILS"); 133 | _displayReservationDetails(); 134 | cout << "\n\t\t\t\t\t\t\t\t\t\tTicket Booked Successfully...!!\n"; 135 | } 136 | } 137 | else 138 | { 139 | busTempFileStream.write((char *)&b, sizeof(b)); 140 | } 141 | 142 | busFileStream.read((char *)&b, sizeof(b)); 143 | } 144 | 145 | if (booked == 1) 146 | { 147 | busFileStream.close(); 148 | busTempFileStream.close(); 149 | remove("../data/buses.dat"); 150 | rename("../data/temp.dat", "../data/buses.dat"); 151 | } 152 | } 153 | 154 | busFileStream.close(); 155 | } 156 | } 157 | 158 | // View all reservations 159 | void Reservation::viewReservations() 160 | { 161 | system("cls"); 162 | 163 | fstream reservationsFileStream; 164 | 165 | system("cls"); 166 | 167 | printHeading("RESERVATIONS"); 168 | 169 | reservationsFileStream.open("../data/reservations.dat", ios::in | ios::app | ios::binary); 170 | 171 | if (reservationsFileStream.fail()) 172 | { 173 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 174 | } 175 | else 176 | { 177 | reservationsFileStream.read((char *)this, sizeof(*this)); 178 | 179 | while (!reservationsFileStream.eof()) 180 | { 181 | _displayReservationDetails(); 182 | reservationsFileStream.read((char *)this, sizeof(*this)); 183 | } 184 | 185 | reservationsFileStream.close(); 186 | } 187 | } 188 | 189 | // Cancel a reservation 190 | void Reservation::cancelReservation() 191 | { 192 | system("cls"); 193 | 194 | char pnr[10]; 195 | int chk = 0; 196 | 197 | fstream busFileStream, reservationsFileStream, reservationsTempFileStream, busTempFileStream; 198 | 199 | printHeading("CANCEL RESERVATION"); 200 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter PNR Number:-> "; 201 | cin.ignore(); 202 | cin.getline(pnr, 10); 203 | 204 | reservationsFileStream.open("../data/reservations.dat", ios::in | ios::app | ios::binary); 205 | reservationsTempFileStream.open("../data/temp.dat", ios::out | ios::app | ios::binary); 206 | 207 | if (reservationsFileStream.fail()) 208 | { 209 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 210 | } 211 | else 212 | { 213 | reservationsFileStream.read((char *)this, sizeof(*this)); 214 | 215 | while (!reservationsFileStream.eof()) 216 | { 217 | if (strcmp(getPnrNo(), pnr) != 0) 218 | { 219 | reservationsTempFileStream.write((char *)this, sizeof(*this)); 220 | } 221 | else 222 | { 223 | Bus b; 224 | busFileStream.open("../data/buses.dat", ios::in | ios::app | ios::binary); 225 | busTempFileStream.open("../data/bustemp.dat", ios::out | ios::app | ios::binary); 226 | 227 | busFileStream.read((char *)&b, sizeof(b)); 228 | 229 | while (!busFileStream.eof()) 230 | { 231 | if (strcmp(b.getBusNo(), bus.getBusNo()) == 0) 232 | { 233 | b.setCancelTicket(); 234 | busTempFileStream.write((char *)&b, sizeof(b)); 235 | } 236 | else 237 | { 238 | busTempFileStream.write((char *)&b, sizeof(b)); 239 | } 240 | 241 | busFileStream.read((char *)&b, sizeof(b)); 242 | } 243 | busFileStream.close(); 244 | busTempFileStream.close(); 245 | remove("../data/buses.dat"); 246 | rename("../data/bustemp.dat", "../data/buses.dat"); 247 | chk = 1; 248 | } 249 | reservationsFileStream.read((char *)this, sizeof(*this)); 250 | } 251 | if (chk == 0) 252 | { 253 | reservationsFileStream.close(); 254 | reservationsTempFileStream.close(); 255 | cout << "\n\t\t\t\t\t\t\t\t\t\tReservation Not Found...!!\n"; 256 | } 257 | else 258 | { 259 | reservationsFileStream.close(); 260 | reservationsTempFileStream.close(); 261 | remove("../data/reservations.dat"); 262 | rename("../data/temp.dat", "../data/reservations.dat"); 263 | cout << "\n\t\t\t\t\t\t\t\t\t\tReservation Cancelled...!!\n"; 264 | } 265 | } 266 | } 267 | 268 | // Edit a reservation 269 | void Reservation::editReservation() 270 | { 271 | system("cls"); 272 | 273 | char pnr[10]; 274 | int chk = 0; 275 | 276 | fstream ticketFileStream, reservationsTempFileStream; 277 | 278 | printHeading("EDIT RESERVATION"); 279 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter PNR Number:-> "; 280 | cin.ignore(); 281 | cin.getline(pnr, 10); 282 | 283 | ticketFileStream.open("../data/reservations.dat", ios::in | ios::app | ios::binary); 284 | 285 | if (ticketFileStream.fail()) 286 | { 287 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 288 | } 289 | else 290 | { 291 | reservationsTempFileStream.open("../data/temp.dat", ios::out | ios::app | ios::binary); 292 | 293 | ticketFileStream.read((char *)this, sizeof(*this)); 294 | 295 | while (!ticketFileStream.eof()) 296 | { 297 | if (strcmp(getPnrNo(), pnr) == 0) 298 | { 299 | system("cls"); 300 | printHeading("EDIT RESERVATION"); 301 | 302 | _displayReservationDetails(); 303 | char n[20]; 304 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Passenger Name :-> "; 305 | cin.getline(n, 20); 306 | setName(n); 307 | reservationsTempFileStream.write((char *)this, sizeof(*this)); 308 | 309 | chk = 1; 310 | } 311 | else 312 | { 313 | reservationsTempFileStream.write((char *)this, sizeof(*this)); 314 | } 315 | 316 | ticketFileStream.read((char *)this, sizeof(*this)); 317 | } 318 | 319 | if (chk == 1) 320 | { 321 | cout << "\n\t\t\t\t\t\t\t\t\t\tReservation Updated Successfully...!!\n"; 322 | } 323 | else 324 | { 325 | cout << "\n\t\t\t\t\t\t\t\t\t\tReservation Not Found...!!\n"; 326 | } 327 | 328 | ticketFileStream.close(); 329 | reservationsTempFileStream.close(); 330 | remove("../data/reservations.dat"); 331 | rename("../data/temp.dat", "../data/reservations.dat"); 332 | } 333 | } 334 | 335 | // View reservation details by PNR number 336 | void Reservation::viewReservationByPNR() 337 | { 338 | system("cls"); 339 | 340 | char pnr[10]; 341 | int chk = 0; 342 | fstream ticketFileStream; 343 | 344 | printHeading("SHOW RESERVATIONS BY PNR"); 345 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter PNR Number:-> "; 346 | cin.ignore(); 347 | cin.getline(pnr, 10); 348 | 349 | system("cls"); 350 | 351 | printHeading("RESERVATIONS"); 352 | 353 | ticketFileStream.open("../data/reservations.dat", ios::in | ios::app | ios::binary); 354 | 355 | if (ticketFileStream.fail()) 356 | { 357 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 358 | } 359 | else 360 | { 361 | ticketFileStream.read((char *)this, sizeof(*this)); 362 | 363 | while (!ticketFileStream.eof()) 364 | { 365 | if (strcmp(getPnrNo(), pnr) == 0) 366 | { 367 | _displayReservationDetails(); 368 | chk = 1; 369 | } 370 | ticketFileStream.read((char *)this, sizeof(*this)); 371 | } 372 | 373 | if (chk == 0) 374 | { 375 | cout << "\n\t\t\t\t\t\t\t\t\t\tNo Reservations...!!\n"; 376 | } 377 | 378 | ticketFileStream.close(); 379 | } 380 | } 381 | 382 | // View reservations by a passenger name 383 | void Reservation::viewReservationsByName() 384 | { 385 | system("cls"); 386 | 387 | char n[20]; 388 | int chk = 0; 389 | fstream ticketFileStream; 390 | 391 | printHeading("SHOW RESERVATIONS BY NAME"); 392 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Passenger Name:-> "; 393 | cin.ignore(); 394 | cin.getline(n, 20); 395 | 396 | system("cls"); 397 | 398 | printHeading("RESERVATIONS"); 399 | 400 | ticketFileStream.open("../data/reservations.dat", ios::in | ios::app | ios::binary); 401 | 402 | if (ticketFileStream.fail()) 403 | { 404 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 405 | } 406 | else 407 | { 408 | ticketFileStream.read((char *)this, sizeof(*this)); 409 | 410 | while (!ticketFileStream.eof()) 411 | { 412 | if (strcmp(getName(), n) == 0) 413 | { 414 | _displayReservationDetails(); 415 | chk = 1; 416 | } 417 | ticketFileStream.read((char *)this, sizeof(*this)); 418 | } 419 | 420 | if (chk == 0) 421 | { 422 | cout << "\n\t\t\t\t\t\t\t\t\t\tNo Reservations...!!\n"; 423 | } 424 | 425 | ticketFileStream.close(); 426 | } 427 | } 428 | 429 | // View reservations by a bus number 430 | void Reservation::viewReservationsByBusNo() 431 | { 432 | system("cls"); 433 | 434 | char bNo[10]; 435 | int chk = 0; 436 | fstream ticketFileStream; 437 | 438 | printHeading("SHOW RESERVATIONS BY NAME"); 439 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Bus Number:-> "; 440 | cin.ignore(); 441 | cin.getline(bNo, 10); 442 | 443 | system("cls"); 444 | 445 | printHeading("RESERVATIONS"); 446 | 447 | ticketFileStream.open("../data/reservations.dat", ios::in | ios::app | ios::binary); 448 | 449 | if (ticketFileStream.fail()) 450 | { 451 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 452 | } 453 | else 454 | { 455 | ticketFileStream.read((char *)this, sizeof(*this)); 456 | 457 | while (!ticketFileStream.eof()) 458 | { 459 | if (strcmp(bus.getBusNo(), bNo) == 0) 460 | { 461 | _displayReservationDetails(); 462 | chk = 1; 463 | } 464 | ticketFileStream.read((char *)this, sizeof(*this)); 465 | } 466 | 467 | if (chk == 0) 468 | { 469 | cout << "\n\t\t\t\t\t\t\t\t\t\tNo Reservations...!!\n"; 470 | } 471 | 472 | ticketFileStream.close(); 473 | } 474 | } 475 | 476 | // View reservations by the source station 477 | void Reservation::viewReservationsBySource() 478 | { 479 | system("cls"); 480 | 481 | char s[20]; 482 | int chk = 0; 483 | fstream ticketFileStream; 484 | 485 | printHeading("SHOW RESERVATIONS BY SOURCE"); 486 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Source:-> "; 487 | cin.ignore(); 488 | cin.getline(s, 20); 489 | 490 | system("cls"); 491 | 492 | printHeading("RESERVATIONS"); 493 | 494 | ticketFileStream.open("../data/reservations.dat", ios::in | ios::app | ios::binary); 495 | 496 | if (ticketFileStream.fail()) 497 | { 498 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 499 | } 500 | else 501 | { 502 | ticketFileStream.read((char *)this, sizeof(*this)); 503 | 504 | while (!ticketFileStream.eof()) 505 | { 506 | if (strcmp(bus.getSource(), s) == 0) 507 | { 508 | _displayReservationDetails(); 509 | chk = 1; 510 | } 511 | ticketFileStream.read((char *)this, sizeof(*this)); 512 | } 513 | 514 | if (chk == 0) 515 | { 516 | cout << "\n\t\t\t\t\t\t\t\t\t\tNo Reservations...!!\n"; 517 | } 518 | 519 | ticketFileStream.close(); 520 | } 521 | } 522 | 523 | // View reservations by the destination station 524 | void Reservation::viewReservationsByDestination() 525 | { 526 | system("cls"); 527 | 528 | char d[20]; 529 | int chk = 0; 530 | fstream ticketFileStream; 531 | 532 | printHeading("SHOW RESERVATIONS BY DESTINATION"); 533 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Destination:-> "; 534 | cin.ignore(); 535 | cin.getline(d, 20); 536 | 537 | system("cls"); 538 | 539 | printHeading("RESERVATIONS"); 540 | 541 | ticketFileStream.open("../data/reservations.dat", ios::in | ios::app | ios::binary); 542 | 543 | if (ticketFileStream.fail()) 544 | { 545 | cout << "\n\t\t\t\t\t\t\t\t\t\tCan't Open File...!!\n"; 546 | } 547 | else 548 | { 549 | ticketFileStream.read((char *)this, sizeof(*this)); 550 | 551 | while (!ticketFileStream.eof()) 552 | { 553 | if (strcmp(bus.getDestination(), d) == 0) 554 | { 555 | _displayReservationDetails(); 556 | chk = 1; 557 | } 558 | ticketFileStream.read((char *)this, sizeof(*this)); 559 | } 560 | 561 | if (chk == 0) 562 | { 563 | cout << "\n\t\t\t\t\t\t\t\t\t\tNo Reservation...!!\n"; 564 | } 565 | 566 | ticketFileStream.close(); 567 | } 568 | } 569 | -------------------------------------------------------------------------------- /src/Reservation.h: -------------------------------------------------------------------------------- 1 | #ifndef RESERVATION_H 2 | #define RESERVATION_H 3 | 4 | #include 5 | 6 | #include "Bus.h" 7 | #include "utils.h" 8 | 9 | // RESERVATION CLASS 10 | class Reservation 11 | { 12 | private: 13 | char name[20], pnrNo[10], date[20]; 14 | Bus bus; 15 | 16 | public: 17 | // Constructor 18 | Reservation(); 19 | 20 | // Methods 21 | void _generateTicket(char *, Bus); 22 | void _displayReservationDetails(); 23 | void bookTicket(); 24 | void viewReservations(); 25 | void cancelReservation(); 26 | void editReservation(); 27 | void viewReservationByPNR(); 28 | void viewReservationsByName(); 29 | void viewReservationsByBusNo(); 30 | void viewReservationsBySource(); 31 | void viewReservationsByDestination(); 32 | 33 | // Getters 34 | char *getName() 35 | { 36 | return name; 37 | } 38 | 39 | char *getPnrNo() 40 | { 41 | return pnrNo; 42 | } 43 | 44 | char *getDate() 45 | { 46 | return date; 47 | } 48 | 49 | // Setters 50 | void setName(char *n) 51 | { 52 | if (n && n[0]) 53 | strlcpy(name, n); 54 | } 55 | }; 56 | 57 | #endif // !RESERVATION_H 58 | -------------------------------------------------------------------------------- /src/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "Bus.cpp" 5 | #include "Reservation.cpp" 6 | #include "utils.h" 7 | 8 | using namespace std; 9 | 10 | // Global Functions 11 | void welcomeScreen(); 12 | void mainMenu(); 13 | void userMenu(); 14 | void adminLogin(); 15 | void adminMenu(); 16 | void reservationsMenu(); 17 | 18 | // `main` function or program entry point 19 | int main() 20 | { 21 | system("cls"); 22 | system("COLOR 03"); 23 | 24 | welcomeScreen(); 25 | 26 | return 0; 27 | } 28 | 29 | // Welcome screen function 30 | void welcomeScreen() 31 | { 32 | system("cls"); 33 | 34 | cout << "\n\n\n\n"; 35 | cout << "\t\t\t\t\t\t\t\t\t\t================================================\n"; 36 | cout << "\t\t\t\t\t\t\t\t\t\t|| WELCOME TO ||\n"; 37 | cout << "\t\t\t\t\t\t\t\t\t\t|| ||\n"; 38 | cout << "\t\t\t\t\t\t\t\t\t\t|| BUS RESERVATION SYSTEM MANAGEMENT ||\n"; 39 | cout << "\t\t\t\t\t\t\t\t\t\t|| ||\n"; 40 | cout << "\t\t\t\t\t\t\t\t\t\t|| PROJECT ||\n"; 41 | cout << "\t\t\t\t\t\t\t\t\t\t================================================\n\n\n"; 42 | 43 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 44 | cout << "\t\t\t\t\t\t\t\t\t\t\t\t Developed By:- \t\n"; 45 | cout << "\t\t\t\t\t\t\t\t\t\t\t\t \t\n"; 46 | cout << "\t\t\t\t\t\t\t\t\t\t\t\t NIKHIL RAJPUT \t\n"; 47 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n\n"; 48 | 49 | system("pause"); 50 | mainMenu(); 51 | } 52 | 53 | // Main menu function 54 | void mainMenu() 55 | { 56 | int choice; 57 | 58 | while (1) 59 | { 60 | system("cls"); 61 | 62 | // Menu items 63 | printHeading("MAIN MENU"); 64 | 65 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 66 | cout << "\t\t\t\t\t\t\t\t\t\t 1. User Menu \n"; 67 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 68 | cout << "\t\t\t\t\t\t\t\t\t\t 2. Admin Menu \n"; 69 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 70 | cout << "\t\t\t\t\t\t\t\t\t\t 3. EXIT \n"; 71 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n\n"; 72 | 73 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter your choice:-> "; 74 | 75 | cin >> choice; 76 | 77 | switch (choice) 78 | { 79 | case 1: 80 | userMenu(); 81 | break; 82 | 83 | case 2: 84 | adminLogin(); 85 | break; 86 | 87 | case 3: 88 | system("cls"); 89 | cout << "\n\n\n\n\t\t\t\t\t\t\t\t\t\t Thanks for using our project...!!! \t\t\t\n"; 90 | cout << "\n\n\t\t\t\t\t\t\t\t\t\t Have a nice day...!!! \t\t\t\n\n"; 91 | exit(0); 92 | 93 | default: 94 | cout << "\n\n\t\t\t\t\t\t\t\t\t\t Choose valid option!!! \t\t\t\n"; 95 | system("pause"); 96 | mainMenu(); 97 | } 98 | } 99 | } 100 | 101 | // User menu function 102 | void userMenu() 103 | { 104 | int choice; 105 | 106 | while (1) 107 | { 108 | system("cls"); 109 | 110 | Reservation t; 111 | 112 | // Menu items 113 | printHeading("USER MENU"); 114 | 115 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 116 | cout << "\t\t\t\t\t\t\t\t\t\t 1. Book Ticket \n"; 117 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 118 | cout << "\t\t\t\t\t\t\t\t\t\t 2. View Ticket \n"; 119 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 120 | cout << "\t\t\t\t\t\t\t\t\t\t 3. Cancel Ticket \n"; 121 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 122 | cout << "\t\t\t\t\t\t\t\t\t\t 4. BACK \n"; 123 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 124 | 125 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter your choice:-> "; 126 | 127 | cin >> choice; 128 | 129 | switch (choice) 130 | { 131 | case 1: 132 | t.bookTicket(); 133 | system("pause"); 134 | break; 135 | 136 | case 2: 137 | t.viewReservationByPNR(); 138 | system("pause"); 139 | break; 140 | 141 | case 3: 142 | t.cancelReservation(); 143 | system("pause"); 144 | break; 145 | 146 | case 4: 147 | system("cls"); 148 | mainMenu(); 149 | break; 150 | 151 | default: 152 | cout << "\n\t\t\t\t\t Choose valid option!!! \t\t\t\n"; 153 | system("pause"); 154 | break; 155 | userMenu(); 156 | } 157 | } 158 | } 159 | 160 | // Admin login function 161 | void adminLogin() 162 | { 163 | string adminUname, adminPass; 164 | 165 | system("cls"); 166 | 167 | printHeading("ADMIN LOGIN"); 168 | 169 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter AdminID:-> "; 170 | cin >> adminUname; 171 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter Password:-> "; 172 | cin >> adminPass; 173 | 174 | if (adminUname == "admin" && adminPass == "pass") 175 | { 176 | adminMenu(); 177 | } 178 | else 179 | { 180 | cout << "\n\t\t\t\t\t\t\t\t\t\tUsername or Password is wrong...!!! "; 181 | system("pause"); 182 | adminLogin(); 183 | } 184 | } 185 | 186 | // Admin menu function 187 | void adminMenu() 188 | { 189 | Bus b; 190 | Reservation r; 191 | 192 | int choice; 193 | 194 | while (1) 195 | { 196 | system("cls"); 197 | 198 | printHeading("ADMIN PORTAL"); 199 | 200 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 201 | cout << "\t\t\t\t\t\t\t\t\t\t 1. Add Bus \n"; 202 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 203 | cout << "\t\t\t\t\t\t\t\t\t\t 2. View Buses \n"; 204 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 205 | cout << "\t\t\t\t\t\t\t\t\t\t 3. Book Ticket \n"; 206 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 207 | cout << "\t\t\t\t\t\t\t\t\t\t 4. Edit Ticket \n"; 208 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 209 | cout << "\t\t\t\t\t\t\t\t\t\t 5. Cancel Ticket \n"; 210 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 211 | cout << "\t\t\t\t\t\t\t\t\t\t 6. View Bookings \n"; 212 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 213 | cout << "\t\t\t\t\t\t\t\t\t\t 7. View Bus Details \n"; 214 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 215 | cout << "\t\t\t\t\t\t\t\t\t\t 8. Edit Bus \n"; 216 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 217 | cout << "\t\t\t\t\t\t\t\t\t\t 9. Delete Bus \n"; 218 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 219 | cout << "\t\t\t\t\t\t\t\t\t\t 10. BACK \n"; 220 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n\n"; 221 | 222 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter your choice:-> "; 223 | 224 | cin >> choice; 225 | 226 | switch (choice) 227 | { 228 | case 1: 229 | b.addBus(); 230 | system("pause"); 231 | break; 232 | 233 | case 2: 234 | b.displayBuses(); 235 | system("pause"); 236 | break; 237 | 238 | case 3: 239 | r.bookTicket(); 240 | system("pause"); 241 | break; 242 | 243 | case 4: 244 | r.editReservation(); 245 | system("pause"); 246 | break; 247 | 248 | case 5: 249 | r.cancelReservation(); 250 | system("pause"); 251 | break; 252 | 253 | case 6: 254 | reservationsMenu(); 255 | break; 256 | 257 | case 7: 258 | b.displayBusDetailsByNo(); 259 | system("pause"); 260 | break; 261 | 262 | case 8: 263 | b.editBus(); 264 | system("pause"); 265 | break; 266 | 267 | case 9: 268 | b.removeBus(); 269 | system("pause"); 270 | break; 271 | 272 | case 10: 273 | system("cls"); 274 | mainMenu(); 275 | break; 276 | 277 | default: 278 | cout << "\n\t\t\t\t\t Choose valid option!!! \t\t\t\n"; 279 | system("pause"); 280 | adminMenu(); 281 | } 282 | } 283 | } 284 | 285 | // View reservations function 286 | void reservationsMenu() 287 | { 288 | Reservation t; 289 | 290 | int choice; 291 | 292 | while (1) 293 | { 294 | system("cls"); 295 | 296 | printHeading("VIEW BOOKINGS"); 297 | 298 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 299 | cout << "\t\t\t\t\t\t\t\t\t\t 1. By PNR \n"; 300 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 301 | cout << "\t\t\t\t\t\t\t\t\t\t 2. By Name \n"; 302 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 303 | cout << "\t\t\t\t\t\t\t\t\t\t 3. By Bus \n"; 304 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 305 | cout << "\t\t\t\t\t\t\t\t\t\t 4. By Source \n"; 306 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 307 | cout << "\t\t\t\t\t\t\t\t\t\t 5. By Destination \n"; 308 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 309 | cout << "\t\t\t\t\t\t\t\t\t\t 6. All Bookings \n"; 310 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n"; 311 | cout << "\t\t\t\t\t\t\t\t\t\t 7. BACK \n"; 312 | cout << "\t\t\t\t\t\t\t\t\t\t-------------------------------------------------\n\n"; 313 | 314 | cout << "\n\t\t\t\t\t\t\t\t\t\tEnter your choice:-> "; 315 | 316 | cin >> choice; 317 | 318 | switch (choice) 319 | { 320 | case 1: 321 | t.viewReservationByPNR(); 322 | system("pause"); 323 | break; 324 | 325 | case 2: 326 | t.viewReservationsByName(); 327 | system("pause"); 328 | break; 329 | 330 | case 3: 331 | t.viewReservationsByBusNo(); 332 | system("pause"); 333 | break; 334 | 335 | case 4: 336 | t.viewReservationsBySource(); 337 | system("pause"); 338 | break; 339 | 340 | case 5: 341 | t.viewReservationsByDestination(); 342 | system("pause"); 343 | break; 344 | 345 | case 6: 346 | t.viewReservations(); 347 | system("pause"); 348 | break; 349 | 350 | case 7: 351 | system("cls"); 352 | adminMenu(); 353 | break; 354 | 355 | default: 356 | cout << "\n\t\t\t\t\t Choose valid option!!! \t\t\t\n"; 357 | system("pause"); 358 | reservationsMenu(); 359 | } 360 | } 361 | } 362 | -------------------------------------------------------------------------------- /src/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_H 2 | #define UTILS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | using namespace std; 13 | 14 | void printHeading(string header) 15 | { 16 | cout << "\n\n\n\n"; 17 | cout << "\t\t\t\t\t\t\t\t\t\t==========================================================\n"; 18 | cout << "\t\t\t\t\t\t\t\t\t\t " << header << " \n"; 19 | cout << "\t\t\t\t\t\t\t\t\t\t==========================================================\n\n"; 20 | } 21 | 22 | string generatePNR(int n) 23 | { 24 | srand(time(0)); 25 | 26 | string pnr; 27 | 28 | int randomNo = rand() % n; 29 | 30 | pnr = "PNR" + to_string(randomNo); 31 | 32 | return pnr; 33 | } 34 | 35 | string getCurrentDate() 36 | { 37 | time_t t = time(NULL); 38 | struct tm tStruct; 39 | 40 | #if defined(_WIN32) || defined(_WIN64) 41 | // Windows: Use localtime_s 42 | localtime_s(&tStruct, &t); 43 | #else 44 | // POSIX-compliant systems (Linux and macOS): Use localtime_r 45 | localtime_r(&t, &tStruct); 46 | #endif 47 | 48 | // Use stringstream for efficient string construction 49 | ostringstream oss; 50 | oss << tStruct.tm_mday << "-" 51 | << (tStruct.tm_mon + 1) << "-" 52 | << (tStruct.tm_year + 1900); 53 | 54 | return oss.str(); 55 | } 56 | 57 | size_t strlcpy(char *dst, const char *src, size_t dstsize = numeric_limits::max()) 58 | { 59 | size_t srclen = strlen(src); 60 | size_t copylen = (srclen >= dstsize) ? dstsize - 1 : srclen; 61 | 62 | if (dstsize != 0) 63 | { 64 | memcpy(dst, src, copylen); 65 | dst[copylen] = '\0'; // Null-terminate the destination buffer 66 | } 67 | 68 | return srclen; // Return the total length of the string it tried to create 69 | } 70 | 71 | #endif // UTILS_H 72 | --------------------------------------------------------------------------------