C++ Programming Please improve the given main file error code below. You just need to improve the case 0 of the code. See atached photos for instructions and errors. #include #include #include "sllstack.h" using namespace std; main.cpp int main(int argc, char** argv) { SLLStack* stack = new SLLStack(); int test; string str; cin >> test; switch (test) { case 0: getline(cin, str); bool ispar(string x); string x=str; stack s; for(int i=0;ipush('a'); stack->push('b'); stack->push('c'); cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 2: stack->push('5'); stack->push('3'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('7'); stack->push('9'); stack->push('4'); cout << stack->pop() << endl; stack->push('6'); stack->push('8'); cout << stack->pop() << endl; cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 3: stack->push('a'); stack->push('b'); stack->push('c'); cout << stack->pop() << endl; stack->push('d'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('e'); stack->push('f'); cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 4: stack->push('C'); cout << stack->pop() << endl; stack->push('L'); stack->push('K'); stack->push('N'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('O'); stack->push('V'); stack->push('W'); cout << stack->pop() << endl; stack->push('E'); cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 5: stack->push('B'); cout << stack->pop() << endl; stack->push('K'); stack->push('H'); stack->push('V'); stack->push('O'); stack->push('C'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('P'); stack->push('E'); cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 6: stack->push('g'); stack->push('h'); stack->push('i'); stack->push('j'); stack->push('k'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('l'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('m'); stack->push('n'); cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; } return 0; }
C++ Programming Please improve the given main file error code below. You just need to improve the case 0 of the code. See atached photos for instructions and errors. #include #include #include "sllstack.h" using namespace std; main.cpp int main(int argc, char** argv) { SLLStack* stack = new SLLStack(); int test; string str; cin >> test; switch (test) { case 0: getline(cin, str); bool ispar(string x); string x=str; stack s; for(int i=0;ipush('a'); stack->push('b'); stack->push('c'); cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 2: stack->push('5'); stack->push('3'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('7'); stack->push('9'); stack->push('4'); cout << stack->pop() << endl; stack->push('6'); stack->push('8'); cout << stack->pop() << endl; cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 3: stack->push('a'); stack->push('b'); stack->push('c'); cout << stack->pop() << endl; stack->push('d'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('e'); stack->push('f'); cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 4: stack->push('C'); cout << stack->pop() << endl; stack->push('L'); stack->push('K'); stack->push('N'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('O'); stack->push('V'); stack->push('W'); cout << stack->pop() << endl; stack->push('E'); cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 5: stack->push('B'); cout << stack->pop() << endl; stack->push('K'); stack->push('H'); stack->push('V'); stack->push('O'); stack->push('C'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('P'); stack->push('E'); cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; case 6: stack->push('g'); stack->push('h'); stack->push('i'); stack->push('j'); stack->push('k'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('l'); cout << stack->pop() << endl; cout << stack->pop() << endl; stack->push('m'); stack->push('n'); cout << stack->size() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->pop() << endl; cout << stack->isEmpty() << endl; break; } return 0; }
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
C++ Programming
Please improve the given main file error code below. You just need to improve the case 0 of the code. See atached photos for instructions and errors.
#include <iostream>
#include <cstring>
#include "sllstack.h"
using namespace std;
int main(int argc, char** argv) {
SLLStack* stack = new SLLStack();
int test;
string str;
cin >> test;
switch (test) {
case 0:
getline(cin, str);
bool ispar(string x);
string x=str;
stack<char> s;
for(int i=0;i<x.length();++i)
{
if(x[i]=='(' or x[i]=='{' or x[i]=='[')
s.push(x[i]);
else if (x[i]==')' and !s.empty())
{
if(s.top()!='(')
return false;
s.pop();
}
else if(x[i]=='}' and s.empty()!=1)
{
if(s.top()!='{')
return false;
s.pop();
}
else if(x[i]==']' and s.empty()!=1)
{
if(s.top()!='[')
return false;
s.pop();
cout<<"Not accepted"<<endl;
}
else
return false;
}
return (s.empty());
cout<<"accepted";
break;
case 1:
stack->push('a');
stack->push('b');
stack->push('c');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 2:
stack->push('5');
stack->push('3');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('7');
stack->push('9');
stack->push('4');
cout << stack->pop() << endl;
stack->push('6');
stack->push('8');
cout << stack->pop() << endl;
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 3:
stack->push('a');
stack->push('b');
stack->push('c');
cout << stack->pop() << endl;
stack->push('d');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('e');
stack->push('f');
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 4:
stack->push('C');
cout << stack->pop() << endl;
stack->push('L');
stack->push('K');
stack->push('N');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('O');
stack->push('V');
stack->push('W');
cout << stack->pop() << endl;
stack->push('E');
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 5:
stack->push('B');
cout << stack->pop() << endl;
stack->push('K');
stack->push('H');
stack->push('V');
stack->push('O');
stack->push('C');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('P');
stack->push('E');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 6:
stack->push('g');
stack->push('h');
stack->push('i');
stack->push('j');
stack->push('k');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('l');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('m');
stack->push('n');
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
}
return 0;
}
string x=str;
stack<char> s;
for(int i=0;i<x.length();++i)
{
if(x[i]=='(' or x[i]=='{' or x[i]=='[')
s.push(x[i]);
else if (x[i]==')' and !s.empty())
{
if(s.top()!='(')
return false;
s.pop();
}
else if(x[i]=='}' and s.empty()!=1)
{
if(s.top()!='{')
return false;
s.pop();
}
else if(x[i]==']' and s.empty()!=1)
{
if(s.top()!='[')
return false;
s.pop();
cout<<"Not accepted"<<endl;
}
else
return false;
}
return (s.empty());
cout<<"accepted";
break;
case 1:
stack->push('a');
stack->push('b');
stack->push('c');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 2:
stack->push('5');
stack->push('3');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('7');
stack->push('9');
stack->push('4');
cout << stack->pop() << endl;
stack->push('6');
stack->push('8');
cout << stack->pop() << endl;
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 3:
stack->push('a');
stack->push('b');
stack->push('c');
cout << stack->pop() << endl;
stack->push('d');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('e');
stack->push('f');
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 4:
stack->push('C');
cout << stack->pop() << endl;
stack->push('L');
stack->push('K');
stack->push('N');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('O');
stack->push('V');
stack->push('W');
cout << stack->pop() << endl;
stack->push('E');
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 5:
stack->push('B');
cout << stack->pop() << endl;
stack->push('K');
stack->push('H');
stack->push('V');
stack->push('O');
stack->push('C');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('P');
stack->push('E');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
case 6:
stack->push('g');
stack->push('h');
stack->push('i');
stack->push('j');
stack->push('k');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('l');
cout << stack->pop() << endl;
cout << stack->pop() << endl;
stack->push('m');
stack->push('n');
cout << stack->size() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->pop() << endl;
cout << stack->isEmpty() << endl;
break;
}
return 0;
}
![Additionally, you are also going to solve the Brackets Problem in
the case O of the main.cpp file where you have to identify
whether a given string that contains brackets is valid or not.
Brackets may be parentheses ( and ), curly brackets { and },
and square brackets [ and ]. Each opening symbol must match
its corresponding closing symbol. For example, a left bracket,
"L" must match a corresponding right bracket, ")," as in the
following expression: [0]
Take note of the three considerations that will make the string
invalid: a mismatch where the closing bracket did not match
what was in the top of the stack (e.g. "(1)"), an excess opening
where we have completed checking the string where there
should have been more closing bracket/s (e.g. "(0"), and an
excess closing where we found a closing bracket but there's no
opening bracket to match it with (e.g. "0)").
Using the methods of a stack and your SLL implementation,
create a separate program that will print accepted if a given
string is valid exclusively in terms of brace pairing and
otherwise, print not accepted.](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2cb11186-80ff-4474-bc75-6eff69002743%2F88abe3c7-f99a-49bb-9ed6-c43e8ef06c32%2Fr1zzc5_processed.png&w=3840&q=75)
Transcribed Image Text:Additionally, you are also going to solve the Brackets Problem in
the case O of the main.cpp file where you have to identify
whether a given string that contains brackets is valid or not.
Brackets may be parentheses ( and ), curly brackets { and },
and square brackets [ and ]. Each opening symbol must match
its corresponding closing symbol. For example, a left bracket,
"L" must match a corresponding right bracket, ")," as in the
following expression: [0]
Take note of the three considerations that will make the string
invalid: a mismatch where the closing bracket did not match
what was in the top of the stack (e.g. "(1)"), an excess opening
where we have completed checking the string where there
should have been more closing bracket/s (e.g. "(0"), and an
excess closing where we found a closing bracket but there's no
opening bracket to match it with (e.g. "0)").
Using the methods of a stack and your SLL implementation,
create a separate program that will print accepted if a given
string is valid exclusively in terms of brace pairing and
otherwise, print not accepted.
![main.cpp: In function 'int main(int, char**)':
main.cpp:17:15: error: expected primary-expression before char'
stack<char> s;
main.cpp:21:17: error: 's' was not declared in this scope
s. push(x[i]);
main.cpp:22:37: error: 's was not declared in this scope
else if (x[i]--')' and !s.empty())
main.cpp:44:16: error: 's was not declared in this scope
return (s.empty());](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F2cb11186-80ff-4474-bc75-6eff69002743%2F88abe3c7-f99a-49bb-9ed6-c43e8ef06c32%2Fhrqtqds_processed.png&w=3840&q=75)
Transcribed Image Text:main.cpp: In function 'int main(int, char**)':
main.cpp:17:15: error: expected primary-expression before char'
stack<char> s;
main.cpp:21:17: error: 's' was not declared in this scope
s. push(x[i]);
main.cpp:22:37: error: 's was not declared in this scope
else if (x[i]--')' and !s.empty())
main.cpp:44:16: error: 's was not declared in this scope
return (s.empty());
Expert Solution
![](/static/compass_v2/shared-icons/check-mark.png)
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
![Blurred answer](/static/compass_v2/solution-images/blurred-answer.jpg)
Recommended textbooks for you
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![Database System Concepts](https://www.bartleby.com/isbn_cover_images/9780078022159/9780078022159_smallCoverImage.jpg)
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
![Starting Out with Python (4th Edition)](https://www.bartleby.com/isbn_cover_images/9780134444321/9780134444321_smallCoverImage.gif)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
![Digital Fundamentals (11th Edition)](https://www.bartleby.com/isbn_cover_images/9780132737968/9780132737968_smallCoverImage.gif)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
![C How to Program (8th Edition)](https://www.bartleby.com/isbn_cover_images/9780133976892/9780133976892_smallCoverImage.gif)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
![Database Systems: Design, Implementation, & Manag…](https://www.bartleby.com/isbn_cover_images/9781337627900/9781337627900_smallCoverImage.gif)
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
![Programmable Logic Controllers](https://www.bartleby.com/isbn_cover_images/9780073373843/9780073373843_smallCoverImage.gif)
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education