Please send questions to
st10@humboldt.edu .
/*--------------------------------------------------------
Header file for class Course with NO explicitly-declared
destructor, copy constructor, or overloaded assignment
operator.
created by: Sharon Tuttle
last modified: 12-12-03
---------------------------------------------------------*/
#include <string>
#include "Student.h"
#include "Prof.h"
using namespace std;
const int ENROLLMENT_MAX = 30;
class Course
{
public:
// constructors
//
// assumption: when a course is first created,
// no students are enrolled in it.
Course();
Course(string cNum, string cName);
Course(string cNum, string cName, Prof instr);
// copy constructor
// destructor
// accessors
string get_courseName() const;
string get_courseNum() const;
int get_numEnrolled() const;
Student* get_enrolled() const;
Prof get_instructor() const;
// mutators
//
// assumption: users can only change numEnrolled
// and enrolled by enrolling, removing
// students from the course.
void set_courseNum(string new_cNum);
void set_courseName(string new_cName);
void set_instructor(Prof new_instr);
// overloaded operators
bool operator ==(const Course& rightHandCourse) const;
// other methods
//-----
// Contract: Student -> bool
// Purpose: try to add Student st to enrolled array for
// the calling Course. If numEnrolled ==
// ENROLLMENT_MAX, st cannot be added,
// and false is returned. Otherwise, st is
// added to the enrolled array (as its last element),
// and numEnrolled increases by one.
//
// Examples: if Course c1 has c1.numEnrolled == ENROLLMENT_MAX,
// and if st1 is a Student instance, then
// c1.enroll(st1) == false
// if Course c1 has c1.numEnrolled == 2
// and if st3 is a Student instance, then
// c1.enroll(st3) == true
// c1.numEnrolled == 3
// c2.enrolled[2] == st3
//-----
bool enroll(Student st);
//-----
// Contract: Student -> bool
// Purpose: try to remove Student st from enrolled array for
// the calling Course. If a Student equivalent
// to st cannot be found in enrolled, then returns
// false and nothing is changed. If such an
// equivalent st can be found, the first instance
// of such a Student will be removed from enrolled,
// the numEnrolled will be decreased by 1, and
// true will be returned.
//
// Examples: if Course c1 has enrolled NOT containing
// a Student equivalent to st1, where
// st1 is a Student instance, then
// c1.remove(st1) == false
// if Course c2 has c2.numEnrolled == 29
// and st1 has an equivalent instance in c2's
// enrolled array, then:
// c2.remove(st1) == true
// c2.numEnrolled == 28
// c2.enrolled has one fewer element (one fewer
// st1-equivalent Student)
//-----
bool remove(Student st);
//-----
// Contract: void -> void
// Purpose: print a roll report for the calling Course
//
// Examples: for Prof p1("Tuttle", "Sharon", "M.", "Dr.", ...)
// and Student s1("Jones", "Anna", 3)
// Student s2("Smith", "Joe", 3)
// Student s3("Nguyen", "Dian", 3)
// and Course c1("CS 131", "Intro to CS", p1);
// c1.enroll(s1);
// c1.enroll(s2);
// c1.enroll(s3);
// Then c1.printRoll() should produce:
//
// Class Roll for CS 131 - Intro to CS:
//
// Instructor: Dr. Sharon M. Tuttle
// Enrollment: 3
// 1. Anna Jones
// 2. Joe Smith
// 3. Dian Nguyen
//------------------------------------------------------------
void printRoll() const;
//-----
// Contract : courseAvg : void -> double
// Purpose : compute and return the course average
// by averaging the enrolled Students'
// current averages. If a student's
// current average is computed as -1,
// do not include it in the course
// average (and only divide by the
// number of students with non-neg-1
// averages). If no students have non-neg-1
// averages, return a course average of -1.
//
// Examples: for Student s1("Jones", "Anna", 3)
// with grades 100, 80, 75,
// Student s2("Smith", "Joe", 3)
// with no grades
// Student s3("Nguyen", "Dian", 3)
// with grades 60, 80, 90
// and Course c1("CS 131", "Intro to CS", p1);
// c1.enroll(s1);
// c1.enroll(s2);
// c1.enroll(s3);
// Then c1.courseAvg() == (approx) 80.83333
//
// For Course c2("CS 0", "Empty");
// c2.courseAvg() == -1
//
// For Course c3("CS 1", "Almost empty");
// Student s4("Johnson", "Ann", 0);
// Student s5("Jimson", "Benny", 0);
// Student s6("Judd", "Ashley", 3);
// c3.enroll(s4);
// c3.enroll(s5);
// c3.enroll(s6);
// then c3.courseAvg() == -1
//-----------------------------------------------------------
double courseAvg() const;
private:
// member variables
string courseNum;
string courseName;
int numEnrolled;
Student *enrolled;
Prof instructor;
};