C++ Projects with Source Code
10 Unique C++ Projects with Source Code The C++ programming language is widely recognized for offering numerous advantages compared to the C language. The most interesting feature of this language is its support for object-oriented programming, which opens up a completely new realm of possibilities. We are pleased to provide you with over 10 C++ projects with source code for learners. One of the most popular programming languages that is widely used in many different industries, including games, operating systems, web browsers, and database management systems, is C++. Because it incorporates object-oriented programming concepts, such as the use of specified classes, into the C programming language, some refer to C++ as “C with classes.” Over time, C++ has continued to be a very useful language for computer programming as well as to teach new programmers how object-oriented programming operates. C++ Projects with Source Code 1. Bank Management System Project This project is a simple C++ Project with source code. Bank Management System Project in C++ uses C++ to manage banking operations like account creation, deposits, and withdrawals. Users interact with the system, providing input for tasks such as updating account details. C++ is chosen for its efficiency and versatility, allowing the implementation of features like data processing and user interfaces. The output includes updated account balances and transaction receipts displayed to users. C++ #include <iostream> #include <map> #include <string> using namespace std; class Bank { private: map<string, double> accounts; public: void createAccount(const string& name, double initialDeposit) { if (accounts.find(name) != accounts.end()) { cout << "Account already exists!" << endl; } else { accounts[name] = initialDeposit; cout << "Account created successfully!" << endl; } } void deposit(const string& name, double amount) { if (accounts.find(name) != accounts.end()) { accounts[name] += amount; cout << "Amount deposited successfully!" << endl; } else { cout << "Account does not exist!" << endl; } } void withdraw(const string& name, double amount) { if (accounts.find(name) != accounts.end()) { if (accounts[name] >= amount) { accounts[name] -= amount; cout << "Amount withdrawn successfully!" << endl; } else { cout << "Insufficient balance!" << endl; } } else { cout << "Account does not exist!" << endl; } } void checkBalance(const string& name) { if (accounts.find(name) != accounts.end()) { cout << "Balance for account " << name << " is: " << accounts[name] << endl; } else { cout << "Account does not exist!" << endl; } } }; int main() { Bank bank; // Sample usage bank.createAccount("Alice", 1000); bank.deposit("Alice", 500); bank.checkBalance("Alice"); bank.withdraw("Alice", 200); bank.checkBalance("Alice"); return 0; } #include <iostream> #include <map> #include <string> using namespace std; class Bank { private: map<string, double> accounts; public: void createAccount(const string& name, double initialDeposit) { if (accounts.find(name) != accounts.end()) { cout << "Account already exists!" << endl; } else { accounts[name] = initialDeposit; cout << "Account created successfully!" << endl; } } void deposit(const string& name, double amount) { if (accounts.find(name) != accounts.end()) { accounts[name] += amount; cout << "Amount deposited successfully!" << endl; } else { cout << "Account does not exist!" << endl; } } void withdraw(const string& name, double amount) { if (accounts.find(name) != accounts.end()) { if (accounts[name] >= amount) { accounts[name] -= amount; cout << "Amount withdrawn successfully!" << endl; } else { cout << "Insufficient balance!" << endl; } } else { cout << "Account does not exist!" << endl; } } void checkBalance(const string& name) { if (accounts.find(name) != accounts.end()) { cout << "Balance for account " << name << " is: " << accounts[name] << endl; } else { cout << "Account does not exist!" << endl; } } }; int main() { Bank bank; // Sample usage bank.createAccount("Alice", 1000); bank.deposit("Alice", 500); bank.checkBalance("Alice"); bank.withdraw("Alice", 200); bank.checkBalance("Alice"); return 0; } 2. Train Reservation System Project The concept of the project is a train reservation system to reserve train tickets for multiple destinations. In this project, C++ is used to implement the logic for seat availability, reservation confirmation, and the generation of booking records. C++ is utilized to handle data processing, implement user interfaces, and manage the overall flow of the reservation application. The language allows for implementing key functionalities required for a reservation system, providing users with a straightforward and reliable platform to manage their train travel plans. C++ #include <iostream> #include <map> #include <vector> #include <string> using namespace std; class TrainReservationSystem { private: map<int, int> availableSeats; // Map to store available seats for each train public: TrainReservationSystem() { // Initialize available seats for each train availableSeats[1] = 50; availableSeats[2] = 50; availableSeats[3] = 50; } void displayAvailableSeats() { cout << "Available Seats:" << endl; for (const auto& pair : availableSeats) { cout << "Train " << pair.first << ": " << pair.second << " seats" << endl; } } void bookTicket(int trainNumber, int numTickets) { if (availableSeats.find(trainNumber) != availableSeats.end()) { if (availableSeats[trainNumber] >= numTickets) { availableSeats[trainNumber] -= numTickets; cout << numTickets << " ticket(s) booked successfully for Train " << trainNumber << endl; } else { cout << "Insufficient seats available for Train " << trainNumber << endl; } } else { cout << "Invalid Train Number" << endl; } } void cancelTicket(int trainNumber, int numTickets) { if (availableSeats.find(trainNumber) != availableSeats.end()) { availableSeats[trainNumber] += numTickets; cout << numTickets << " ticket(s) canceled successfully for Train " << trainNumber << endl; } else { cout << "Invalid Train Number" << endl; } } }; int main() { TrainReservationSystem trainSystem; int choice, trainNumber, numTickets; do { cout << "nTrain Reservation System" << endl; cout << "1. Display Available Seats" << endl; cout << "2. Book Ticket" << endl; cout << "3. Cancel Ticket" << endl; cout << "4. Exit" << endl; cout << "Enter your choice: "; cin >> choice; switch(choice) { case 1: trainSystem.displayAvailableSeats(); break; case 2: cout << "Enter Train Number: "; cin >> trainNumber; cout << "Enter Number of Tickets: "; cin >> numTickets; trainSystem.bookTicket(trainNumber, numTickets); break; case 3: cout << "Enter Train Number: "; cin >> trainNumber; cout << "Enter Number of Tickets: "; cin >> numTickets; trainSystem.cancelTicket(trainNumber, numTickets); break; case 4: cout