Untitled

mail@pastecode.io avatar
unknown
plain_text
20 days ago
2.6 kB
2
Indexable
Never
#include "CourseRegistrationSystem.h"
#include <iostream>

void addCourse(std::vector<std::unique_ptr<Course>>& courses, const std::string& name, int minStudents, int maxStudents) {
    courses.push_back(std::make_unique<Course>(name, minStudents, maxStudents));
}

void addStudent(std::vector<std::unique_ptr<Student>>& students, const std::string& name) {
    students.push_back(std::make_unique<Student>(name));
}

void registerStudentForCourse(Student& student, Course& course) {
    if (student.registerCourse(&course)) {
        std::cout << student.getName() << " successfully registered for " << course.getName() << std::endl;
    } else {
        std::cout << student.getName() << " could not register for " << course.getName() << std::endl;
    }
}

void displayAvailableCourses(const std::vector<std::unique_ptr<Course>>& courses) {
    std::cout << "Available courses:" << std::endl;
    for (const auto& course : courses) {
        if (course->isAvailable()) {
            std::cout << course->getName() << " (" << course->getCurrentStudents() << "/" << course->getMaxStudents() << ")" << std::endl;
        }
    }
}


#ifndef COURSE_REGISTRATION_SYSTEM_H
#define COURSE_REGISTRATION_SYSTEM_H

#include "Course.h"
#include "Student.h"
#include <vector>
#include <memory>
#include <string>

void addCourse(std::vector<std::unique_ptr<Course>>& courses, const std::string& name, int minStudents, int maxStudents);
void addStudent(std::vector<std::unique_ptr<Student>>& students, const std::string& name);
void registerStudentForCourse(Student& student, Course& course);
void displayAvailableCourses(const std::vector<std::unique_ptr<Course>>& courses);

#endif // COURSE_REGISTRATION_SYSTEM_H

#include "CourseRegistrationSystem.h"

int main() {
    std::vector<std::unique_ptr<Course>> courses;
    std::vector<std::unique_ptr<Student>> students;

    // Add courses
    addCourse(courses, "Math 101", 5, 30);
    addCourse(courses, "Physics 101", 5, 30);
    addCourse(courses, "Chemistry 101", 5, 30);

    // Add students
    addStudent(students, "John Doe");
    addStudent(students, "Jane Smith");

    // Register students for courses
    registerStudentForCourse(*students[0], *courses[0]);
    registerStudentForCourse(*students[0], *courses[1]);
    registerStudentForCourse(*students[1], *courses[1]);

    // Display available courses
    displayAvailableCourses(courses);

    // Display courses registered by a student
    students[0]->displayCourses();
    students[1]->displayCourses();

    return 0;
}
Leave a Comment