SlideShare a Scribd company logo
Please need help on C++ language.
Infix to Postfix) Write a program that converts an infix expression into an equivalent postfix
expression. The rules to convert an infix expression into an equivalent postfix expression are as
follows:
Initialize pfx to an empty expression and also initialize the stack.
Get the next symbol, sym, from infx.
If sym is an operand, append sym to pfx.
If sym is (, push sym into the stack.
If sym is ), pop and append all of the symbols from the stack until the most recent left
parentheses. Pop and discard the left parentheses.
If sym is an operator:
Pop and append all of the operators from the stack to pfx that are above the most recent left
parentheses and have precedence greater than or equal to sym.
Push sym onto the stack.
After processing infx, some operators might be left in the stack. Pop and append to pfx
everything from the stack.
In this program, you will consider the following (binary) arithmetic operators: +, -, *, and /.
You may assume that the expressions you will process are error free. Design a class that stores
the infix and postfix strings. The class must include the following operations:
getInfix: Stores the infix expression.
showInfix: Outputs the infix expression.
showPostfix: Outputs the postfix expression.
convertToPostfix: Converts the infix expression into a postfix expression. The resulting postfix
expression is stored in pfx.
precedence: Determines the precedence between two operators. If the first operator is of higher
or equal precedence than the second operator, it returns the value true; otherwise, it returns the
value false.
A + B - C;
(A + B ) * C;
(A + B) * (C - D);
A + ((B + C) * (E - F) - G) / (H - I);
A + B * (C + D ) - E / F * G + H;
Infix Expression: A+B-C;
Postfix Expression: AB+C-
Infix Expression: (A+B)*C;
Postfix Expression: AB+C*
Infix Expression: (A+B)*(C-D);
Postfix Expression: AB+CD-*
Infix Expression: A+((B+C)*(E-F)-G)/(H-I);
Postfix Expression: ABC+EF-*G-HI-/+
Infix Expression: A+B*(C+D)-E/F*G+H;
Postfix Expression: ABCD+*+EF/G*-H+
PLEASE PROVIDE FOLLOWING.
A UML diagram for your class.
The header file for your class.
The implementation file for your class.
The source code for your test program.
Solution
#include
using namespace std;
const int MAX = 50 ;
class InfixToPostfix
{
private :
char target[MAX], stack[MAX] ;
char *s, *t ;
int top ;
public :
InfixToPostfix( ) ;
void getInfix ( char *str ) ;
void showInfix () ;
void push ( char c ) ;
char pop( ) ;
void convertToPostfix( ) ;
int precedence ( char c ) ;
void showPostfix( ) ;
void Delete();
} ;
InfixToPostfix :: InfixToPostfix( )
{
top = -1 ;
strcpy ( target, "" ) ;
strcpy ( stack, "" ) ;
t = target ;
s = "" ;
}
void InfixToPostfix :: getInfix ( char *str )
{
s = str ;
}
void InfixToPostfix :: showInfix ( )
{
cout<<"Infix Expression :"<= precedence ( *s ) )
{
*t = opr ;
t++ ;
opr = pop( ) ;
}
push ( opr ) ;
push ( *s ) ;
}
else
push ( *s ) ;
s++ ;
}
if ( *s == ')' )
{
opr = pop( ) ;
while ( ( opr ) != '(' )
{
*t = opr ;
t++ ;
opr = pop( ) ;
}
s++ ;
}
}
while ( top != -1 )
{
char opr = pop( ) ;
*t = opr ;
t++ ;
}
*t = '0' ;
}
int InfixToPostfix :: precedence ( char c )
{
if ( c == '$' )
return 3 ;
if ( c == '*' || c == '/' || c == '%' )
return 2 ;
else
{
if ( c == '+' || c == '-' )
return 1 ;
else
return 0 ;
}
}
void InfixToPostfix :: showPostfix( )
{
cout << " Postfix expression : "<

More Related Content

Similar to Please need help on C++ language.Infix to Postfix) Write a program.pdf

stack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfstack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdf
Kalpana Mohan
 
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdfWrite a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
FOREVERPRODUCTCHD
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
nikshaikh786
 
Stack
StackStack
Stack
StackStack
CH4.pptx
CH4.pptxCH4.pptx
CH4.pptx
AliJama14
 
Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptx
RockyIslam5
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
maamir farooq
 
