Implement a stack and solutions to the following problems: balancing parenthesis, evaluating postfix expressions and transforming infix expressions into postfix expressions. We are providing some sample code and input files: public/   balancing.cpp    - main method to check whether an expression is balanced   infix2postfix.cpp    - main method to transform an infix expression into postfix   input_balanced.txt    - test cases for balancing.cpp   input_infix2postfix.txt    - test cases for infixtopostfix.cpp   input_postfixEval.txt    - test cases for postfixEval.cpp   postfixEval.cpp    - main method to evaluate postfix expressions   stack.cpp    - stack implementation   stack.hpp    - stack header file   • To compile, run   $ g++ stack.cpp balancing.cpp    $ g++ stack.cpp postfixEval.cpp    $ g++ stack.cpp infixtopostfix.cpp • To run each program, run   $ ./a.out • The test cases follow this format: expected_solution input. Given input, your job is to implement code that gets the expected_solution. Obviously, you need to calculate expected_solution, not just print it. • balancing.cpp must balance round parentheses, and square and curly brackets (() [] {}) • While we provide a few test cases, you are expected to add more to make sure your code works. Note: in postfixEval, we just consider each single digital is an input number. For example, “65-” means the two operands are “6” and “5”, NOT “65”.   what should the code be for the balancing.cpp

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

Implement a stack and solutions to the following problems: balancing parenthesis, evaluating postfix expressions and transforming infix expressions into postfix expressions.

We are providing some sample code and input files:

public/ 

 balancing.cpp 

  - main method to check whether an expression is balanced 

 infix2postfix.cpp 

  - main method to transform an infix expression into postfix 

 input_balanced.txt 

  - test cases for balancing.cpp 

 input_infix2postfix.txt 

  - test cases for infixtopostfix.cpp 

 input_postfixEval.txt 

  - test cases for postfixEval.cpp 

 postfixEval.cpp 

  - main method to evaluate postfix expressions 

 stack.cpp 

  - stack implementation 

 stack.hpp 

  - stack header file

 

• To compile, run

  $ g++ stack.cpp balancing.cpp 

  $ g++ stack.cpp postfixEval.cpp 

  $ g++ stack.cpp infixtopostfix.cpp

• To run each program, run

  $ ./a.out

• The test cases follow this format: expected_solution input. Given input, your job is to implement code that gets the expected_solution. Obviously, you need to calculate expected_solution, not just print it.

• balancing.cpp must balance round parentheses, and square and curly brackets (() [] {})

• While we provide a few test cases, you are expected to add more to make sure your code works.

Note: in postfixEval, we just consider each single digital is an input number. For example, “65-” means the two operands are “6” and “5”, NOT “65”.

 

what should the code be for the balancing.cpp

G- Q1.cpp
G- balancing.cpp x
G- infix2postfix.cpp
G. postfixEval.cpp
G- stack.cpp
G+ stack.hpp
E input_balanced.txt
= input_infix2postfix. D O
Users > diyadeepak > Desktop > assignment 2 > public > G balancing.cpp > ..
1
#include "stack.hpp"
2
3
using namespace std;
R ta
t l T
4
int main(){
freopen ("input_balanced.txt", "r", stdin);
5
7
string s,r;
int line_counter;
while(cin >> r){
9
10
cin>>s;
Stack<char> stack;
bool isBalanced
bool solution;
11
12
= true;
13
14
if(r[0]
'Y' || r[0]
'y'){
15
solution
= true;
16
}else{
17
solution
= false;
18
}
19
// The input file is in the format "expected_solution expression"
// so variable solution tells you whether 'expression' is balanced or not
20
21
22
for(int i=0; i<s. length(); ++i){
// WRITE CODE HERE so that isBalanced indicates whether 's' is balanced
23
24
25
}
26
27
// checking if you stored in isBalanced the correct value
28
if(isBalanced
solution){
cout <« "line "
}else{
« line_counter <« ": OK [" << solution <<
<« isBalanced << "]" <« endl;
%3D
%3D
29
30
31
cout << "line "
« line_counter <<«
': ERROR [" < solution <<
<« isBalanced << "]" « endl;
32
}
33
line_counter++;
34
}
35
}
Transcribed Image Text:G- Q1.cpp G- balancing.cpp x G- infix2postfix.cpp G. postfixEval.cpp G- stack.cpp G+ stack.hpp E input_balanced.txt = input_infix2postfix. D O Users > diyadeepak > Desktop > assignment 2 > public > G balancing.cpp > .. 1 #include "stack.hpp" 2 3 using namespace std; R ta t l T 4 int main(){ freopen ("input_balanced.txt", "r", stdin); 5 7 string s,r; int line_counter; while(cin >> r){ 9 10 cin>>s; Stack<char> stack; bool isBalanced bool solution; 11 12 = true; 13 14 if(r[0] 'Y' || r[0] 'y'){ 15 solution = true; 16 }else{ 17 solution = false; 18 } 19 // The input file is in the format "expected_solution expression" // so variable solution tells you whether 'expression' is balanced or not 20 21 22 for(int i=0; i<s. length(); ++i){ // WRITE CODE HERE so that isBalanced indicates whether 's' is balanced 23 24 25 } 26 27 // checking if you stored in isBalanced the correct value 28 if(isBalanced solution){ cout <« "line " }else{ « line_counter <« ": OK [" << solution << <« isBalanced << "]" <« endl; %3D %3D 29 30 31 cout << "line " « line_counter <<« ': ERROR [" < solution << <« isBalanced << "]" « endl; 32 } 33 line_counter++; 34 } 35 }
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 3 images

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