-->

Linked List, Stack And Queue

Question
CBSEENCO12011724

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’.

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

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