Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please help me retrenchment my project or change other form by java. #include #include #include #include #include using namespace std; const ostream& stackTrace(ostream& out, stack

please help me retrenchment my project or change other form by java.
#include
#include
#include
#include
#include
using namespace std;
const ostream& stackTrace(ostream& out, stack callStack){
while(callStack.size() > 0){
out << callStack.top() << endl;
callStack.pop();
}
return out;
}
int main(int argc, char **argv) {
string line;
string command;
string functionName;
string poppedFunction;
bool errorDetected = false;
bool errorNoFunction = false;
bool errorWrongFunction = false;
stack callStack;
size_t lineNumber = 0;
size_t maximumDepth = 0;
while (getline(cin, line) && errorDetected == false) {
lineNumber++;
stringstream parser(line);
parser >> command >> functionName;
//add the function name to the stack
if(command == "call"){
callStack.push(functionName);
}
else if(command == "return"){
//check to see if the maxiumum depth of the stack has been reached
if(callStack.size() > maximumDepth){
maximumDepth = callStack.size();
}
//check to make sure the stack isnt empty
if(callStack.size() == 0){
errorDetected = true;
errorNoFunction = true;
}
//check to make sure the function name matches before popping
else if(callStack.top() != functionName){
errorDetected = true;
errorWrongFunction = true;
}
//pop the stack
else{
callStack.pop();
}
}
else{
errorDetected = true;
}
//clear the stringstream for the next command
parser.clear();
}
if(errorNoFunction){
cout << "Invalid trace at line " << lineNumber << endl;
cout << "Returning from " << functionName
<< " but no functions are currently being called" << endl;
cout << "Stack trace:" << endl;
//do a stack trace
stackTrace(cout,callStack);
}
else if(errorWrongFunction){
cout << "Invalid trace at line " << lineNumber << endl;
cout << "Returning from " << functionName << " instead of "
<< callStack.top() << endl;
cout << "Stack trace:" << endl;
//do a stack trace
stackTrace(cout,callStack);
}
else if((callStack.size() > 0)){
cout << "Invalid trace at line " << lineNumber << endl;
cout << "Not all functions returned" << endl;
cout << "Stack trace:" << endl;
//do a stack trace
stackTrace(cout,callStack);
}
else{
cout << "Valid trace" << endl;
cout << "Maximum call depth was " << maximumDepth << endl;
}
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

Online Systems For Physicians And Medical Professionals How To Use And Access Databases

Authors: Harley Bjelland

1st Edition

1878487442, 9781878487445

More Books

Students also viewed these Databases questions

Question

1. Identify three communication approaches to identity.

Answered: 1 week ago

Question

d. Who are important leaders and heroes of the group?

Answered: 1 week ago

Question

3. Describe phases of minority identity development.

Answered: 1 week ago