⬅ Previous Next ➡

Projects & Practice

Projects & Practice (C++ Hands-on)
  • This section focuses on hands-on C++ projects to apply OOP concepts in real-world style programs.
  • Projects covered: Student Management, Banking System, Library System, File-based apps, and a Final OOP Project.
  • Key concepts used: classes/objects, constructors, encapsulation, inheritance, polymorphism, STL, and file handling.

1) Student Management System (Mini Project)

  • Features:
    • Add student (id, name, marks)
    • Display all students
    • Search by id
  • Use: vector (STL) + class.
#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Student {
public:
    int id;
    string name;
    float marks;

    void input() {
        cin >> id >> name >> marks;
    }

    void show() const {
        cout << id << " " << name << " " << marks << endl;
    }
};

int main() {
    vector<Student> st;
    int n = 2;

    cout << "Enter id name marks for " << n << " students:\n";
    for (int i = 0; i < n; i++) {
        Student s;
        s.input();
        st.push_back(s);
    }

    cout << "\nAll Students:\n";
    for (const auto &s : st) {
        s.show();
    }

    int key;
    cout << "\nSearch id: ";
    cin >> key;

    bool found = false;
    for (const auto &s : st) {
        if (s.id == key) {
            cout << "Found: ";
            s.show();
            found = true;
            break;
        }
    }

    if (!found) cout << "Not found\n";
    return 0;
}

2) Banking System (Mini Project)

  • Features:
    • Create account (name + balance)
    • Deposit, Withdraw, Balance
    • Basic validation (no negative, no over-withdraw)
  • Use: encapsulation (private data + public methods).
#include <iostream>
#include <string>
using namespace std;

class BankAccount {
private:
    string name;
    double balance;

public:
    BankAccount(string n, double b) : name(n), balance(b) {}

    void deposit(double amt) {
        if (amt > 0) balance += amt;
    }

    void withdraw(double amt) {
        if (amt > 0 && amt <= balance) balance -= amt;
    }

    void show() const {
        cout << "Name: " << name << " Balance: " << balance << endl;
    }
};

int main() {
    BankAccount acc("Sourav", 1000);

    acc.deposit(500);
    acc.withdraw(300);
    acc.show();

    return 0;
}

3) Library Management System (Mini Project)

  • Features:
    • Add book (id, title)
    • Issue/Return (status)
    • Display all books
  • Use: class + vector + simple status flag.
#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Book {
public:
    int id;
    string title;
    bool issued;

    Book(int i, string t) : id(i), title(t), issued(false) {}
};

int main() {
    vector<Book> books;
    books.push_back(Book(1, "C++"));
    books.push_back(Book(2, "DSA"));

    // Issue book id=1
    for (auto &b : books) {
        if (b.id == 1) b.issued = true;
    }

    cout << "Books List:\n";
    for (const auto &b : books) {
        cout << b.id << " " << b.title << " Status: " << (b.issued ? "Issued" : "Available") << endl;
    }

    return 0;
}

4) File-based Application (Save & Load Records)

  • Use files to store data permanently.
  • Simple format: write text lines (CSV-like).
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {
    // Save data
    ofstream out("students.txt", ios::app);
    if (!out.is_open()) return 0;

    int id = 1;
    string name = "Sourav";
    float marks = 88.5f;

    out << id << "," << name << "," << marks << endl;
    out.close();

    // Read data
    ifstream in("students.txt");
    if (!in.is_open()) return 0;

    string line;
    while (getline(in, line)) {
        cout << line << endl;
    }
    in.close();

    return 0;
}

5) Final OOP Project (Recommended)

  • Final Project Idea: OOP + File + STL Based System
  • Choose one:
    • Advanced Student ERP Module (students, fees, attendance)
    • Library System (books, members, issue/return, fine)
    • Banking System (accounts, transactions, reports)
  • Recommended modules:
    • Login (basic)
    • CRUD operations (add, view, update, delete)
    • Search and filter
    • File persistence (save/load)
    • Reports (summary, totals)

6) Quick Notes

  • Start with console-based CRUD first, then add file saving.
  • Use vector for lists, map for fast search (id → record).
  • Keep data members private and use methods for access (encapsulation).
  • Use inheritance/polymorphism only when it truly fits (avoid unnecessary complexity).
⬅ Previous Next ➡