Samu
Samu
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) {}
// Course class
class Course {
private:
string courseName;
vector<Student*> enrolledStudents;
public:
// Constructor to initialize course name
Course(const string& name) : courseName(name) {}
// 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";
}
}
// Create students
Student s1(1, "Alice", 20);
Student s2(2, "Bob", 22);
// Create courses
Course math("Mathematics");
Course science("Science");
return 0;
}
Output:-
Reference:-
JavatPoint:- www.javatpoint.com
GeekForGeeks:- www.geeksforgeeks.com