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
icon
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;
 
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<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.
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());
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
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
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)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education