Design and implement a Course object that models courses off

Design and implement a Course object that models courses offered at NAU. Courses should be initialized with a short name (e.g., CS126), a number of credits, a start time, and an end time. Include a method that will return True if two course times overlap, and False if they do not.

Solution

class Course

{                

                  int credits;

                  int sH;         //Start time hours part

                  int sM;        // Start time minutes part

                  int eH;        // End time hours part

                  int eM;       // End time minutes part

                  Course(int c=0, sH=0, sM=0, eH=0, eM=0)

                  {

                                    this.credits = c;

                                    this.sH = sH;

                                    this.sM = sM;

                                    this.eH = eH;

                                    this.M = eM;

                  }

                  bool overlap(Course c1, Course c2)

                  {

                                    int s1,s2,e1,e2;

                  s1 = c1.sH*100+c2.sM;    //concatenate hours and minutes

                                    e1 = c1.eH*100+c1.eM;

                                    s2 = c2.sH*100+c2.sM;

                                    e2 = c2.eH*100+c2.eM;

                                   

                                    if(s1 <= s2)      //If c1 starts before c2

                                    {

                                                      if(s2 <= e1)

                                                      {

                                                                        return true;

                                                      }

                                                      else

                                                      {

                                                                        return false;

                                                      }

                                    }

                                    else

                                    {

                                                      if(s1 <= e2)

                                                      {

                                                                        return true;

                                                      }

                                                      else

                                                      {

                                                                        return false;

                                                      }

                                    }

                  }

};

int main()

{

                  Course courses;

                  Course CS126(10, 9, 45, 10, 45);   // object initialized - CS126- 10 credits – 9:45 to 10:45

                  Course CS127(12, 10, 00, 11, 15);

                  bool result = courses.overlap(CS126, CS127);

}

Design and implement a Course object that models courses offered at NAU. Courses should be initialized with a short name (e.g., CS126), a number of credits, a s
Design and implement a Course object that models courses offered at NAU. Courses should be initialized with a short name (e.g., CS126), a number of credits, a s

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site