Question: / / Online C + + compiler to run C + + program online #include #include #include #include #include #include / / For time functions
Online C compiler to run C program online
#include
#include
#include
#include
#include
#include For time functions
#include
class CustomerTask
public:
int taskID;
std::string taskName;
int arrivalTime;
int waitTime;
int startTime;
int periodTime;
std::string priority;
CustomerTaskint id std::string name, int arrival, int period, std::string p
: taskIDid taskNamename arrivalTimearrival waitTime periodTimeperiod priorityp startTime
if priority "Important"
thisarrivalTime ;
else if priority "VIP"
thisarrivalTime ;
std::string getFormattedTimeint minutes
int hours minutes ;
int mins minutes ;
std::stringstream ss;
ss std::setw std::setfill hours : std::setw std::setfill mins;
return ssstr;
void printTaskInfo
std::cout "Task ID: taskID Task Name: taskName Arrival Time: getFormattedTimearrivalTime
Wait Time: waitTime minutes, Start Time: startTime getFormattedTimestartTime : "Not served"
Period Time: periodTime minutes, Priority: priority std::endl;
;
class Compare
public:
bool operatorCustomerTask& t CustomerTask& t
return tstartTime tstartTime;
;
class Bank
private:
std::priorityqueue, Compare tasks;
public:
void addTask
int id period;
std::string name, priority, arrivalTimeStr;
std::cout "Enter task ID: ;
std::cin id;
std::cout "Enter task name: ;
std::cin name;
std::cout "Enter arrival time format HH:MM: ;
std::cin arrivalTimeStr;
std::cout "Enter period time: ;
std::cin period;
std::cout "Enter priority NormalImportantVIP: ;
std::cin priority;
Parse the input time in HH:MM format
int hours, minutes;
if sscanfarrivalTimeStrcstrd:d &hours, &minutes hours hours minutes minutes
std::cout "Invalid arrival time format. Please use HH:MM
;
return;
int arrivalTime hours minutes;
if arrivalTime arrivalTime
std::cout "Invalid arrival time. Must be between AM and PM exclusive
;
return;
CustomerTask taskid name, arrivalTime, period, priority;
tasks.pushtask;
void addNTasksint n
std::vector newTasks;
for int i ; i n; i
int id i ;
std::string name "Task" std::tostringid;
int arrival rand; Random time between AM and PM
int period rand; Random time between and minutes
std::string priority rand "Important" : rand "VIP" : "Normal";
CustomerTask taskid name, arrival, period, priority;
newTasks.pushbacktask;
std::sortnewTasksbegin newTasks.end Compare;
for auto& task : newTasks
tasks.pushtask;
void rearrangeQueue
std::vector tempTasks;
while tasks.empty
CustomerTask task tasks.top;
tasks.pop;
task.waitTime ;
task.startTime task.arrivalTime task.waitTime;
tempTasks.pushbacktask;
for auto& task : tempTasks
tasks.pushtask;
void printTaskInfo
std::priorityqueue, Compare tempTasks tasks;
while tempTasks.empty
CustomerTask task tempTasks.top;
tempTasks.pop;
task.printTaskInfo;
int totalWaitTime
int total ;
std::priorityqueue, Compare tempTasks tasks;
while tempTasks.empty
CustomerTask task tempTasks.top;
tempTasks.pop;
total task.waitTime;
return total;
int timeNeededToFinishAllTasks
int total ;
std::priorityqueue, Compare tempTasks tasks;
while tempTasks.empty
CustomerTask task tempTasks.top;
tempTasks.pop;
total task.periodTime;
int tasksNotCompleted
int count ;
std::priorityqueue, Compare tempTasks tasks;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
