Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Have to make a Scheduler.cpp and implement functions in the bottom. Scheduler.h and Scheduler-driver.cpp is given in the bottom. Please add comment codes so I

Have to make a Scheduler.cpp and implement functions in the bottom. Scheduler.h and Scheduler-driver.cpp is given in the bottom. Please add comment codes so I can understand whats going on. Thank you! C++

image text in transcribed

image text in transcribedimage text in transcribedimage text in transcribed

3 Driver file You have been provided with a simple driver file that parses commands from cin and calls relevant Scheduler functions. The first command it recognizes is print, which just calls printSchedule. The second command is add, which will add events to the schedule with schedule. The format for this command is: add EVENT from TIME1 to TIME2 where EVENT should be replaced by the name of the event, TIME1 with the start time, and TIME2 with the ending time. If the indicated time is not available (!isAvailable), the driver will print an error message (Scheduling conflict: not added), or it will print a notification that the change was successful (Added to schedule). The third command is cancel, which will remove events from the schedule with free. The format for this command is: cancel TIME where TIME should be replaced with the start time of the event to cancel. Both the add and cancel will print the modified schedule afterwards. The last command recognized by the driver is quit, which ends the program. The driver can also be exited with Ctrl-C. All commands (and event names) are case-insensitive. bool Scheduler::isAvailable (unsigned start, unsigned duration) const: returns whether the time period from time start to start + duration is free; times are considered free if they occur during a ScheduleNode with name == "FREE". Valid times are 0-99; the head Scheduler Node is considered to start at time 0, and the next node starts immediately after the previous node ends. Times beyond the Scheduler's length are not considered free. void Scheduler::schedule(const string& name, unsigned start, unsigned duration): schedule a new event with the given name and duration at a given time, making sure not to create an invalid schedule (e.g., length = 100, consecutive nodes with same name, or 0- length node). You may assume that the user has already called isAvailable on the start and duration. void Scheduler:: free (unsigned start): frees up the time associated with the event that starts at the given time (i.e., sets that time back to FREE), without creating an invalid schedule. Has no effect if the time is already free or no event starts at that time. void Scheduler::printSchedule() const: prints information for all of the events in the schedule, in the following format: TIME: NAME (DURATION) where TIME represents the start time of the event, NAME the event's name, and DURATION the length of the event. Note that there are two spaces after the colon and one before the open parenthesis. Scheduler::"Scheduler(): destroys the Scheduler, freeing all ScheduleNodes. You are not required to implement a copy constructor or copy assignment operator for the Scheduler. void ScheduleNode: :merge(ScheduleNode* other): (Optional) compares this ScheduleN- ode to its argument (which should be the next or previous node), and combines the two nodes into one with the same name where the length is the sum of the two original nodes. This function is not called by the driver and is totally optional, but you may find it helpful to implement this so that you can use it in other functions. #ifndef __SCHEDULER_H #define __SCHEDULER_H #include #include using namespace std; const unsigned DEFAULT_LENGTH = 100; const string FREE = "FREE"; class Scheduler; class ScheduleNode; class Scheduler private: ScheduleNode* head; unsigned length; public: Scheduler (unsigned len = DEFAULT_LENGTH) { length = len; head = new ScheduleNode (FREE, len); } bool isAvailable(unsigned start, unsigned duration) const; void schedule(const string& name, unsigned start, unsigned duration); void free (unsigned start); void print schedule() const; -Scheduler(); class ScheduleNode friend Scheduler; private: string name; unsigned length; ScheduleNode* prev; ScheduleNode* next; public: ScheduleNode(string name, unsigned len = 0) : name (name) { length = len; next = prev = nullptr; cout #include #include using namespace std; #include "scheduler.h" void makeUppercase(string& str) for (char& c: str) c = toupper(c); int main() Scheduler schedule; string cmd, opt; unsigned time, duration; schedule.print Schedule(); cin >> cmd; makeUppercase (cmd); while (cmd != "QUIT") if (cmd == "CANCEL") cin >> time; schedule. free(time); schedule.printSchedule(); else if (cmd == "ADD") time = duration = -1; string temp; //add EVENT from X to Y cin >> opt >> temp >> time >> temp >> duration; makeUppercase (opt); duration -= time; if (opt == FREE) cout > cmd; makeUppercase(cmd); return 0; 3 Driver file You have been provided with a simple driver file that parses commands from cin and calls relevant Scheduler functions. The first command it recognizes is print, which just calls printSchedule. The second command is add, which will add events to the schedule with schedule. The format for this command is: add EVENT from TIME1 to TIME2 where EVENT should be replaced by the name of the event, TIME1 with the start time, and TIME2 with the ending time. If the indicated time is not available (!isAvailable), the driver will print an error message (Scheduling conflict: not added), or it will print a notification that the change was successful (Added to schedule). The third command is cancel, which will remove events from the schedule with free. The format for this command is: cancel TIME where TIME should be replaced with the start time of the event to cancel. Both the add and cancel will print the modified schedule afterwards. The last command recognized by the driver is quit, which ends the program. The driver can also be exited with Ctrl-C. All commands (and event names) are case-insensitive. bool Scheduler::isAvailable (unsigned start, unsigned duration) const: returns whether the time period from time start to start + duration is free; times are considered free if they occur during a ScheduleNode with name == "FREE". Valid times are 0-99; the head Scheduler Node is considered to start at time 0, and the next node starts immediately after the previous node ends. Times beyond the Scheduler's length are not considered free. void Scheduler::schedule(const string& name, unsigned start, unsigned duration): schedule a new event with the given name and duration at a given time, making sure not to create an invalid schedule (e.g., length = 100, consecutive nodes with same name, or 0- length node). You may assume that the user has already called isAvailable on the start and duration. void Scheduler:: free (unsigned start): frees up the time associated with the event that starts at the given time (i.e., sets that time back to FREE), without creating an invalid schedule. Has no effect if the time is already free or no event starts at that time. void Scheduler::printSchedule() const: prints information for all of the events in the schedule, in the following format: TIME: NAME (DURATION) where TIME represents the start time of the event, NAME the event's name, and DURATION the length of the event. Note that there are two spaces after the colon and one before the open parenthesis. Scheduler::"Scheduler(): destroys the Scheduler, freeing all ScheduleNodes. You are not required to implement a copy constructor or copy assignment operator for the Scheduler. void ScheduleNode: :merge(ScheduleNode* other): (Optional) compares this ScheduleN- ode to its argument (which should be the next or previous node), and combines the two nodes into one with the same name where the length is the sum of the two original nodes. This function is not called by the driver and is totally optional, but you may find it helpful to implement this so that you can use it in other functions. #ifndef __SCHEDULER_H #define __SCHEDULER_H #include #include using namespace std; const unsigned DEFAULT_LENGTH = 100; const string FREE = "FREE"; class Scheduler; class ScheduleNode; class Scheduler private: ScheduleNode* head; unsigned length; public: Scheduler (unsigned len = DEFAULT_LENGTH) { length = len; head = new ScheduleNode (FREE, len); } bool isAvailable(unsigned start, unsigned duration) const; void schedule(const string& name, unsigned start, unsigned duration); void free (unsigned start); void print schedule() const; -Scheduler(); class ScheduleNode friend Scheduler; private: string name; unsigned length; ScheduleNode* prev; ScheduleNode* next; public: ScheduleNode(string name, unsigned len = 0) : name (name) { length = len; next = prev = nullptr; cout #include #include using namespace std; #include "scheduler.h" void makeUppercase(string& str) for (char& c: str) c = toupper(c); int main() Scheduler schedule; string cmd, opt; unsigned time, duration; schedule.print Schedule(); cin >> cmd; makeUppercase (cmd); while (cmd != "QUIT") if (cmd == "CANCEL") cin >> time; schedule. free(time); schedule.printSchedule(); else if (cmd == "ADD") time = duration = -1; string temp; //add EVENT from X to Y cin >> opt >> temp >> time >> temp >> duration; makeUppercase (opt); duration -= time; if (opt == FREE) cout > cmd; makeUppercase(cmd); return 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

3. An overview of the key behaviors is presented.

Answered: 1 week ago

Question

2. The model is credible to the trainees.

Answered: 1 week ago