Assignment 1 Description PDF
Assignment 1 Description PDF
● Notes
■ You must implement your program using C++ classes
● Member functions
○ Constructor: Initializes id, name, and sets up
defaults.
○ Getters: getId(), getName(), and
getEnrolledCourses() return respective details
(const).
○ takesCourse(Course): Checks if the student is
enrolled in the course.
○ takeCourse(Course): Adds a course if not
enrolled and within credit limit.
○ dropCourse(Course): Removes a course from
enrollment.
○ printDetails(): Displays student details and
enrolled courses.
UML diagram of Course class
● Member variables
○ Store id, name, credits, and students securely.
○ students should store IDs of enrolled students.
○ credits should be an integer representing course credits
● Member functions
○ Constructor: Initializes id, name, and credits.
○ Getter functions: getId(), getName(),
getCredits() - must be const and return respective
values without modifications.
○ hasStudent(): Check if a student is already enrolled.
Return true if found.
○ addStudent(): Add a student to the students list. Return
true if the student was successfully added.
○ dropStudent(): Remove a student from the students
list.
○ printDetails(): Print course details, including id,
name, credits, and list of enrolled student IDs.
UML diagram of LMS class
● Member variables
○ Store name, students, and courses securely
(i.e., private members)
○ Use a vector to store array of instances from
Student and Course classes.
● Member functions
○ Constructor: Initialize LMS with a name.
○ addStudent(): Add a Student object to the
students list.
○ addCourse(): Add a Course object to the
courses list.
○ addStudentToCourse(): Link a student to a course
by updating both the students and courses lists.
Perform necessary checks to ensure validity.
○ printDetails(): Display the LMS name, the list
of students, and the list of courses with their
details.
Example main() function
// Main Program
int main() {
string nameLMS;
getline(cin,nameLMS);
LMS myLMS(nameLMS);
int number_students;
cin>>number_students;
//Add students
for(int i=0;i<number_students;i++){
int id;
string name;
cin>>id>>name;
Student s1(id, name);
myLMS.addStudent(s1);
}
LMS
instance
Student
instance
Example main() function
// Main Program
// Add courses
int number_courses;
cin>>number_courses;
for(int i=0;i<number_courses;i++){
string id,name;
int credit;
cin>>id>>name>>credit;
Course c1(id, name, credit);
myLMS.addCourse(c1);
}
Course
instance
Example main() function
// Main Program
// Enroll students in courses
int n;
cin >> n;
for(int i=0;i<n;i++){
int student_id;
string course_id;
cin>>student_id>>course_id;
myLMS.addStudentToCourse(student_id, course_id);
}
// Print LMS details
myLMS.printDetails();
return 0;
}
Test case 1 (sample)
Input: Output:
SmallLMS LMS Name: SmallLMS
1 Students:
1 Alice Student ID: 1, Name: Alice
1 Enrolled Courses: 101~
101 Math 3 Courses:
1 Course ID: 101, Name: Math, Credits: 3
1 101 Enrolled Students: 1
main.cpp
myLMS.addStudent(s1);
Course.cpp cin>>student_id>>course_id;
myLMS.addStudentToCourse(student_id, course_id);
}
// Print LMS details
LMS.h
myLMS.printDetails();
return 0;
}
LMS.cpp