MO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.pptMO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.ppt
shashankbhadouria4
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
Vineeta Garg
 
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
P. Subathra Kishore, KAMARAJ College of Engineering and Technology, Madurai
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
Afaq Mansoor Khan
 
Assume an infix expression can only contain five operators, + .pdf
Assume an infix expression can only contain five operators,    + .pdfAssume an infix expression can only contain five operators,    + .pdf
Assume an infix expression can only contain five operators, + .pdf
marketing413921
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
Kulachi Hansraj Model School Ashok Vihar
 
Stack Applications
Stack ApplicationsStack Applications
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversion
Rashmiranja625
 
Stack
StackStack
Applications of stack
Applications of stackApplications of stack
Applications of stack
A. S. M. Shafi
 
Stacks
StacksStacks
Stacks
Sadaf Ismail
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
Then Murugeshwari
 

Similar to Please need help on C++ language.Infix to Postfix) Write a program.pdf (20)

stack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdfstack-111104232459-phpapp02.pdf
stack-111104232459-phpapp02.pdf
 
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdfWrite a program to convert a given INFIX into POSTFIX. Make sure .pdf
Write a program to convert a given INFIX into POSTFIX. Make sure .pdf
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Stack
StackStack
Stack
 
Stack
StackStack
Stack
 
CH4.pptx
CH4.pptxCH4.pptx
CH4.pptx
 
Lecture_04.2.pptx
Lecture_04.2.pptxLecture_04.2.pptx
Lecture_04.2.pptx
 
Data structures stacks
Data structures   stacksData structures   stacks
Data structures stacks
 
MO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.pptMO 2020 DS Stacks 3 AB.ppt
MO 2020 DS Stacks 3 AB.ppt
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix2.2 stack applications Infix to Postfix & Evaluation of Post Fix
2.2 stack applications Infix to Postfix & Evaluation of Post Fix
 
Prefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix NotationsPrefix, Infix and Post-fix Notations
Prefix, Infix and Post-fix Notations
 
Assume an infix expression can only contain five operators, + .pdf
Assume an infix expression can only contain five operators,    + .pdfAssume an infix expression can only contain five operators,    + .pdf
Assume an infix expression can only contain five operators, + .pdf
 
Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions Conversion of Infix To Postfix Expressions
Conversion of Infix To Postfix Expressions
 
Stack Applications
Stack ApplicationsStack Applications
Stack Applications
 
Infix-Postfix expression conversion
Infix-Postfix expression conversionInfix-Postfix expression conversion
Infix-Postfix expression conversion
 
Stack
StackStack
Stack
 
Applications of stack
Applications of stackApplications of stack
Applications of stack
 
Stacks
StacksStacks
Stacks
 
Infix to postfix conversion
Infix to postfix conversionInfix to postfix conversion
Infix to postfix conversion
 

More from pristiegee

Question No. 2 Describe how the Packet-Filtering Router filter data..pdf
Question No. 2 Describe how the Packet-Filtering Router filter data..pdfQuestion No. 2 Describe how the Packet-Filtering Router filter data..pdf
Question No. 2 Describe how the Packet-Filtering Router filter data..pdf
pristiegee
 
Indicicate the coordinaiton number of the metal and oxidation number.pdf
Indicicate the coordinaiton number of the metal and oxidation number.pdfIndicicate the coordinaiton number of the metal and oxidation number.pdf
Indicicate the coordinaiton number of the metal and oxidation number.pdf
pristiegee
 
QUESTION 12 12. An example of an error of presentation would be e.pdf
QUESTION 12 12. An example of an error of presentation would be e.pdfQUESTION 12 12. An example of an error of presentation would be e.pdf
QUESTION 12 12. An example of an error of presentation would be e.pdf
pristiegee
 
On a Metabolic Pathways experiment, Describe your observations below.pdf
On a Metabolic Pathways experiment, Describe your observations below.pdfOn a Metabolic Pathways experiment, Describe your observations below.pdf
On a Metabolic Pathways experiment, Describe your observations below.pdf
pristiegee
 
Name at least three major contributions of Islamic mathematicians..pdf
Name at least three major contributions of Islamic mathematicians..pdfName at least three major contributions of Islamic mathematicians..pdf
Name at least three major contributions of Islamic mathematicians..pdf
pristiegee
 
Module 02 Discussion - Domestic ContainmentDiscuss the concept of .pdf
Module 02 Discussion - Domestic ContainmentDiscuss the concept of .pdfModule 02 Discussion - Domestic ContainmentDiscuss the concept of .pdf
Module 02 Discussion - Domestic ContainmentDiscuss the concept of .pdf
pristiegee
 
