Aims

This assignment aims to establish a basic familiarity with C++ classes. The assignment introduce increasingly object-based, C++ style of solution to a problem.

General Requirements

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.

Objectives

On completion of these tasks you should be able to:

  • code and run C++ programs using the development environment.
  • make effective use of the on-line documentation system that supports the development environment.
  • code programs using C++ in a hybrid style (procedural code using instances of simple classes) and in a more object-based style.
  • manipulate string data.

Tasks:

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.

  • push_back(const Subject &): pushes a subject object at the back of the linked list.
  • front(): returns the address of the front node of the linked list. pop_front(): pops the front node of the linked list.
  • findSubject(const std::string &): gets a subject code (as an argument) and find the subject record in the linked list.
  • Other necessary member functions. Implement the member functions of class SubjectList in the file Subject.cpp.

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.

  • push_back(const Subject &): pushes a subject object at the back of the linked list.
  • front(): returns the address of the front node of the linked list. pop_front(): pops the front node of the linked list
  • findStudent(int): gets a student number (as an argument) and finds the student record in the linked list.
  • Other necessary member functions.

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.

  • push_back(const Subject &): pushes a subject object at the back of the linked list.
  • front(): returns the address of the front node of the linked list. pop_front(): pops the front node of the linked list.
  • Other necessary member functions.

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:

  • loadSubjects(const char *): loads subject records from a given text file (as an argument) and stores them into the subject linked list. See the testing file subjects.txt for the details.
  • loadStudents(const char *): loads student records from a given text file (as argument) and stores them into the student linked list. See the testing file students.txt for the details.
  • loadEnrolment(const char *): loads Enrolment records from a given text file (as argument) and stores them into the enrolment linked list. See the testing file enrolments.txt for the details.
  • displaySubjects(): displays all subjects in the linked list. displayStudents(): displays all students in the linked list.
  • addEnrolments(): gets input data for enrolments and stores them into the enrolment linked list.
  • searchStudentInfo(): gets student numbers and displays their number, name, address and email; then display all the subjects the students enrolled.
  • searchSubjectInfo(): gets subject code and displays their code, title, and credit; then displays all the students’ details who enrolled in those subjects.
  • doAdmin(): displays a menu and gets input choice, then call the member functions to perform the actions.
  • Other necessary member functions.

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.

Testing:

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.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.