0% found this document useful (0 votes)
14 views4 pages

25 - 10 - 2024 - Lab 5 OOP

Uploaded by

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

25 - 10 - 2024 - Lab 5 OOP

Uploaded by

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

[Lab05] [OOP]

Create a project named Q1 and classes Person, Student, Course, and Enrollment as described below:

Class: Person (Base Class)

• Attributes:
o id: A unique identifier for the person (e.g., "P01").
o name: The name of the person (e.g., "John").
• Methods:
o entryData(): Returns a string "Add Person: id - name".
o printData(): Returns a string "Person: id - name".

Class: Student (Inherits from Person)

• Attributes:
o Inherited Attributes:
§ id: Inherited from Person.
§ name: Inherited from Person.
o New Attribute:
§ major: The major or department of the student (e.g., "CS" for Computer Science).
• Methods:
o entryData(): Overrides the entryData() method from Person. Returns a string "Add
Student: id - name - major".
o printData(): Overrides the printData() method from Person. Returns a string "Student:
id - name - major".

Class: Course

• Attributes:
o code: A unique course code (e.g., "C101").
o title: The title of the course (e.g., "Data Structures").
o credits: The number of credits the course is worth (e.g., 3).
• Methods:
o entryData(): Returns a string "Add Course: code - title - credits".
o printData(): Returns a string "Course: code - title - credits".

Class: Enrollment

• Attributes:
o studentId: The ID of the student enrolled in the course (e.g., "S01").
o courseCode: The code of the course in which the student is enrolled (e.g., "C101").
o grade (optional): The grade the student has received in the course (e.g., "A", "B", or ""). This
attribute might be left as null or "Not Graded" if the course hasn't been graded yet.
• Methods:
o entryData(): Returns a string "Enroll Student: id - course code - [optional
grade]".
o printData(): Returns a string "Enrollment: studentId - courseCode - [optional
grade]".
The Input:

• The first line contains a positive integer T (1 ≤ T ≤ 100), which is the number of test cases.
• The next T lines contain:
1. S id name major, when the line starts with the string "S", the program will add a new
Student to the list and print out the string "Add Student: id - name - major".
2. C code title credits, when the line starts with the string "C", the program will add a new
Course to the list and print out the string "Add Course: code - title - credits".
3. E id courseCode [optional grade], when the line starts with the string "E", the program
will enroll the Student with the given id in the Course with the specified courseCode and
print out the string "Enroll Student: id – courseCode - grade".
4. Clear, when the line contains only the string "Clear", the program will remove all Students,
Courses, and Enrollments and print out the string "* Remove all".
5. Print, when the line contains only the string "Print", the program will print out the
information of all Students, Courses, and Enrollments as shown in the sample.
6. GetStudents, when the line contains only the string "GetStudents", the program will print
out the information of all Students as shown in the sample.
7. GetCourses, when the line contains only the string "GetCourses", the program will print out
the information of all Courses as shown in the sample.
8. GetEnrollments, when the line contains only the string "GetEnrollments", the program will
print out the information of all Enrollments as shown in the sample.
9. GetStudentCourses id, when the line starts with the string "GetStudentCourses", the
program will print out the courses that the Student with the given id is enrolled in, as shown
in the sample.

Sample Input 1
input output
4 Add Student: S01 - John - CS
S S01 John CS Add Course: C101 - DataStructures - 3
C C101 DataStructures 3 Enroll Student: S01 - C101 - Not Graded
E S01 C101 ---Print---
Print Student: S01 - John - CS
Course: C101 - DataStructures - 3
Enrollment: S01 - C101 - Not Graded

Sample Input 2
input output
7 Add Student: S02 - Alice - Math
S S02 Alice Math Add Student: S03 - Bob - Physics
S S03 Bob Physics Add Course: C202 - Algebra - 4
C C202 Algebra 4 Add Course: C303 - Calculus - 3
C C303 Calculus 3 Enroll Student: S02 - C202 - 2
E S02 C202 2 Enroll Student: S03 - C303 - Not Graded
E S03 C303 ---Print---
Print Student: S02 - Alice - Math
Student: S03 - Bob - Physics
Course: C202 - Algebra - 4
Course: C303 - Calculus - 3
Enrollment: S02 - C202 - 2
Enrollment: S03 - C303 - Not Graded
Sample Input 3
input output
7 Add Student: S04 - Charlie - Chemistry
S S04 Charlie Chemistry Add Course: C404 - OrganicChemistry - 3
C C404 OrganicChemistry 3 Enroll Student: S04 - C404 - Not Graded
E S04 C404 ---Print---
Print Student: S04 - Charlie - Chemistry
GetStudents Course: C404 - OrganicChemistry - 3
GetCourses Enrollment: S04 - C404 - Not Graded
GetStudentCourses S04 ---GetStudents---
Student: S04 - Charlie - Chemistry
---GetCourses---
Course: C404 - OrganicChemistry - 3
---GetStudentCourses---
Course: C404 - OrganicChemistry - 3

Sample Input 4
input output
5 Add Student: S05 - Daisy - Literature
S S05 Daisy Literature Add Course: C505 - ModernPoetry - 2
C C505 ModernPoetry 2 Enroll Student: S05 - C505 - Not Graded
E S05 C505 * Remove all
Clear ---Print---
Print Empty

Sample Input 5
input output
7 Add Student: S06 - Emma - Biology
S S06 Emma Biology Add Course: C606 - Evolution - 3
C C606 Evolution 3 Add Course: C707 - Genetics - 4
C C707 Genetics 4 Enroll Student: S06 - C606 - Not Graded
E S06 C606 Enroll Student: S06 - C707 - Not Graded
E S06 C707 ---GetEnrollments---
GetEnrollments Enrollment: S06 - C606 - Not Graded
GetStudentCourses S06 Enrollment: S06 - C707 - Not Graded
---GetStudentCourses---
Course: C606 - Evolution - 3
Course: C707 - Genetics - 4

---end—

You might also like