Stage 1
Program Specification
A program is required for use by a lecturer in which objects representing students are to be used.
(a) Define a class named student.
It should have three member variables, one of which holds the surname of student, one the integer enrolment number and one floating point total mark.
Its constructor function should announce that a student is enrolling. It should prompt for and accept the surname of the student and the enrolment number from the keyboard and set the total mark to zero.
Four other member functions are required.
The first should return the surname of the student.
The second should return the enrolment number.
The third should return the total mark.
The fourth should accept a new mark and update the total mark when a new test is taken.
Its destructor function should announce that a student is leaving, display the surname of the student and the final total mark.
(b) Write a short main function (Main program)
This function should test the class student in which an auto object of class student is created. The class student should be thoroughly tested by applying the member functions to the object and passing known data where applicable.
(c) Explain how your main function has tested all the features of the class student.
Write an explanation of how the features of the student class have been tested by the main function. i.e. called all its member functions showing that they have set, accessed and/or amended the member variables correctly. Include any test data used, either entered at the keyboard or written into the main function and the results produced.
Stage 2
Background to the problem
A college offers a range of courses, each of which has a name. Students may be enrolled on courses.
The course we are interested in has only one student enrolled at a time, but when one student leaves another one can be accepted. (In a more realistic simulation an array of student objects would be declared and a new student could be received into the class if there were room for them in the class, i.e. space in the array.)
When a student is recruited for the course they are allocated an enrolment number. A running total of their marks is kept as tests are taken. When the student leaves a note is made of their enrolment number and the total mark.
Program Specification
Following on from stage 1 you are now required to modify your code.
A program is required which will simulate several students in turn enrolling on the course.
(a) Define an aggregate class named course with three attributes.
The first should be a member variable recording the name of the course.
The second should be a pointer to a potential dynamic object of class student. This object will be created when a new student is accepted on to the course and destroyed when they leave.
The third is a flag recording whether a student is enrolled or not. The class student has the same definition as in Stage 1
The course constructor function should create a course object with no student enrolled. It should ask the program user for the name of the course.
The course destructor function should display the course name, and if a student is still enrolled their enrolment number and total mark.
One course member function should create a new student and set the flag to 1 and another course member function should deal with the student leaving the course. It should display the student name and total mark, destroy the student object and reset the flag to 0.
Five more course member functions are required.
The first should return the name of the course.
The second should return the value of the flag, eg 1 if a student is enrolled and 0 if not.
The third should return the name of the student.
The fourth should accept the student's new mark and add it to their running total.
The fifth should return the student's total mark.
(b) A simulation program (a main program) should be written which should include the definition of the class student and the definition of the new class course.
In the main function one auto object of class course should be created and given a name.
Then the user should repeatedly be able to specify whether a student has been recruited, left or has completed a test.
A new student can only be recruited if it is vacant, in which case the user should be asked for the new student's name.
A student can only leave the course if there is a student enrolled in which case the user should be informed of the departing student's name, enrolment number and their final mark.
A new mark can only be accepted if there is a student enrolled.
Messages should be displayed if the user makes an error.
When the program finishes the name of any student still occupying the course and their total mark should be displayed.
Code, run and debug your program.