0% found this document useful (0 votes)
20 views7 pages

Samu

Hi

Uploaded by

harshadpowar2212
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views7 pages

Samu

Hi

Uploaded by

harshadpowar2212
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Introduction :-

A Student Management System (SMS) is a software


application designed to manage and organize student-related
data efficiently. In this project, we implement the system
using Object-Oriented Programming (OOP) principles in C+
+. The system stores student information, assigns them to
courses, manages their grades, and provides functionalities to
view and update these records.

Code:-
#include <iostream>
#include <unordered_map>
#include <vector>
#include <string>
using namespace std;

// Student class
class Student {
private:
int studentID;
string name;
int age;
unordered_map<string, int> courses; // Stores course names and marks

public:
// Constructor to initialize student details
Student(int id, string name, int age) : studentID(id), name(name), age(age) {}

// Add a course with optional marks (default 0)


void addCourse(const string& courseName, int marks = 0) {
courses[courseName] = marks;
}

// Update marks for a specific course


void updateMarks(const string& courseName, int marks) {
if (courses.find(courseName) != courses.end()) {
courses[courseName] = marks;
} else {
cout << courseName << " not found for " << name << ".\n";
}
}

// Print student details


void display() const {
cout << "ID: " << studentID << ", Name: " << name
<< ", Age: " << age << ", Courses: [";
for (const auto& course : courses) {
cout << course.first << ": " << course.second << " ";
}
cout << "]\n";
}
// Get the student ID (used for lookup)
int getID() const {
return studentID;
}
};

// Course class
class Course {
private:
string courseName;
vector<Student*> enrolledStudents;

public:
// Constructor to initialize course name
Course(const string& name) : courseName(name) {}

// Enroll a student in the course


void enrollStudent(Student* student) {
enrolledStudents.push_back(student);
student->addCourse(courseName); // Automatically add course to the
student
}

// List all students enrolled in the course


void listStudents() const {
cout << "Students enrolled in " << courseName << ":\n";
for (const auto& student : enrolledStudents) {
student->display();
}
}
};

// StudentManagementSystem class
class StudentManagementSystem {
private:
unordered_map<int, Student> students; // Store students by ID

public:
// Add a new student
void addStudent(const Student& student) {
if (students.find(student.getID()) == students.end()) {
students[student.getID()] = student;
cout << "Student " << student.getID() << " added successfully.\n";
} else {
cout << "Student with ID " << student.getID() << " already exists.\n";
}
}

// View details of a specific student


void viewStudent(int studentID) const {
auto it = students.find(studentID);
if (it != students.end()) {
it->second.display();
} else {
cout << "Student with ID " << studentID << " not found.\n";
}
}

// Update marks for a specific student and course


void updateStudentMarks(int studentID, const string& courseName, int
marks) {
auto it = students.find(studentID);
if (it != students.end()) {
it->second.updateMarks(courseName, marks);
} else {
cout << "Student with ID " << studentID << " not found.\n";
}
}

// List all students in the system


void listAllStudents() const {
if (students.empty()) {
cout << "No students registered.\n";
} else {
for (const auto& pair : students) {
pair.second.display();
}
}
}
};

// Main function to demonstrate the system


int main() {
// Create an instance of StudentManagementSystem
StudentManagementSystem sms;

// Create students
Student s1(1, "Alice", 20);
Student s2(2, "Bob", 22);

// Add students to the system


sms.addStudent(s1);
sms.addStudent(s2);

// Create courses
Course math("Mathematics");
Course science("Science");

// Enroll students in courses


math.enrollStudent(&s1);
science.enrollStudent(&s2);

// Update student marks


sms.updateStudentMarks(1, "Mathematics", 85);

// View student details


sms.viewStudent(1);

// List all students


sms.listAllStudents();
// List students enrolled in Mathematics
math.listStudents();

return 0;
}

Output:-

Reference:-

JavatPoint:- www.javatpoint.com
GeekForGeeks:- www.geeksforgeeks.com

You might also like