Redo Programming Exercise 10 of Chapter 17 so that it uses the STL class stack to convert the infix expressions to postfix expressions
Redo Programming Exercise 10 of Chapter 17 so that it uses the STL class stack to convert the infix expressions to postfix expressions
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++
Redo
![Instructions
Instructions
Redo Programming Exercise 10 of Chapter 17 so that it uses the STL
class stack to convert the infix expressions to postfix expressions.
Grading
When you have completed your program, click the Submit button to
record your score.
infixData.txt
1 A+B-C;
2 (A+B)*C;
3 (A+B)*(C-D);
4 A+((B+C)*(E-F)-G)/(H-I);
5 A+B* (C+D)-E/F*G+H;
6
infixData.txt
infixToPostFixlmp.cpp| infixToPostfix.h
infixToPostFixImp.cpp infixToPostfix.h
1 #include<iostream>
2 #include<string>
3 #include<fstream>
4 #include "infixToPostfix.h"
5 using namespace std;
6 int main() {
7
8
9
10
infixToPostfix InfixExp;
string infix;
cout << "Infix: ";
cin >> infix;
11
12
13
14
15 InfixExp.getInfix(infix);
16
// InfixExp.showInfix();
cout << "Postfix: ";
22 return 0;
23 }
24
17
18
19 InfixExp.showPostfix();
20
cout << endl;
21
main.cpp
main.cpp
| +
+
infixData.txt
1 #include<iostream>
2 #include<stack> // for using stl stack
3 using namespace std;
4 class infixToPostfix {
5 string infix;
6 public:
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
infixToPostFixImp.cpp infixToPostfix.h
32
33
34
35
36
void getInfix (string x) {
this->infix = x;
}
void showInfix() {
}
//Function to return order_of_operatoredence of operators
int order_of_operator (char c)
if (c==¹^¹)
cout << this->infix << endl;
return 3;
else if (c == '/' || c == '*')
return 2;
else if (c == '+' || c == '-')
C
return 1;
else
return -1;
메
string convertInfixtoPostfix (string s) {
main.cpp
for (int i = 0; i < s.size()-1; i++) { // s.size()-1 as to avoid the ";"
char c = s[1];
if ((c>= 'a' && c <= ¹z¹) || (c>= 'A' && c <= 'Z') || (c >= '0' && c
final_string += c;
// If the scanned character is an
// '(', push it to the stack.
else if (c == '(')
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
61
62
63
stack<char> st; //For stack operations, we are using STL class stack accordi 64
string final_string;
65
66
}
67 };
68
59
60
}
6
7
8}
9
------
st.push('(');"
else if (c == ¹)') {
int main() {
while (st.top() != '(')
{
}
}
st.pop();
}
//If an operator is scanned
else {
final_string += st.top();
st.pop();
while (!st.empty() && order_of_operator (s[1]) <= order_of_operator
final_string+= st.top();
st.pop();
}
}
while (!st.empty()) {
st.push(c);
final_string+= st.top();
st.pop();
return final_string;
}
void showPostfix() {
string ans = convertInfixtoPostfix (this->infix);
cout << ans << endl;
infixData.txt
1 #include <iostream>
2
3 using namespace std;
4
infixToPostFixlmp.cpp | infixToPostfix.h
// Write your main here.
return 0;
main.cpp
+](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fdf5ed780-1f6f-4967-98f6-5be55b32abf1%2F3709bd19-c401-4c2c-aa01-69bc1484b434%2Forxa82_processed.png&w=3840&q=75)
Transcribed Image Text:Instructions
Instructions
Redo Programming Exercise 10 of Chapter 17 so that it uses the STL
class stack to convert the infix expressions to postfix expressions.
Grading
When you have completed your program, click the Submit button to
record your score.
infixData.txt
1 A+B-C;
2 (A+B)*C;
3 (A+B)*(C-D);
4 A+((B+C)*(E-F)-G)/(H-I);
5 A+B* (C+D)-E/F*G+H;
6
infixData.txt
infixToPostFixlmp.cpp| infixToPostfix.h
infixToPostFixImp.cpp infixToPostfix.h
1 #include<iostream>
2 #include<string>
3 #include<fstream>
4 #include "infixToPostfix.h"
5 using namespace std;
6 int main() {
7
8
9
10
infixToPostfix InfixExp;
string infix;
cout << "Infix: ";
cin >> infix;
11
12
13
14
15 InfixExp.getInfix(infix);
16
// InfixExp.showInfix();
cout << "Postfix: ";
22 return 0;
23 }
24
17
18
19 InfixExp.showPostfix();
20
cout << endl;
21
main.cpp
main.cpp
| +
+
infixData.txt
1 #include<iostream>
2 #include<stack> // for using stl stack
3 using namespace std;
4 class infixToPostfix {
5 string infix;
6 public:
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
infixToPostFixImp.cpp infixToPostfix.h
32
33
34
35
36
void getInfix (string x) {
this->infix = x;
}
void showInfix() {
}
//Function to return order_of_operatoredence of operators
int order_of_operator (char c)
if (c==¹^¹)
cout << this->infix << endl;
return 3;
else if (c == '/' || c == '*')
return 2;
else if (c == '+' || c == '-')
C
return 1;
else
return -1;
메
string convertInfixtoPostfix (string s) {
main.cpp
for (int i = 0; i < s.size()-1; i++) { // s.size()-1 as to avoid the ";"
char c = s[1];
if ((c>= 'a' && c <= ¹z¹) || (c>= 'A' && c <= 'Z') || (c >= '0' && c
final_string += c;
// If the scanned character is an
// '(', push it to the stack.
else if (c == '(')
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
61
62
63
stack<char> st; //For stack operations, we are using STL class stack accordi 64
string final_string;
65
66
}
67 };
68
59
60
}
6
7
8}
9
------
st.push('(');"
else if (c == ¹)') {
int main() {
while (st.top() != '(')
{
}
}
st.pop();
}
//If an operator is scanned
else {
final_string += st.top();
st.pop();
while (!st.empty() && order_of_operator (s[1]) <= order_of_operator
final_string+= st.top();
st.pop();
}
}
while (!st.empty()) {
st.push(c);
final_string+= st.top();
st.pop();
return final_string;
}
void showPostfix() {
string ans = convertInfixtoPostfix (this->infix);
cout << ans << endl;
infixData.txt
1 #include <iostream>
2
3 using namespace std;
4
infixToPostFixlmp.cpp | infixToPostfix.h
// Write your main here.
return 0;
main.cpp
+
Expert Solution

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 5 steps with 4 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education