needs correction doesnt run

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

needs correction doesnt run

#include <iostream>
#include <stack>

using namespace std;

int matchingBracketsstringexprstringexprstringexpr

    stack<char> s;
    char x;
 
    for inti=0;i<expr.length(inti=0;i<expr.length(inti=0;i<expr.length(; i++)
    {
        if expr[i]==′(′||expr[i]==′[′||expr[i]==′′)s.push(expr[i]);continue;if(s.empty())returni;switch(expr[i])case′)′:x=s.top();s.pop();if(x==′′||x==′[′)returni;break;case′′:x=s.top();s.pop();if(x==′(′||x==′[′)returni;break;case′]′:x=s.top();s.pop();if(x==′(′||x==′′)returni;break;return0;intmain([Math Processing Error]expr[i]==′(′||expr[i]==′[′||expr[i]==′′)s.push(expr[i]);continue;if(s.empty())returni;switch(expr[i])case′)′:x=s.top();s.pop();if(x==′′||x==′[′)returni;break;case′′:x=s.top();s.pop();if(x==′(′||x==′[′)returni;break;case′]′:x=s.top();s.pop();if(x==′(′||x==′′)returni;break;return0;intmain(
{
    string expr;
    int res;
    
    getline(cin,exprcin,expr)cin,expr);
 
    res=matchingBracketsexprexpr;
    
    if res==0res==0
        cout << "No mistake";
    else
        cout << res;
    return 0;
}

 
Problem Description:
Your friend keeps finding mistakes in his code due to unmatched brackets errors. You, as a good
friend, decided to help him by developing a program that will find errors in the usage of different
types of brackets. A Code can contain any of the following brackets []{}(), where the opening
brackets are [,{, and (and the closing brackets corresponding to them are ],}, and ).
Being a good friend, you want your program not to only detect that there is an error in the
usage of brackets, but also point to the exact place in the code with the problematic bracket.
Using C++/CPP
Requirements:
1. Write a program that finds the first unmatched closing bracket which either does not
have an opening bracket before it, or closes the wrong opening bracket, like } in ()[}. If
there are no such mistakes, then it should find the first unmatched opening bracket
without the corresponding closing bracket after it, like (in {}([]. If there are no mistakes,
you should output "No Mistakes".
2. If there exists a mistake then your program should output the index of the first
unmatched closing bracket in the input string, and if there are no unmatched closing
brackets, output the index of the first unmatched opening bracket in the input string.
Note: In case of unmatched brackets you will always look for the first unmatched
closing bracket, if there are no unmatched closing brackets, then you will look for the
first unmatched opening bracket.
Transcribed Image Text:Problem Description: Your friend keeps finding mistakes in his code due to unmatched brackets errors. You, as a good friend, decided to help him by developing a program that will find errors in the usage of different types of brackets. A Code can contain any of the following brackets []{}(), where the opening brackets are [,{, and (and the closing brackets corresponding to them are ],}, and ). Being a good friend, you want your program not to only detect that there is an error in the usage of brackets, but also point to the exact place in the code with the problematic bracket. Using C++/CPP Requirements: 1. Write a program that finds the first unmatched closing bracket which either does not have an opening bracket before it, or closes the wrong opening bracket, like } in ()[}. If there are no such mistakes, then it should find the first unmatched opening bracket without the corresponding closing bracket after it, like (in {}([]. If there are no mistakes, you should output "No Mistakes". 2. If there exists a mistake then your program should output the index of the first unmatched closing bracket in the input string, and if there are no unmatched closing brackets, output the index of the first unmatched opening bracket in the input string. Note: In case of unmatched brackets you will always look for the first unmatched closing bracket, if there are no unmatched closing brackets, then you will look for the first unmatched opening bracket.
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY