Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Example File START winscp START putty CALL connect try_catch CALL login no_try_catch CALL Writerile no_try_catch RETURN THROW THROW END Note this file would then display
Example File START winscp START putty CALL connect try_catch CALL login no_try_catch CALL Writerile no_try_catch RETURN THROW THROW END Note this file would then display the following process list: winscp added to queue putty added to queue winscp calls connect putty calls login winscp calls writeFile putty login function returned winscp exception caught by connect function putty terminated due to unhandled exception Starter Code . Link You are provided a full templated Node class, Stack header file, and Queue header file. Again, you'll need to implement other classes (e.g. Executive class to run the show, a Process class to model a process. Overview You will create a mock CPU scheduler. Programs will get in a queue and wait for their turn to have some time in the processor. While a program is using the CPU it call do simple things like add a function to its call stack. Functions might return normally or throw exceptions. When functions throw exceptions, we'll need to pop calls off the call stack until something handles the exception, or the program crashes. You will need to implement a templated Queue and a Stack and design and implement any additional classes needed (e.g. an Executive class, Process class). Input from a file (name given at command-line) will dictate the order the programs are loaded into the queue and what any program is doing with its CPU time. File overview terminal The input file you receive at the command line will consist of the commands listed below. After each command is executed display appropriate output You may assume the files will be properly formatted with commands that can be executed in the order given. Details A new process created and added to the queue. All processes start with a "main" as their first function call. Print a message to the screen indicating which process was added to the queue. No mains are able to catch exceptions COMMAND START CALL sfunction name> chas try-catch?> The process at the front of the queue gets some CPU time and calls a function. This put that function on the call stack for that process. After the call is made, that process goes to the back of the line, with that call still on the top of its call stack. Print a message to the screen indicating which process called the function and what the name of the function is. RETURN The process at the front of the queue has the function at the top of its call-stack return. If the process has any functions left on the call-stack, put it at the back of the queue. Otherwise, if its main returns, simply remove it. Should a process end, display a message indicating this. Ut oh! The function of the process at the front of the queue just threw an exception! Pop calls off its call stack until you reach function that has a try-catch block OR you pop main off in which case you remove that process from the Queue and print " terminated due to unhandled exception." If the process caught the exception, print a message about the handling, "process>exception caught by ", and move the process to the back of the queue. This will be the last command in the file. This marks the end of command you have to process. Your program can exit once your process all preceding commands. THROW END Example File //Node.h #ifndef NODE_H #define NODE H template class Node { private: Tm_entry; Node* m_next; public: Node(T entry); TgetEntry() const; void setEntry(T entry); Node* getNext() const; void setNext (Node* next); }; #include "Node.cpp" #endif //Node.cpp template Node: : Node (T entry) { m_entry = entry; m next = nullptr; } template T Node::getEntry() const { return(m_entry); } template void Node::setEntry(T entry) { m_entry = entry; } template Node* Node::getNext() const { return(m_next); } template void Node::setNext (Node* next) { m next = next; } #ifndef QUEUE_H #define QUEUE_H #include #include "Node.h" template class Queue { private: Node* m_front; Node* m_back; public: Queue(); Queue (const Queue& orig); void operator= (const Queue& rhs); void enqueue (T entry); void dequeue(); T peekFront() const; bool isEmpty() const; }; #include "Queue.cpp" #endif #ifndef STACK H #define STACK H #include #include "Node.h" template class Stack { private: Node* m top; public: Stack(); Stack(const Stack& orig); void operator= (const Stack& rhs); void push(T entry); void pop(); T peek() const; bool isEmpty() const; }; #include "Stack.cpp" #endif Example File START winscp START putty CALL connect try_catch CALL login no_try_catch CALL Writerile no_try_catch RETURN THROW THROW END Note this file would then display the following process list: winscp added to queue putty added to queue winscp calls connect putty calls login winscp calls writeFile putty login function returned winscp exception caught by connect function putty terminated due to unhandled exception Starter Code . Link You are provided a full templated Node class, Stack header file, and Queue header file. Again, you'll need to implement other classes (e.g. Executive class to run the show, a Process class to model a process. Overview You will create a mock CPU scheduler. Programs will get in a queue and wait for their turn to have some time in the processor. While a program is using the CPU it call do simple things like add a function to its call stack. Functions might return normally or throw exceptions. When functions throw exceptions, we'll need to pop calls off the call stack until something handles the exception, or the program crashes. You will need to implement a templated Queue and a Stack and design and implement any additional classes needed (e.g. an Executive class, Process class). Input from a file (name given at command-line) will dictate the order the programs are loaded into the queue and what any program is doing with its CPU time. File overview terminal The input file you receive at the command line will consist of the commands listed below. After each command is executed display appropriate output You may assume the files will be properly formatted with commands that can be executed in the order given. Details A new process created and added to the queue. All processes start with a "main" as their first function call. Print a message to the screen indicating which process was added to the queue. No mains are able to catch exceptions COMMAND START CALL sfunction name> chas try-catch?> The process at the front of the queue gets some CPU time and calls a function. This put that function on the call stack for that process. After the call is made, that process goes to the back of the line, with that call still on the top of its call stack. Print a message to the screen indicating which process called the function and what the name of the function is. RETURN The process at the front of the queue has the function at the top of its call-stack return. If the process has any functions left on the call-stack, put it at the back of the queue. Otherwise, if its main returns, simply remove it. Should a process end, display a message indicating this. Ut oh! The function of the process at the front of the queue just threw an exception! Pop calls off its call stack until you reach function that has a try-catch block OR you pop main off in which case you remove that process from the Queue and print " terminated due to unhandled exception." If the process caught the exception, print a message about the handling, "process>exception caught by ", and move the process to the back of the queue. This will be the last command in the file. This marks the end of command you have to process. Your program can exit once your process all preceding commands. THROW END Example File //Node.h #ifndef NODE_H #define NODE H template class Node { private: Tm_entry; Node* m_next; public: Node(T entry); TgetEntry() const; void setEntry(T entry); Node* getNext() const; void setNext (Node* next); }; #include "Node.cpp" #endif //Node.cpp template Node: : Node (T entry) { m_entry = entry; m next = nullptr; } template T Node::getEntry() const { return(m_entry); } template void Node::setEntry(T entry) { m_entry = entry; } template Node* Node::getNext() const { return(m_next); } template void Node::setNext (Node* next) { m next = next; } #ifndef QUEUE_H #define QUEUE_H #include #include "Node.h" template class Queue { private: Node* m_front; Node* m_back; public: Queue(); Queue (const Queue& orig); void operator= (const Queue& rhs); void enqueue (T entry); void dequeue(); T peekFront() const; bool isEmpty() const; }; #include "Queue.cpp" #endif #ifndef STACK H #define STACK H #include #include "Node.h" template class Stack { private: Node* m top; public: Stack(); Stack(const Stack& orig); void operator= (const Stack& rhs); void push(T entry); void pop(); T peek() const; bool isEmpty() const; }; #include "Stack.cpp" #endif
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