Intermediate C++ Projects
Level up with object-oriented programming and data structures
β‘ Intermediate C++ Projects
Build more complex applications using classes, objects, file handling, and data structures. These projects introduce object-oriented programming concepts and help you create structured, maintainable code with real-world applications.
#include <iostream>
#include <vector>
using namespace std;
class Student {
private:
string name;
int id;
public:
Student(string n, int i) : name(n), id(i) {}
void display() { cout << "ID: " << id << ", Name: " << name << endl; }
};
Intermediate Project Categories
Management Systems
Object-oriented applications
File Operations
Data persistence projects
Data Structures
Implementing core structures
Algorithms
Problem-solving implementations
πΉ Bank Account Management System
The Bank Account Management System is an object-oriented simulation of core banking operations
using classes and methods. It models account entities with attributes like Account Holder,
Account Number, and Balance, supporting transactions such as deposit() and
withdraw(). For instance, John Doe's account (12345) starts with $1000,
updates to $1500 after a $500 deposit, and adjusts to $1300 after a
$200 withdrawal. This system demonstrates encapsulation, transaction logging, and balance validation,
providing a scalable foundation for financial software development.
#include <iostream>
#include <string>
using namespace std;
class BankAccount {
private:
string accountHolder;
int accountNumber;
double balance;
public:
BankAccount(string name, int accNum, double initialBalance) {
accountHolder = name;
accountNumber = accNum;
balance = initialBalance;
}
void deposit(double amount) {
if(amount > 0) {
balance += amount;
cout << "Deposited $" << amount << ". New balance: $" << balance << endl;
}
}
void withdraw(double amount) {
if(amount > 0 && amount <= balance) {
balance -= amount;
cout << "Withdrawn $" << amount << ". New balance: $" << balance << endl;
} else {
cout << "Insufficient funds or invalid amount!" << endl;
}
}
void displayInfo() {
cout << "Account Holder: " << accountHolder << endl;
cout << "Account Number: " << accountNumber << endl;
cout << "Balance: $" << balance << endl;
}
};
int main() {
BankAccount account("John Doe", 12345, 1000.0);
account.displayInfo();
account.deposit(500);
account.withdraw(200);
account.displayInfo();
return 0;
}
Sample Output:
Account Holder: John Doe
Account Number: 12345
Balance: $1000
Deposited $500. New balance: $1500
Withdrawn $200. New balance: $1300
πΉ Simple Linked List Implementation
A Simple Linked List Implementation creates a fundamental linear data structure where nodes
store data and point to the next element. Each node contains a value and a pointer, forming a chain
that allows dynamic memory allocation and efficient insertions/deletions compared to arrays. This implementation
demonstrates core concepts like traversal, node creation, and memory management, serving as a building block for
more complex structures like stacks, queues, or graphs. Itβs essential for understanding pointers, recursion, and
algorithmic efficiency in C++ or low-level programming.
#include <iostream>
using namespace std;
class Node {
public:
int data;
Node* next;
Node(int value) {
data = value;
next = nullptr;
}
};
class LinkedList {
private:
Node* head;
public:
LinkedList() {
head = nullptr;
}
void insert(int value) {
Node* newNode = new Node(value);
newNode->next = head;
head = newNode;
cout << "Inserted " << value << endl;
}
void display() {
Node* current = head;
cout << "List: ";
while(current != nullptr) {
cout << current->data << " -> ";
current = current->next;
}
cout << "NULL" << endl;
}
void deleteValue(int value) {
if(head == nullptr) return;
if(head->data == value) {
Node* temp = head;
head = head->next;
delete temp;
cout << "Deleted " << value << endl;
return;
}
Node* current = head;
while(current->next != nullptr && current->next->data != value) {
current = current->next;
}
if(current->next != nullptr) {
Node* temp = current->next;
current->next = current->next->next;
delete temp;
cout << "Deleted " << value << endl;
}
}
};
int main() {
LinkedList list;
list.insert(10);
list.insert(20);
list.insert(30);
list.display();
list.deleteValue(20);
list.display();
return 0;
}
πΉ File-Based Contact Book
The File-Based Contact Book is a practical application that stores and retrieves contact
information using file operations. It allows users to add, view, edit, and delete contacts, persisting
data in text or binary files for long-term storage. By leveraging functions like fopen(),
fwrite(), and fread(), it ensures data durability across sessions. This system teaches
file I/O, data serialization, and basic CRUD operations, making it a foundational project for understanding how
applications manage persistent data in desktop or embedded systems.
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
struct Contact {
string name;
string phone;
string email;
};
class ContactBook {
private:
vector<Contact> contacts;
string filename;
public:
ContactBook(string file) : filename(file) {
loadContacts();
}
void addContact() {
Contact newContact;
cout << "Enter name: ";
cin.ignore();
getline(cin, newContact.name);
cout << "Enter phone: ";
getline(cin, newContact.phone);
cout << "Enter email: ";
getline(cin, newContact.email);
contacts.push_back(newContact);
saveContacts();
cout << "Contact added successfully!" << endl;
}
void displayContacts() {
if(contacts.empty()) {
cout << "No contacts found!" << endl;
return;
}
cout << "\n--- Contact List ---" << endl;
for(size_t i = 0; i < contacts.size(); i++) {
cout << i+1 << ". " << contacts[i].name << endl;
cout << " Phone: " << contacts[i].phone << endl;
cout << " Email: " << contacts[i].email << endl << endl;
}
}
void saveContacts() {
ofstream file(filename);
for(const auto& contact : contacts) {
file << contact.name << "|" << contact.phone << "|" << contact.email << endl;
}
file.close();
}
void loadContacts() {
ifstream file(filename);
string line;
while(getline(file, line)) {
Contact contact;
size_t pos1 = line.find('|');
size_t pos2 = line.find('|', pos1 + 1);
contact.name = line.substr(0, pos1);
contact.phone = line.substr(pos1 + 1, pos2 - pos1 - 1);
contact.email = line.substr(pos2 + 1);
contacts.push_back(contact);
}
file.close();
}
};
int main() {
ContactBook book("contacts.txt");
int choice;
do {
cout << "\n1. Add Contact\n2. Display Contacts\n3. Exit\n";
cout << "Enter choice: ";
cin >> choice;
switch(choice) {
case 1: book.addContact(); break;
case 2: book.displayContacts(); break;
case 3: cout << "Goodbye!" << endl; break;
default: cout << "Invalid choice!" << endl;
}
} while(choice != 3);
return 0;
}