Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Task D. Scheduling X after Y? Add a new function TimeSlot scheduleAfter(TimeSlot ts, Movie nextMovie); The function should produce and return a new TimeSlot for
Task D. Scheduling X after Y?
Add a new function
TimeSlot scheduleAfter(TimeSlot ts, Movie nextMovie);
The function should produce and return a new TimeSlot for the movie nextMovie, scheduled immediately after the time slot ts.
For example, if the movie scheduled in ts starts at 14:10 and lasts 120 minutes, then the time slot for the next movie should start at exactly 16:10.
Modify main function to test your code.
Here is the code to add the next function.
includeusing 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started