Question: Task E. Overlapping time slots? Add a new function bool timeOverlap(TimeSlot ts1, TimeSlot ts2); The function should return true if the two time slots overlap,

Task E. Overlapping time slots?

Add a new function

bool timeOverlap(TimeSlot ts1, TimeSlot ts2); 

The function should return true if the two time slots overlap, otherwise return false. (Take into account the starting times of the time slots and the duration of the scheduled movies.)

Modify main function to test your code.

Hint: You may use minutesUntil to check which time slot is earlier, then find the how long is the interval between their starting times. They overlap if the movie duration is greater than the interval between the time slots starting times. Alternatively, converting times into minutes since midnight can be a good idea as well.

(By the way, if you want to be accurate, if one movie starts at 10:00 and lasts 90 minutes until 11:30, then it does not overlap with a movie that starts exactly at 11:30. However, they would overlap if the latter movie started one minute earlier, at 11:29.)

include using namespace std; enum Genre {ACTION, COMEDY, DRAMA, ROMANCE, THRILLER}; // struct for time type struct Time { int h; int m; }; struct Movie { string title; Genre genre; // only one genre per movie int duration; // in minutes }; struct TimeSlot { Movie movie; // what movie Time startTime; // when it starts }; // ----------------------------------------------------------------- // return number of minutes passed since midnight int minutesSinceMidnight(Time time) { return ( time.h * 60 ) + time.m; } // return number of minutes between two times int minutesUntil(Time earlier, Time later) { return ( ( ( later.h * 60 ) + later.m ) - ( ( earlier.h * 60 ) + earlier.m ) ); } // add minutes to time Time addMinutes(Time time0, int min) { time0.m = time0.m + min; if ( time0.m == 60 ) { time0.m = 0; time0.h = time0.h + 1; } else if ( time0.m > 60 ) { int hours = time0.m / 60; time0.m = time0.m - hours*60; time0.h = time0.h + hours; } if ( time0.h > 23 ) time0.h = time0.h - 24; return time0; } // function to print Time void printTime(Time time) { cout << time.h << ":" << time.m; } // function to print Movie void printMovie(Movie mv) { string g; switch (mv.genre) { case ACTION : g = "ACTION"; break; case COMEDY : g = "COMEDY"; break; case DRAMA : g = "DRAMA"; break; case ROMANCE : g = "ROMANCE"; break; case THRILLER : g = "THRILLER"; break; } cout << mv.title << " " << g << " (" << mv.duration << " min)"; } void printTimeSlot(TimeSlot ts) { printMovie(ts.movie); cout << " [starts at "; printTime(ts.startTime); cout << ", ends by "; Time endtime = addMinutes (ts.startTime, ts.movie.duration); printTime(endtime); cout << "]" << endl; } // ------------------------------------------------------------------ int main() { Movie movie1 = {"Back to the Future", COMEDY, 116}; Movie movie2 = {"Black Panther", ACTION, 134}; Movie movie3 = {"Blind", THRILLER , 111}; Movie movie4 = {"Dear John", DRAMA, 125}; TimeSlot morning = { movie1, { 9, 15} }; TimeSlot daytime = { movie2, {12, 15} }; TimeSlot evening = { movie2, {16, 45} }; TimeSlot night = { movie3, {17, 30} }; TimeSlot night1 = { movie4, {18, 44} }; printTimeSlot(morning); printTimeSlot(daytime); printTimeSlot(evening); printTimeSlot(night1); printTimeSlot(night1); return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!