Sponsor Area
Linked List, Stack And Queue
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*- |
Some More Questions From Linked List, Stack and Queue Chapter
Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion.
X / Y + U* (VW)
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
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:
possible to achieve success with hard work. Lot
of money does not mean SUCCESS.
Observe the program segment given below carefully and the question that follow:
class Stock
{
int Ino,Qty; char Item[20];
public:
void Enter() {cin>>In0;gets(Item); cin>>Qty;}
void Issue(int Q) { Qty+=Q}
void Purchase(int Q) { Qty-=Q}
int GetIno(return Ino;)
};
void Purchaseitem(int Pino, int PQty)
{
fstream file;
File.open('STOCK.DAT',ios::binary|ios::in|ios::out);
Stock S;
int Success=0;
while (Success==0 && File.read((char*)&S, sizeof(S)))
{
if (Pino==S.GetIno())
{
S.Purchase(PQty);
File.seekp(Success); //Statement 1
File.write((char*) &S, sizeof(S)); //statement 2
Success++;
}
}
if (Success==1)
cout<<'Purchase Updated'<<endl;
else
cout<<'Wrong Item No'<<endl;
File.close( );
}
(i) Write statement 1 to position the file pointer to the appropriate place, so that the data updation is done for the required item.
(ii) Write statement 2 to perform the write operation so that the updation is done in the binary file.
class Stock
{
int Ino,Qty; char Item[20];
public:
void Enter() {cin>>In0;gets(Item); cin>>Qty;}
void Issue(int Q) { Qty+=Q}
void Purchase(int Q) { Qty-=Q}
int GetIno(return Ino;)
};
void Purchaseitem(int Pino, int PQty)
{
fstream file;
File.open('STOCK.DAT',ios::binary|ios::in|ios::out);
Stock S;
int Success=0;
while (Success==0 && File.read((char*)&S, sizeof(S)))
{
if (Pino==S.GetIno())
{
S.Purchase(PQty);
File.seekp(Success); //Statement 1
File.write((char*) &S, sizeof(S)); //statement 2
Success++;
}
}
if (Success==1)
cout<<'Purchase Updated'<<endl;
else
cout<<'Wrong Item No'<<endl;
File.close( );
}(ii) Write statement 2 to perform the write operation so that the updation is done in the binary file.
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’.
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;
}
};
class Phone
{
char Phoneno[10]; int Calls;
public:
void Get( )
{
gets(Phoneno); cin>>Calls;
}
void Billing( )
{
cout<<Phoneno<<'#'<<Calls<<endl;
}
int GetCalls( )
{
return Calls;
}
};Sponsor Area
Mock Test Series
Mock Test Series



