Mini projects are the best way to apply everything you’ve learned: variables, loops, functions, file handling, exception handling, debugging, and good coding standards. They help you build complete, working programs that feel like real software.
This module covers two excellent mini projects:
- Calculator
- Student Management System (Advanced version with file handling)
Perfect for your C++ course website — Calculator for Class 5–10 students, and Student Management System for Class 11–12 and BS level.
Calculator Project
A simple console-based calculator that performs basic and scientific operations. Great first project to practice functions, switch-case, loops, and logic building.
Features (Build in Stages)
Stage 1: Basic Calculator (Class 5–8)
- Addition, Subtraction, Multiplication, Division
- Handle division by zero
Stage 2: Enhanced Calculator (Class 9–10)
- Modulus (%), Power (^), Square root
- Memory functions (M+, MR, MC)
Stage 3: Scientific Calculator (Class 11–12)
- Trigonometric functions (sin, cos, tan)
- Logarithm, Factorial
Full Code: Basic + Enhanced Calculator
/*
* Project: Simple Calculator
* Author: Your Name
* Description: Console-based calculator with basic and advanced operations
* Features: +, -, *, /, %, ^, sqrt, memory
*/
#include <iostream>
#include <cmath> // For pow(), sqrt()
#include <iomanip> // For setprecision
using namespace std;
double memory = 0.0; // Global memory variable
void showMenu() {
cout << "\n=== CALCULATOR ===\n";
cout << "1. Add (+)\n";
cout << "2. Subtract (-)\n";
cout << "3. Multiply (*)\n";
cout << "4. Divide (/)\n";
cout << "5. Modulus (%)\n";
cout << "6. Power (^)\n";
cout << "7. Square Root\n";
cout << "8. Memory Add (M+)\n";
cout << "9. Memory Recall (MR)\n";
cout << "10. Memory Clear (MC)\n";
cout << "11. Exit\n";
cout << "Choose operation: ";
}
int main() {
int choice;
double num1, num2, result;
cout << fixed << setprecision(2); // Show 2 decimal places
do {
showMenu();
cin >> choice;
if (choice >= 1 && choice <= 7) {
cout << "Enter two numbers (or one for sqrt): ";
cin >> num1;
if (choice != 7) cin >> num2;
}
switch (choice) {
case 1:
result = num1 + num2;
cout << num1 << " + " << num2 << " = " << result << endl;
break;
case 2:
result = num1 - num2;
cout << num1 << " - " << num2 << " = " << result << endl;
break;
case 3:
result = num1 * num2;
cout << num1 << " * " << num2 << " = " << result << endl;
break;
case 4:
if (num2 == 0) {
cout << "Error: Division by zero!\n";
} else {
result = num1 / num2;
cout << num1 << " / " << num2 << " = " << result << endl;
}
break;
case 5:
if ((int)num2 == 0) {
cout << "Error: Modulus by zero!\n";
} else {
cout << (int)num1 << " % " << (int)num2 << " = "
<< (int)num1 % (int)num2 << endl;
}
break;
case 6:
result = pow(num1, num2);
cout << num1 << " ^ " << num2 << " = " << result << endl;
break;
case 7:
if (num1 < 0) {
cout << "Error: Square root of negative number!\n";
} else {
cout << "sqrt(" << num1 << ") = " << sqrt(num1) << endl;
}
break;
case 8:
cout << "Enter number to add to memory: ";
cin >> num1;
memory += num1;
cout << "Added to memory. Current memory: " << memory << endl;
break;
case 9:
cout << "Memory value: " << memory << endl;
break;
case 10:
memory = 0.0;
cout << "Memory cleared!\n";
break;
case 11:
cout << "Thank you for using Calculator!\n";
break;
default:
cout << "Invalid choice! Try again.\n";
}
} while (choice != 11);
return 0;
}Enhancements You Can Add
- Use functions for each operation.
- Add exception handling for invalid inputs.
- GUI version using libraries (later in course).
- History of calculations (store in vector).
Learning Outcomes
- switch-case
- Functions and modular code
- Error handling
- Loops and menu systems
Student Management System (Full Mini Project)
This is an advanced project combining file handling, functions, structures, menus, search/update/delete, and good coding standards.
Features
- Add new student
- View all students
- Search by roll number
- Update student details
- Delete student
- Save to binary file (“students.dat”)
- Load from file on startup
Full Code with Comments and Standards
/*
* Project: Student Management System
* Description: Complete console-based system using binary file handling
* Features: Add, View, Search, Update, Delete, File persistence
*/
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const string FILENAME = "students.dat";
// Student structure with good naming
struct Student {
int roll_number;
string student_name;
int age;
float marks;
};
// Function prototypes
void add_student();
void view_all_students();
void search_student(int roll);
void update_student(int roll);
void delete_student(int roll);
void show_menu();
int main() {
int choice;
cout << "=== STUDENT MANAGEMENT SYSTEM ===\n";
do {
show_menu();
cout << "Enter your choice: ";
cin >> choice;
cin.ignore(); // Clear buffer
int roll;
switch (choice) {
case 1:
add_student();
break;
case 2:
view_all_students();
break;
case 3:
cout << "Enter roll number to search: ";
cin >> roll;
search_student(roll);
break;
case 4:
cout << "Enter roll number to update: ";
cin >> roll;
update_student(roll);
break;
case 5:
cout << "Enter roll number to delete: ";
cin >> roll;
delete_student(roll);
break;
case 6:
cout << "Thank you! Goodbye.\n";
break;
default:
cout << "Invalid choice! Please try again.\n";
}
} while (choice != 6);
return 0;
}
void show_menu() {
cout << "\n--- MAIN MENU ---\n";
cout << "1. Add New Student\n";
cout << "2. View All Students\n";
cout << "3. Search Student\n";
cout << "4. Update Student\n";
cout << "5. Delete Student\n";
cout << "6. Exit\n";
}
// Add student - append to file
void add_student() {
ofstream out_file(FILENAME, ios::binary | ios::app);
if (!out_file) {
cout << "Error opening file!\n";
return;
}
Student s;
cout << "Enter Roll Number: ";
cin >> s.roll_number;
cin.ignore();
cout << "Enter Name: ";
getline(cin, s.student_name);
cout << "Enter Age: ";
cin >> s.age;
cout << "Enter Marks (0-100): ";
cin >> s.marks;
// Basic validation
if (s.marks < 0 || s.marks > 100) {
cout << "Invalid marks! Setting to 0.\n";
s.marks = 0;
}
out_file.write((char*)&s, sizeof(s));
out_file.close();
cout << "Student added successfully!\n";
}
// View all students
void view_all_students() {
ifstream in_file(FILENAME, ios::binary);
if (!in_file || in_file.peek() == EOF) {
cout << "No records found or file error!\n";
return;
}
Student s;
cout << "\n" << setw(10) << "Roll"
<< setw(20) << "Name"
<< setw(8) << "Age"
<< setw(10) << "Marks" << endl;
cout << string(50, '-') << endl;
while (in_file.read((char*)&s, sizeof(s))) {
cout << setw(10) << s.roll_number
<< setw(20) << s.student_name
<< setw(8) << s.age
<< setw(10) << fixed << setprecision(2) << s.marks << endl;
}
in_file.close();
}
// Search by roll number
void search_student(int search_roll) {
ifstream in_file(FILENAME, ios::binary);
if (!in_file) {
cout << "File error!\n";
return;
}
Student s;
bool found = false;
while (in_file.read((char*)&s, sizeof(s))) {
if (s.roll_number == search_roll) {
cout << "\nStudent Found:\n";
cout << "Roll: " << s.roll_number << endl;
cout << "Name: " << s.student_name << endl;
cout << "Age: " << s.age << endl;
cout << "Marks: " << s.marks << endl;
found = true;
break;
}
}
if (!found) {
cout << "Student with roll " << search_roll << " not found!\n";
}
in_file.close();
}
// Update student
void update_student(int update_roll) {
fstream file(FILENAME, ios::binary | ios::in | ios::out);
if (!file) {
cout << "File error!\n";
return;
}
Student s;
bool found = false;
long pos;
while (file.read((char*)&s, sizeof(s))) {
pos = file.tellg() - sizeof(s); // Position before reading
if (s.roll_number == update_roll) {
cout << "Current Details:\n";
cout << "Name: " << s.student_name << " | Age: " << s.age
<< " | Marks: " << s.marks << endl;
cout << "\nEnter new details:\n";
cout << "New Name: ";
cin.ignore();
getline(cin, s.student_name);
cout << "New Age: ";
cin >> s.age;
cout << "New Marks: ";
cin >> s.marks;
file.seekp(pos);
file.write((char*)&s, sizeof(s));
cout << "Student updated successfully!\n";
found = true;
break;
}
}
if (!found) {
cout << "Student not found!\n";
}
file.close();
}
// Delete student (using temp file method)
void delete_student(int delete_roll) {
ifstream in_file(FILENAME, ios::binary);
ofstream temp_file("temp.dat", ios::binary);
if (!in_file) {
cout << "File error!\n";
return;
}
Student s;
bool found = false;
while (in_file.read((char*)&s, sizeof(s))) {
if (s.roll_number != delete_roll) {
temp_file.write((char*)&s, sizeof(s));
} else {
found = true;
}
}
in_file.close();
temp_file.close();
remove(FILENAME.c_str());
rename("temp.dat", FILENAME.c_str());
if (found) {
cout << "Student deleted successfully!\n";
} else {
cout << "Student not found!\n";
}
}Project Enhancements (For BS Level)
- Add password protection for admin.
- Sort students by marks/name.
- Calculate average, highest/lowest marks.
- Export to text/CSV file.
- Use classes instead of struct.
- Add exception handling.
- Input validation with loops.
Learning Outcomes
- File handling (binary)
- Structures and data persistence
- Menu-driven programs
- Search, update, delete algorithms
- Professional coding standards