How to do problem 15.16 Find a function f R rightarrow R^+ that i.pdf
How to do problem 15.16  Find a function f R rightarrow R^+ that i.pdfHow to do problem 15.16  Find a function f R rightarrow R^+ that i.pdf
How to do problem 15.16 Find a function f R rightarrow R^+ that i.pdf
pristiegee
 
Fill in the table below for the molecules shown. HCI Ar (atom) Ethane.pdf
Fill in the table below for the molecules shown. HCI Ar (atom) Ethane.pdfFill in the table below for the molecules shown. HCI Ar (atom) Ethane.pdf
Fill in the table below for the molecules shown. HCI Ar (atom) Ethane.pdf
pristiegee
 
How financial reporting for public companies has changed since the E.pdf
How financial reporting for public companies has changed since the E.pdfHow financial reporting for public companies has changed since the E.pdf
How financial reporting for public companies has changed since the E.pdf
pristiegee
 
Hello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdfHello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdf
pristiegee
 
Give the examples of network core devices Give the examples of physic.pdf
Give the examples of network core devices Give the examples of physic.pdfGive the examples of network core devices Give the examples of physic.pdf
Give the examples of network core devices Give the examples of physic.pdf
pristiegee
 
For a binary search tree that has a Node with three elements, data, a.pdf
For a binary search tree that has a Node with three elements, data, a.pdfFor a binary search tree that has a Node with three elements, data, a.pdf
For a binary search tree that has a Node with three elements, data, a.pdf
pristiegee
 
Find the coordinates of the midpoint of the segment connecting points.pdf
Find the coordinates of the midpoint of the segment connecting points.pdfFind the coordinates of the midpoint of the segment connecting points.pdf
Find the coordinates of the midpoint of the segment connecting points.pdf
pristiegee
 
Each student is to prepare a 3-5 page paper on a project on ONE of t.pdf
Each student is to prepare a 3-5 page paper on a project on ONE of t.pdfEach student is to prepare a 3-5 page paper on a project on ONE of t.pdf
Each student is to prepare a 3-5 page paper on a project on ONE of t.pdf
pristiegee
 
describe two processes by which evolution can occur. explain why.pdf
describe two processes by which evolution can occur. explain why.pdfdescribe two processes by which evolution can occur. explain why.pdf
describe two processes by which evolution can occur. explain why.pdf
pristiegee
 
Develop a structure chart for student asking diploma in university a.pdf
Develop a structure chart for student asking diploma in university a.pdfDevelop a structure chart for student asking diploma in university a.pdf
Develop a structure chart for student asking diploma in university a.pdf
pristiegee
 
Consider the following model of a very simple economy. Household savi.pdf
Consider the following model of a very simple economy. Household savi.pdfConsider the following model of a very simple economy. Household savi.pdf
Consider the following model of a very simple economy. Household savi.pdf
pristiegee
 
Assembly ProgramngCan the upper 16 bits of the four 32 bit general.pdf
Assembly ProgramngCan the upper 16 bits of the four 32 bit general.pdfAssembly ProgramngCan the upper 16 bits of the four 32 bit general.pdf
Assembly ProgramngCan the upper 16 bits of the four 32 bit general.pdf
pristiegee
 
A) How does the ability of the ligand to cross the plasma membrane d.pdf
A) How does the ability of the ligand to cross the plasma membrane d.pdfA) How does the ability of the ligand to cross the plasma membrane d.pdf
A) How does the ability of the ligand to cross the plasma membrane d.pdf
pristiegee
 
A T-account is a way of depicting the basic form of an account. what .pdf
A T-account is a way of depicting the basic form of an account. what .pdfA T-account is a way of depicting the basic form of an account. what .pdf
A T-account is a way of depicting the basic form of an account. what .pdf
pristiegee
 

More from pristiegee (20)

Question No. 2 Describe how the Packet-Filtering Router filter data..pdf
Question No. 2 Describe how the Packet-Filtering Router filter data..pdfQuestion No. 2 Describe how the Packet-Filtering Router filter data..pdf
Question No. 2 Describe how the Packet-Filtering Router filter data..pdf
 
Indicicate the coordinaiton number of the metal and oxidation number.pdf
Indicicate the coordinaiton number of the metal and oxidation number.pdfIndicicate the coordinaiton number of the metal and oxidation number.pdf
Indicicate the coordinaiton number of the metal and oxidation number.pdf
 
