QuestionQuestion

Instructions

1. Draw a UML diagram:
We are going to create a small inheritance hierarchy of monitor objects. There will be an abstract Monitor class, and two concrete sub-classes: the GPAMonitor class will track the students whose GPA falls below a minimum threshold, and the FWMonitor class will track the students who fail or withdraw from more than a preset number of courses.
We will implement the Observer design pattern with Monitor objects as the observers and the Control object (and indirectly its students) as the subject. Each type of concrete monitor will store of a collection of logs: the GPAMonitor object will document which students have a GPA below the preset minimum, and the FWMonitor object will document which students have failed or withdrawn from a number of courses higher than another preset value. Each log will be formatted as a string containing the student id and either the GPA or number of failed and withdrawn (FW) courses. Every time a student object is created and added to our student audit system, the monitor objects (the observers) will be notified of a change in that student by the Control object (the subject). The monitor objects will examine the student to see if it fits their criteria (either a low GPA or a high number of FW courses). If the student does fit the criteria, the monitor object will create a corresponding log and add it to its log collection. All the logs from both monitor objects will be printed to the screen at the end of the program.
To implement this, we will create a pure virtual update() function in the Monitor class, and the appropriate behaviour will be implemented in the concrete sub-classes. The UML diagram that you submit should reflect the design of the entire program for this assignment.

2. Modify the List class
You will need to use a collection class for each Student object to store Course objects or object pointers. If you did not implement the List class in a previous assignment, you can adapt the Array class from the tutorials.

To prepare your program to work with the new Monitor classes, you will make the following changes to your List class (or Array, if you don’t have a List class):
• implement the computeGPA() function that returns the average of all course grades (between 0 and
12) for the student, excluding the withdrawals; you will use the function prototype:
float computeGPA();
• implement the computeNumFW() function that returns the number of courses that the student has failed or from which the student has withdrawn; you will use the function prototype:
int computeNumFW();

3. Modify the Student and Course classes
To work with the new Monitor classes, you will make the following changes to the Student and Course
classes.
You will add the following two member functions to the Student class:
• a computeGPA() function that returns the GPA for this student, using a function implemented in a previous step
• a computeNumFW() function that returns the number of FW courses for this student, using a function implemented in a previous step
You will also modify the Student print function to print the student’s GPA.
You may need to add getter functions in the Student class for the student id and in the Course class for the course grade.

4. Implement the Monitor classes
You will create a new Monitor abstract class that serves as the base class for the observers in the Observer design pattern. This class will contain the following:
• a data member that stores a collection of logs; you can use a STL vector of strings for this collection; we used the vector class in our in-class examples on polymorphism
• a pure virtual update() function that has the following prototype: void update(Student*);
• a printLogs() member function that prints the collection of logs to the screen
You will create a new GPAMonitor concrete class that derives from the Monitor class. This class will contain the following:
• a data member that represents the minimum threshold for GPAs to be flagged; when the GPAMonitor
object detects a student with a GPA below this minimum threshold, it will create a new log
• a constructor
• an implementation of the update(Student* stu) function that checks if the given student’s GPA is below the minimum threshold; if it is, then the function will create a new log documenting the student id and the corresponding GPA, and it will add the new log to its collection
You will create a new FWMonitor concrete class that derives from the Monitor class. This class will contain the following:
• a data member that represents the threshold for flagging a student’s number of FW courses; when the FWMonitor object detects a student with a number of FW courses greater than this threshold, it will create a new log
• a constructor
• an implementation of the update(Student* stu) function that checks if the given student’s number of FW courses is greater than the threshold; if it is, then the function will create a new log documenting the student id and the corresponding number of FW courses, and it will add the new log to its collection

