Question: C++ I only need help with task e. However, I am also including full prompt just in case you need that to understand task e.

C++

I only need help with task e.

However, I am also including full prompt just in case you need that to understand task e.

Thank you

Task E. Overlapping time slots?

Add a new function

bool timeOverlap(TimeSlot ts1, TimeSplot 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.)

struct Time {

int h;

int m;

};

Lets write a printer function that prints a Time value on the screen in HOURS:MINUTES format:

void printTime(Time time) {

cout << time.h << ":" << time.m;

}

printTime({8, 10}); // was illegal

return {17, 45}; // was illegal

Task A. Simple functions for time

Create a new program time.cpp. (Copy the struct Time declaration in your program, it should be placed before main() function.)

Implement two new functions:

int minutesSinceMidnight(Time time);

int minutesUntil(Time earlier, Time later);

The first function should return the number of minutes from 0:00AM until time.

The second function should receive two Time arguments earlier and later and report how many minutes separate the two moments. For example, when passing 10:30AM and 1:40PM:

minutesUntil( {10, 30}, {13, 40} )

// ==> should return 190 minutes

(A caveat: If the earlier moment of time happens to be after the later moment of time, report a negative number of minutes. Although its not difficult to achieve this if your implementation for the first function is correct.)

For testing purposes, implement a simple user interface:

$ ./time

Enter first time: 10 30

Enter second time: 13 40

These moments of time are X and Y minutes after midnight.

The interval between them is Z minutes.

Task B. Making it more interesting

Add a new function to your program time.cpp:

Time addMinutes(Time time0, int min);

The function should create and return a new moment of time that is min minutes after time0. Example:

addMinutes({8, 10}, 75)

// ==> should return {9, 25}

(We will not test how your function behaves if the new returned time will be on the next day, feel free to assume that it will remain withing the same day, ? 23:59.)

Adjust the main function for testing this function. Feel free to add additional tests to check the correctness of your code.

Scheduling time slots for a movie theater

Lets add a few more datatypes:

enum Genre {ACTION, COMEDY, DRAMA, ROMANCE, THRILLER};

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

};

For testing purposes, we would want to make functions printMovie(Movie m) and printTimeSlot(Timeslot ts). Lets write the first of them:

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)";

}

Task C. TimeSlot ending time and printTimeSlot

In the same program time.cpp, implement your own printing function printTimeSlot(TimeSlot ts). It should make output in the following format:

Back to the Future COMEDY (116 min) [starts at 9:15, ends by 11:11]

The ending time is the starting time + movie duration.

Write main function that defines at least five time slots

morning, daytime, and evening defined previously,

plus add a couple of your own time slots with some of your favorite movies (their duration time can be found in IMDB).

The program output should look like:

$ ./time

Back to the Future COMEDY (116 min) [starts at 9:15, ends by 11:11]

Black Panther ACTION (134 min) [starts at 12:15, ends by 14:29]

Black Panther ACTION (134 min) [starts at 16:45, ends by 18:59]

-- your time slot #1 --

-- your time slot #2 --

-- ... --

When defining your own time slots, please make sure they end before midnight, 23:59, so the ending time does not show the next day.

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.

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!