Demo Projects (Guided)
Step-by-step guided projects with features list, class design, flowcharts, and full working code.
Student Management System
š Features
- Add new student (name, roll, marks)
- View all students
- Search by roll number
- Update student marks
- Delete a student
- Save/load data from file
šļø Class Design
Class: Student āāā Attributes: name (string), rollNumber (int), marks (double) āāā Constructor: Student(name, roll, marks) āāā Methods: display(), getMarks(), setMarks(), getRoll() āāā Friend: operator<< for easy printing Class: StudentManager āāā Attributes: students (vector<Student>), filename (string) āāā Methods: addStudent(), viewAll(), searchByRoll() āāā Methods: updateMarks(), deleteStudent() āāā Methods: saveToFile(), loadFromFile()
š Flowchart
START
ā
ā¼
Load data from file
ā
ā¼
āāāāāāāāāāāāāāāāāāā
ā MAIN MENU ā
ā 1. Add Student ā
ā 2. View All ā
ā 3. Search ā
ā 4. Update Marks ā
ā 5. Delete ā
ā 6. Exit ā
āāāāāāāāāā¬āāāāāāāāā
ā
āāāāāā¼āāāāā
ā Choice? āāāāā 1 āāā Get name, roll, marks ā Add to vector ā Save
ā āāāāā 2 āāā Loop through vector ā Display each
ā āāāāā 3 āāā Get roll ā Linear search ā Display or "Not found"
ā āāāāā 4 āāā Search ā If found ā Get new marks ā Update ā Save
ā āāāāā 5 āāā Search ā If found ā Remove from vector ā Save
ā āāāāā 6 āāā Save to file ā EXIT
āāāāāāāāāāāš» Full Implementation
student_system.cpp
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
using namespace std;
class Student {
string name;
int rollNumber;
double marks;
public:
Student() : name(""), rollNumber(0), marks(0) {}
Student(string n, int r, double m) : name(n), rollNumber(r), marks(m) {}
int getRoll() const { return rollNumber; }
double getMarks() const { return marks; }
void setMarks(double m) { marks = m; }
void display() const {
cout << "Roll: " << rollNumber
<< " | Name: " << name
<< " | Marks: " << marks << endl;
}
string toFileString() const {
return name + "|" + to_string(rollNumber) + "|" + to_string(marks);
}
static Student fromFileString(const string& line) {
int p1 = line.find("|");
int p2 = line.find("|", p1 + 1);
string n = line.substr(0, p1);
int r = stoi(line.substr(p1 + 1, p2 - p1 - 1));
double m = stod(line.substr(p2 + 1));
return Student(n, r, m);
}
};
class StudentManager {
vector<Student> students;
string filename;
public:
StudentManager(string file) : filename(file) { loadFromFile(); }
void addStudent() {
string name;
int roll;
double marks;
cout << "Enter name: ";
cin.ignore();
getline(cin, name);
cout << "Enter roll number: ";
cin >> roll;
// Check duplicate
for (const auto& s : students) {
if (s.getRoll() == roll) {
cout << "Roll number already exists!" << endl;
return;
}
}
cout << "Enter marks: ";
cin >> marks;
students.push_back(Student(name, roll, marks));
saveToFile();
cout << "Student added successfully!" << endl;
}
void viewAll() const {
if (students.empty()) {
cout << "No students found." << endl;
return;
}
cout << "\n--- All Students (" << students.size() << ") ---" << endl;
for (const auto& s : students) s.display();
}
void searchByRoll() const {
int roll;
cout << "Enter roll number: ";
cin >> roll;
for (const auto& s : students) {
if (s.getRoll() == roll) {
cout << "\nStudent found:" << endl;
s.display();
return;
}
}
cout << "Student not found!" << endl;
}
void updateMarks() {
int roll;
double newMarks;
cout << "Enter roll number: ";
cin >> roll;
for (auto& s : students) {
if (s.getRoll() == roll) {
cout << "Current marks: " << s.getMarks() << endl;
cout << "Enter new marks: ";
cin >> newMarks;
s.setMarks(newMarks);
saveToFile();
cout << "Marks updated!" << endl;
return;
}
}
cout << "Student not found!" << endl;
}
void deleteStudent() {
int roll;
cout << "Enter roll number to delete: ";
cin >> roll;
for (int i = 0; i < students.size(); i++) {
if (students[i].getRoll() == roll) {
students[i].display();
cout << "Confirm delete? (y/n): ";
char ch;
cin >> ch;
if (ch == 'y' || ch == 'Y') {
students.erase(students.begin() + i);
saveToFile();
cout << "Student deleted!" << endl;
}
return;
}
}
cout << "Student not found!" << endl;
}
void saveToFile() {
ofstream file(filename);
for (const auto& s : students) {
file << s.toFileString() << endl;
}
file.close();
}
void loadFromFile() {
ifstream file(filename);
string line;
students.clear();
while (getline(file, line)) {
if (!line.empty()) {
students.push_back(Student::fromFileString(line));
}
}
file.close();
}
};
int main() {
StudentManager manager("students.txt");
int choice;
do {
cout << "\n===== STUDENT MANAGEMENT SYSTEM =====" << endl;
cout << "1. Add Student" << endl;
cout << "2. View All Students" << endl;
cout << "3. Search by Roll Number" << endl;
cout << "4. Update Marks" << endl;
cout << "5. Delete Student" << endl;
cout << "6. Exit" << endl;
cout << "Enter choice: ";
cin >> choice;
switch (choice) {
case 1: manager.addStudent(); break;
case 2: manager.viewAll(); break;
case 3: manager.searchByRoll(); break;
case 4: manager.updateMarks(); break;
case 5: manager.deleteStudent(); break;
case 6: cout << "Goodbye!" << endl; break;
default: cout << "Invalid choice!" << endl;
}
} while (choice != 6);
return 0;
}