-->

Linked List, Stack And Queue

Question
CBSEENCO12011573

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();
};

Solution
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;
	}
}

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.
A/(B+C)*DE

Convert the following infix expression to its equivalent postfix expression, showing the stack contents for each step of conversion.

X / Y + U* (V­W)

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

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.

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;
	}
};