This assignment aims to establish a basic familiarity with C++ classes. The assignment introduce increasingly object-based, C++ style of solution to a problem.
You should observe the common principles of OO programming when you design your classes.
You should make proper documentation and implementation comments in your codes where they are necessary.
Logical structures and statements are properly used for specific purposes.
On completion of these tasks you should be able to:
In this assignment, you will design and implement classes that handle students’ enrolments by using the following UML diagrams (ID means unique identifier). See image.
Define a class Subject in a file Subject.h that contains data members listed in the UML diagrams above. Define constructors (such as default constructor, initialization constructors, and copy constructor if necessary) and other member functions to access (set and get values) private data members. Implement the member functions in a file Subject.cpp.
Define a class SubjectNode in the file Subject.h that contains two data members: A Subject object and a pointer that points to another SubjectNode object. Define constructors and other member functions to access private data members of the class SubjectNode. Implement the member functions in the file Subject.cpp.
Define a class SubjectList (as a single linked list) in the file Subject.h that contains two data members: A SubjectNode pointer points to the front of the linked list and a SubjectNode pointer points to the back of the linked list. Define constructors, destructor (clear the dynamic memory), and following member functions to maintain the linked list.
Define a class Student in a file Student.h that contains data members listed in the UML diagrams above. Define constructors (such as default constructor, initialization constructors, and copy constructor if necessary) and other member functions to access (set and get values) private data members. Implement the member functions in a file Student.cpp.
Define a class StudentNode in the file Student.h that contains two data members: A Student object and a pointer that points to another StudentNode object. Define constructors and other member functions to access private data members of the class StudentNode. Implement the member functions in the file Student.cpp.
Define a class StudentList (as a single linked list) in the file Student.h that contains two data members: A StudentNode pointer points to the front of the linked list and a StudentNode pointer points to the back of the linked list. Define constructors, destructor (clear the dynamic memory), and following member functions to maintain the linked list.
Implement the member functions of class StudentList in the file Student.cpp.
Define a class Enrolment in a file Enrolment.h that contains data members listed in the UML diagram above. Define constructors (such as default constructor, initialization constructors, and copy constructor if necessary) and other member functions to access (set or get values) private data members. Implement the member functions in a file Enrolment.cpp.
Define a class EnrolmentNode in the file Enrolment.h that contains two data members: A Enrolment object and a pointer that points to another EnrolmentNode object. Define constructors and other member functions to access private data members of the class EnrolmentNode. Implement the member functions in the file Enrolment.cpp.
Define a class EnrolmentList (as a single linked list) in the file Enrolment.h that contains two data members: An EnrolmentNode pointer points to the front of the linked list and an EnrolmentNode pointer points to the back of the linked list. Define constructors, destructor (clear the dynamic memory), and following member functions to maintain the linked list.
Implement the member functions of class EnrolmentList in the file Enrolment.cpp.
Define a class Admin in a file Admin.h that contains three data members: linked lists of subjects, students and enrolments. Define the following member functions in the file Admin.h:
Implement member functions in a file Admin.cpp.
Define a main() function in a file main.cpp which takes 3 text file names from command line arguments. In the main() function, you will check the number of arguments to make sure 3 file names have been passed. You will define an Admin object, then load data from three text files into three linked lists, display subjects and students that loaded, then display menu (by call the member function doAdmin()). More details can be found in the Testing section.
Note: Do not put statement “using namespace std;” in the head files.
In the working directory on banshee, you can compile the program by
CC –o ass1 main.cpp Admin.cpp Subject.cpp Student.cpp Enrolment.cpp
Or to make it simple, you can compile the program by
CC –o ass1 *.cpp
To run the program, you should pass the file names to the main() by
ass1 subject-file-name student-file-name enrolment-file-name
You can download the test files subjects.txt, students.txt and enrolments.txt from this site.
Note: Do not define constant files’ names inside the source code.
You can use command bcheck on banshee to check if there is any memory leak by
bcheck ass1 subject-file-name student-file-name enrolment-file-name
In the following testing example, red data denote input data from keyboard.
$ ass1 subjects.txt students.txt enrolments.txt
Subjects are:
CSCI103,Algorithms and Problem Solving,6
CSCI114,Procedural Programming,6
CSCI124,Applied Programming,6
CSCI204,Object and Generic Programming in C++,6
CSCI222,System Development,6
CSCI235,Databases,6
CSCI315,Database Design and Implementation,6
CSCI321,Project,12
Students are:
1234567,Alice Montage,1 Northfield Ave Wollongong,am12@xxx.edu.au
1234568,Bob Smith,102 Princess Highway Wollongong,bs36@xxx.edu.au
1234569,Cart Dong,48 Moore Street Northfield Wollongong,cd28@xxx.edu.au
1. Add new enrolments.
2. Search student's information.
3. Search subject's information.
0. Exit.
Please choose: 1
When the choice is 1, the program will get input of enrolments until student’s number is 0 (zero). For each student, the program will get the subjects the student enrolled in until the subject code is 0 (zero).
Input a student's number (0-quit): 123
Wrong student number.
Input a student's number (0-quit): 1234569
Input a subject code (0-quit): 103
Wrong subject code.
Input a subject code (0-quit): CSCI103
Input year: 2010
Input session (1-Autumn, 2-Spring, 3-Summer, 0-Annual): 1
Input mark: 90.5
Input a subject code (0-quit): CSCI114
Input year: 2010
Input session (1-Autumn, 2-Spring, 3-Summer, 0-Annual): 1
Input mark: 92.8
Input a subject code (0-quit): CSCI203
Wrong subject code.
Input a subject code (0-quit): CSCI124
Input year: 2010
Input session (1-Autumn, 2-Spring, 3-Summer, 0-Annual): 2
Input mark: 88
Input a subject code (0-quit): 0
Input a student's number (0-quit): 1234567
Input a subject code (0-quit): CSCI321
Input year: 2012
Input session (1-Autumn, 2-Spring, 3-Summer, 0-Annual): 0
Input mark: 75
Input a subject code (0-quit): 0
Input a student's number (0-quit): 0
1. Add new enrolments.
2. Search student's information.
3. Search subject's information.
0. Exit.
Please choose: 2
When the choice is 2, the program will get a student’s number, display the student’s information and subjects enrolled by that student. The function will continue until input number is 0 (zero).
Input a student's number (0-quit): 123 Wrong student number.
Input a student's number (0-quit): 1234567
1234567, Alice Montage, 1 Northfield Ave Wollongong, am12@xxx.edu.au Enrolled subjects:
CSCI103, Algorithms and Problem Solving, 6
CSCI114, Procedural Programming, 6
CSCI124, Applied Programming, 6
CSCI204, Object and Generic Programming in C++, 6
CSCI222, System Development, 6
CSCI235, Databases, 6
CSCI315, Database Design and Implementation, 6
CSCI321, Project, 12
Input a student's number (0-quit): 0
1. Add new enrolments.
2. Search student's information.
3. Search subject's information.
0. Exit.
Please choose: 3
When the choice is 3, the program will get a subject code, and display the subject’s information and all the students who enrolled in the subject. The function will continue until input code is 0 (zero).
Input a subject's code (0-quit): CSCI103
CSCI103, Algorithms and Problem Solving, 6 Enrolled students:
1234567, Alice Montage, 1 Northfield Ave Wollongong, am12@xxx.edu.au
1234568, Bob Smith, 102 Princess Highway Wollongong, bs36@xxx.edu.au
1234569, Cart Dong, 48 Moore Street Northfield Wollongong, cd28@xxx.edu.au
Input a subject's code (0-quit): CSCI111
Wrong subject code.
Input a subject's code (0-quit): 0
1. Add new enrolments.
2. Search student's information.
3. Search subject's information.
0. Exit.
Please choose: 0
When 0 is selected, the program will call destructors of the objects automatically and terminated.