QUESTION 12 12. An example of an error of presentation would be e.pdf
QUESTION 12 12. An example of an error of presentation would be e.pdfQUESTION 12 12. An example of an error of presentation would be e.pdf
QUESTION 12 12. An example of an error of presentation would be e.pdf
 
On a Metabolic Pathways experiment, Describe your observations below.pdf
On a Metabolic Pathways experiment, Describe your observations below.pdfOn a Metabolic Pathways experiment, Describe your observations below.pdf
On a Metabolic Pathways experiment, Describe your observations below.pdf
 
Name at least three major contributions of Islamic mathematicians..pdf
Name at least three major contributions of Islamic mathematicians..pdfName at least three major contributions of Islamic mathematicians..pdf
Name at least three major contributions of Islamic mathematicians..pdf
 
Module 02 Discussion - Domestic ContainmentDiscuss the concept of .pdf
Module 02 Discussion - Domestic ContainmentDiscuss the concept of .pdfModule 02 Discussion - Domestic ContainmentDiscuss the concept of .pdf
Module 02 Discussion - Domestic ContainmentDiscuss the concept of .pdf
 
How to do problem 15.16 Find a function f R rightarrow R^+ that i.pdf
How to do problem 15.16  Find a function f R rightarrow R^+ that i.pdfHow to do problem 15.16  Find a function f R rightarrow R^+ that i.pdf
How to do problem 15.16 Find a function f R rightarrow R^+ that i.pdf
 
Fill in the table below for the molecules shown. HCI Ar (atom) Ethane.pdf
Fill in the table below for the molecules shown. HCI Ar (atom) Ethane.pdfFill in the table below for the molecules shown. HCI Ar (atom) Ethane.pdf
Fill in the table below for the molecules shown. HCI Ar (atom) Ethane.pdf
 
How financial reporting for public companies has changed since the E.pdf
How financial reporting for public companies has changed since the E.pdfHow financial reporting for public companies has changed since the E.pdf
How financial reporting for public companies has changed since the E.pdf
 
Hello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdfHello everyone,Im working on my fast food order project program..pdf
Hello everyone,Im working on my fast food order project program..pdf
 
Give the examples of network core devices Give the examples of physic.pdf
Give the examples of network core devices Give the examples of physic.pdfGive the examples of network core devices Give the examples of physic.pdf
Give the examples of network core devices Give the examples of physic.pdf
 
For a binary search tree that has a Node with three elements, data, a.pdf
For a binary search tree that has a Node with three elements, data, a.pdfFor a binary search tree that has a Node with three elements, data, a.pdf
For a binary search tree that has a Node with three elements, data, a.pdf
 
Find the coordinates of the midpoint of the segment connecting points.pdf
Find the coordinates of the midpoint of the segment connecting points.pdfFind the coordinates of the midpoint of the segment connecting points.pdf
Find the coordinates of the midpoint of the segment connecting points.pdf
 
Each student is to prepare a 3-5 page paper on a project on ONE of t.pdf
Each student is to prepare a 3-5 page paper on a project on ONE of t.pdfEach student is to prepare a 3-5 page paper on a project on ONE of t.pdf
Each student is to prepare a 3-5 page paper on a project on ONE of t.pdf
 
describe two processes by which evolution can occur. explain why.pdf
describe two processes by which evolution can occur. explain why.pdfdescribe two processes by which evolution can occur. explain why.pdf
describe two processes by which evolution can occur. explain why.pdf
 
Develop a structure chart for student asking diploma in university a.pdf
Develop a structure chart for student asking diploma in university a.pdfDevelop a structure chart for student asking diploma in university a.pdf
Develop a structure chart for student asking diploma in university a.pdf
 
Consider the following model of a very simple economy. Household savi.pdf
Consider the following model of a very simple economy. Household savi.pdfConsider the following model of a very simple economy. Household savi.pdf
Consider the following model of a very simple economy. Household savi.pdf
 
Assembly ProgramngCan the upper 16 bits of the four 32 bit general.pdf
Assembly ProgramngCan the upper 16 bits of the four 32 bit general.pdfAssembly ProgramngCan the upper 16 bits of the four 32 bit general.pdf
Assembly ProgramngCan the upper 16 bits of the four 32 bit general.pdf
 
A) How does the ability of the ligand to cross the plasma membrane d.pdf
A) How does the ability of the ligand to cross the plasma membrane d.pdfA) How does the ability of the ligand to cross the plasma membrane d.pdf
A) How does the ability of the ligand to cross the plasma membrane d.pdf
 
A T-account is a way of depicting the basic form of an account. what .pdf
A T-account is a way of depicting the basic form of an account. what .pdfA T-account is a way of depicting the basic form of an account. what .pdf
A T-account is a way of depicting the basic form of an account. what .pdf
 

Recently uploaded

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
Kartik Tiwari
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 

Recently uploaded (20)

TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Chapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdfChapter -12, Antibiotics (One Page Notes).pdf
Chapter -12, Antibiotics (One Page Notes).pdf
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 

Please need help on C++ language.Infix to Postfix) Write a program.pdf

  • 1. Please need help on C++ language. Infix to Postfix) Write a program that converts an infix expression into an equivalent postfix expression. The rules to convert an infix expression into an equivalent postfix expression are as follows: Initialize pfx to an empty expression and also initialize the stack. Get the next symbol, sym, from infx. If sym is an operand, append sym to pfx. If sym is (, push sym into the stack. If sym is ), pop and append all of the symbols from the stack until the most recent left parentheses. Pop and discard the left parentheses. If sym is an operator: Pop and append all of the operators from the stack to pfx that are above the most recent left parentheses and have precedence greater than or equal to sym. Push sym onto the stack. After processing infx, some operators might be left in the stack. Pop and append to pfx everything from the stack. In this program, you will consider the following (binary) arithmetic operators: +, -, *, and /. You may assume that the expressions you will process are error free. Design a class that stores the infix and postfix strings. The class must include the following operations: getInfix: Stores the infix expression. showInfix: Outputs the infix expression. showPostfix: Outputs the postfix expression. convertToPostfix: Converts the infix expression into a postfix expression. The resulting postfix expression is stored in pfx. precedence: Determines the precedence between two operators. If the first operator is of higher or equal precedence than the second operator, it returns the value true; otherwise, it returns the value false. A + B - C; (A + B ) * C; (A + B) * (C - D); A + ((B + C) * (E - F) - G) / (H - I); A + B * (C + D ) - E / F * G + H; Infix Expression: A+B-C; Postfix Expression: AB+C-
  • 2. Infix Expression: (A+B)*C; Postfix Expression: AB+C* Infix Expression: (A+B)*(C-D); Postfix Expression: AB+CD-* Infix Expression: A+((B+C)*(E-F)-G)/(H-I); Postfix Expression: ABC+EF-*G-HI-/+ Infix Expression: A+B*(C+D)-E/F*G+H; Postfix Expression: ABCD+*+EF/G*-H+ PLEASE PROVIDE FOLLOWING. A UML diagram for your class. The header file for your class. The implementation file for your class. The source code for your test program. Solution #include using namespace std; const int MAX = 50 ; class InfixToPostfix { private : char target[MAX], stack[MAX] ; char *s, *t ; int top ; public : InfixToPostfix( ) ; void getInfix ( char *str ) ; void showInfix () ; void push ( char c ) ; char pop( ) ; void convertToPostfix( ) ;
  • 3. int precedence ( char c ) ; void showPostfix( ) ; void Delete(); } ; InfixToPostfix :: InfixToPostfix( ) { top = -1 ; strcpy ( target, "" ) ; strcpy ( stack, "" ) ; t = target ; s = "" ; } void InfixToPostfix :: getInfix ( char *str ) { s = str ; } void InfixToPostfix :: showInfix ( ) { cout<<"Infix Expression :"<= precedence ( *s ) ) { *t = opr ; t++ ; opr = pop( ) ; } push ( opr ) ; push ( *s ) ; } else push ( *s ) ; s++ ; } if ( *s == ')' ) { opr = pop( ) ; while ( ( opr ) != '(' ) {
  • 4. *t = opr ; t++ ; opr = pop( ) ; } s++ ; } } while ( top != -1 ) { char opr = pop( ) ; *t = opr ; t++ ; } *t = '0' ; } int InfixToPostfix :: precedence ( char c ) { if ( c == '$' ) return 3 ; if ( c == '*' || c == '/' || c == '%' ) return 2 ; else { if ( c == '+' || c == '-' ) return 1 ; else return 0 ; } } void InfixToPostfix :: showPostfix( ) { cout << " Postfix expression : "<