C++ Programming, Stack queue and deque

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, Stack queue and deque
Improve the error code below, you can also create custom methods in the main class. See attached photo for the instructions.

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()); ^ main.cpp:47:14: error: jump to case label [-fpermissive] case 1: ^ main.cpp:16:16: note: crosses initialization of ‘std::__cxx11::string x’ string x=str; ^ main.cpp:56:14: error: jump to case label [-fpermissive] case 2: ^ main.cpp:16:16: note: crosses initialization of ‘std::__cxx11::string x’ string x=str; ^ main.cpp:74:14: error: jump to case label [-fpermissive] case 3: ^ main.cpp:16:16: note: crosses initialization of ‘std::__cxx11::string x’ string x=str; ^ main.cpp:90:14: error: jump to case label [-fpermissive] case 4: ^ main.cpp:16:16: note: crosses initialization of ‘std::__cxx11::string x’ string x=str; ^ main.cpp:110:14: error: jump to case label [-fpermissive] case 5: ^ main.cpp:16:16: note: crosses initialization of ‘std::__cxx11::string x’ string x=str; ^ main.cpp:130:14: error: jump to case label [-fpermissive] case 6: ^ main.cpp:16:16: note: crosses initialization of ‘std::__cxx11::string x’ string x=str; ^ g++: error: main.o: No such file or directory g++: fatal error: no input files compilation terminated.

 

main.cpp

int main(int argc, char** argv) {
    SLLStack* stack = new SLLStack();
    int test;
    string str;
    cin >> test;
    switch (test) {
        case 0:
        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;
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());
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.
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