5. Modify the Control class
You will modify the Control to serve as the subject in the Observer pattern, and work with the new
Monitor classes as follows:
• add a data member to store a collection of Monitor object pointers; you can use a STL vector for this
• implement a new member function to notify the monitor objects when a new student is created; the function prototype will be: void notify(Student* newStu); this function will loop over the collection of monitors and call the update() function on each monitor object, using the new student as parameter; this will ensure that, if the new student meets the criteria of any of the monitor objects, new logs will be created to flag the student
NOTE: DO NOT simply store two monitor objects! The Observer pattern requires a collection that can store any number of observers.
• modify the Control constructor so that:
◦ it dynamically creates a new GPAMonitor object with a minimum bound of 3.0, and it adds this new object to the collection of monitors
◦ it dynamically creates a new FWMonitor object with a threshold of 2, and it adds this new object to the collection of monitors
• modify the Control destructor so that it loops over every monitor object in its collection and calls the
printLogs() function on it; the destructor should also deallocate the memory for the monitor objects
• modify the launch() function so that it calls the notify() function when a new student is added to storage

6. Test the program
• You will provide the in.txt file with sufficient datafill for a minimum of 15 different students, each with at least 5 different courses. The nature of the data and its ordering in the file must thoroughly test your program. If parts of your program cannot be adequately tested because of inadequate datafill, you could lose 100% of the marks for some marking components.
• Check that the student and course information is correct when the storage is printed out.
• Check that the monitor logs are correct when they are printed out at the end of the program.
• Make sure that all dynamically allocated memory is explicitly deallocated when it is no longer used. Use valgrind to check for memory leaks.

Constraints
• your program must follow correct encapsulation principles, including the separation of control, UI, and entity object functionality
• do not use any classes, containers, or algorithms from the C++ standard template library (STL), except in the two instances explicitly permitted for this assignment
• do not use any global variables or any global functions other than main()
• do not use structs; use classes instead
• objects must always be passed by reference, not by value
• your classes must be thoroughly documented in every class definition
• all basic error checking must be performed
• existing functions must be reused everywhere possible

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

#include "Control.h"
#include "GPAMonitor.h"
#include "FWMonitor.h"

Control::Control() {
    /**
    * aasignment 3
    * modify the Control constructor so that:
    * ◦ it dynamically creates a new GPAMonitor object with
    * a minimum bound of 3.0, and it adds this
    * new object to the collection of monitors
    * ◦ it dynamically creates a new FWMonitor object with a
    * threshold of 2, and it adds this new object
    * to the collection of monitors
    */
    Monitor * gpa = new GPAMonitor(3.0);
    collection.push_back(gpa);
    Monitor * fw = new FWMonitor(2);
    collection.push_back(fw);
}

Control::~Control() {
    /**
    * aasignment 3
    * modify the Control destructor so that it loops over every monitor
    * object in its collection and calls the
    * printLogs() function on it; the destructor should also
    * deallocate the memory for the monitor objects
    */
    for (Monitor * elem : collection) {
       elem->printLogs();
       delete elem;
    }

}

void Control::launch() {
    // use the View object to display the main menu and read the user’s selection, until the user chooses to exit   
    Student* studentPtr;
    Course* coursePtr;
    int numStu = 0;
    int menuSelection;
    int courseCode, grade, term;
    string instructor;

    while (1) {
       menuSelection = view.mainMenu();
       if (menuSelection == 0)
            break;
       else if (menuSelection == 1) { // if required by the user :
            // use the View object to read in all the student and course information,
            // create a new dynamically allocated Student object,         
            studentPtr = new Student(view.getStudentID());

            while (1) {
                view.readCourse(courseCode, grade, term, instructor);
                if (courseCode == 0) {
                   break;
                }

                // containing the corresponding dynamically allocated Course objects
                coursePtr = new Course(courseCode, grade, term, instructor);

                studentPtr->addCourse(coursePtr);
            }
            // add the new student to storage using existing functions
            storage.addStu(studentPtr);
            /**
             * assignment #3
             * modify the launch() function so that it calls the notify()
             * function when a new student is added to
             * storage
             */
            notify(studentPtr);
            ++numStu;
       }
    }...

By purchasing this solution you'll be able to access the following files:
Solution.zip.

$107.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available C-Family Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats