Sponsor Area
Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion.
P + ( Q - R ) * S / T
Conversion of the given Infix expression to its equivalent Postfix expression
(P+(((Q-R)*S)/T))
INFIX | STACK | POSTFIX |
( | ( | |
P | ( | P |
+ | (+ | P |
( | (+( | P |
Q | (+( | PQ |
- | (+(- | PQ |
R | (+(- | PQR |
) | (+ | PQR- |
* | (+* | PQR- |
S | (+* | PQR-S |
/ | (+/ | PQR-S* |
T | (+/ | PQR-S*T |
) | PQR-S*T/+ |
Write the definition of a member function PUSHGIFT() for a class STACK in C++,to add a GIFT in a dynamically allocated stack of GIFTs considering the following code is already written as a part of the program:
struct GIFT
{
int GCODE; //Gift Code
char GDESC[20]; //Gift Description
GIFT *Link;
};
class STACK
{
Gift *TOP;
public:
STACK(){
TOP=NULL;
}
void PUSHGIFT();
void POPGIFT();
~STACK();
};
void PUSHGIFT( )
{
GIFT *G = new GIFT;
cout<<'Enter gift code and description';
cin>>G–>GCODE;
gets(G–>GDESC);
if(TOP == NULL)
{
TOP = G;
}
else
{
G–>Link = TOP
TOP = G;
}
}
Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion:
X - ( Y + Z ) / U * V
ELEMENT | STACK | POSTFIX |
X | X | |
- | - | X |
( | -( | X |
Y | -( | XY |
+ | - ( + | XY |
Z | - ( + | XYZ |
) | - | XYZ+ |
/ | -/ | XYZ+ |
U | -/ | XYZ + U |
* | -* | XYZ + U/ |
V | -* | XYZ +U/V |
XYZ+U/V*- |
Convert the following Infix expression to its equivalent Postfix expression, showing the stack contents for each step of conversion.
A/(B+C)*DE
A/(B+C)*DE
= (A / (B+C) * D E)
Element | Stack of Operators | Postfix Expression |
( | ( | |
A | ( | A |
/ | (/ | A |
( | (/( | A |
B | (/( | AB |
+ | (/(+ | AB |
C | (/(+ | ABC |
) | (/ | ABC+ |
* | (* | ABC+/ |
D | (* | ABC+/D |
- | (- | ABC+/D* |
E | (- | ABC+/D*E |
) | ABC+/D*E- |
ABC+/D*E
Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion.
X / Y + U* (VW)
X / Y + U* (VW)=((X / Y)+(U*(VW)))
Element | Stack | Postfix |
X | X | |
/ | / | X |
Y | / | XY |
+ | + | XY/ |
U | + | XY/U |
* | +* | XY/U |
( | +*( | XY/U |
V | +*( | XY/UV |
- | +*(- | XY/UV |
W | +*(- | XY/UVW |
) | +* | XY/UVW- |
+* | XY/UVW-* | |
XY/UVW-*+ |
Write function definition for SUCCESS( ) in C++ to read the content of a text file STORY.TXT, count the presence of word STORY and display the number of occurrence of this word.
Note :
– The word STORY should be an independent word
– Ignore type cases (i.e. lower/upper case)
Example :
If the content of the file STORY.TXT is as follows:
Success shows others that we can do it. It is
possible to achieve success with hard work. Lot
of money does not mean SUCCESS.
The function SUCCESS () should display the following:
3
void SUCCESS()
{
int count=0;
ifstream f('STORY.TXT');
char s[20];
while (!f.eof())
{
f>>s;
if(strcmpi(s,'STORY')==0){
count++;
}
cout<<count;
f.close();
}
}
Write a function in C++ to read the content of a text file “DELHI.TXT” and display all those lines on the screen, which are either starting with ‘D’ or starting with ‘M’.
#include<fstream.h>
#include<conio.h>
int main()
{
ifstream fin;
fin.open('out.txt');
char str[80];
int count=0;
clrscr();
while(!fin.eof())
{
fin.getline(str,80);
if(str[0]=='D' || str[0]=='M')
{
cout<<str<<endl;
}
count++;
}
cout<<'Number of lines in file is '<<count; fin.close();
getch();
return 0;
}
Write a function in C++ to search for the details (Phoneno and Calls) of those Phones, which have more than 800 calls from a binary file “phones.dat”. Assuming that this binary file contains records/objects of class Phone, which is defined below.
class Phone
{
char Phoneno[10]; int Calls;
public:
void Get( )
{
gets(Phoneno); cin>>Calls;
}
void Billing( )
{
cout<<Phoneno<<'#'<<Calls<<endl;
}
int GetCalls( )
{
return Calls;
}
};
void search ()
{
Phone pObj;
ifstream ifs;
ifs.open('phones.dat',ios::binary);
while(ifs.read((char*)&pObj,sizeof(pObj)))
{
if(pObj.GetCalls()>=800)
pObj.Billing();
}
ifs.close();
}
Sponsor Area
Sponsor Area