Q.No. 4(A)

01. (a) Observe the program segment given below carefully and fill the blanks marked as

Line 1 and Line 2 using fstream functions for performing the required task.

#include<fstream.h

class Stock

{

long Ino; // Item Number

char Item[20]; // Item Name

int Qty; // Quantity

public:

void Get(int);

Get(int);// Function to enter the content

void Show( ); // Function to display the content

void Purchase(int Tqty)

{

Qty+ = Tqty; // Function to increment in Qty

}

long KnowIno( )

{

return Ino;

}

};

void Purchaseitem(long PINo, int PQty)

// PINo -> Info of the item purchased

// PQty -> Number of items purchased

{

fstream file;

File.open(“ITEMS.DAT”,ios::binary|ios::in|ios::cut);

int Pos=-1;

Stock S;

while (Pos== -1 & File.read((char*)&S, sizeof(S)))

if (S.KnowInc( ) == PINo)

{

S.Purchase(PQty); // To update the number of items

Pos = File.tellg()- sizeof(S);

//Line 1 : To place the file pointer to the required position

______;

//Line 2 : To write the objects on the binary file

______;

}

if (Pos == -1)

cout<“No updation done as required Ino not found...”;

File.close( );

} 2009

02.(a) Observe the program segment given below carefully and fill the blanks

marked as Statement 1 and Statement 2 using seekg( ), seekp( ), tellp( ) and tellg()

functions for performing the required task.

# include <fstream.h

class PRODUCT

{

int Pno;

char pname [20];

int qty;

public :

void ModifyQty();// The function is to modify quantity of a PRODUCT

};

void PRODUCT :: ModifyQty ( )

{

fstream Fil;

Fil.open(“PRODUCT.DAT”,ios::binary | ios::in | ios::out);

int MPno;

cout<“Product No to modify quantity :”;

cinMPno;

while( Fil.read ((char*) this, sizeof (PRODUCT)))

{

if (MPno ==Pno)

{

cout<“present quantity:” <Qty<endl;

cout<“changed quantity:”;

cin>Qty;

int position = ______; //Statement 1

______; //Statement 2

Fil.write ((char*) this, sizeof (PRODUCT));

// Re-writing the Record

}

}

Fil.close( );

} 2011

03.(a) Write name of two member functions belonging to fstream class. 1998

04.(a) Differentiate between read() & write() functions. 1999

05.(a) Name two member functions of ofstream class. 2000

06. (a) Distinguish between serial files and sequential files. 2001

07. (a) What is the difference between get() and read() ? 2002

08. (a) Assuming that a text file named FIRST.TXT contains some text written into it,

write a function named vowelwords( ), that reads the file FIRST.TXT and creates

a new file named SECOND.TXT, to contain only those words from the file

FIRST.TXT which start with a lowercase vowel (i.e. with ‘a’, ‘e’, ‘i’, ‘o’, ‘u’). For

example if the file FIRST.TXT contains

Carry umbrella and overcoat when it rains

Then the file SECOND.TXT shall contain umbrella and overcoat it

2004

09.(a) Observe the program segment given below carefully, and answer the question that

follows:

class Book

{

int Book no;

char Book_name[20];

public:

//function to enter Book details

void enterdetails();

// function to display Book details

void showdetails();

//function to return Book_no

int Rbook_no ()

{

return Book_no;

}

} ;

void Modify(Book NEW)

{

fstream File;

File.open(“BOOK.DAT”,ios::binary|ios::in|ios::out);

Book OB;

int Recordsread = 0, Found = 0;

while (!Found & File.read((char*)&OB, sizeof (OB)))

{

Recordsread ++ ;

if (NEW.RBook_no() = = OB.RBook_no))

{

______//Missing Statement

File.write((char*)&NEW, sizeof (NEW));

Found = 1;

}

else

File.write((char*)&OB, sizeof(OB));

}

if (! Found)

cout<" Record for modification does not exist”;

File.close();

}

If the function Modify( ) is supposed to modify a record in file BOOK.DAT with the

values of Book NEW passed to its argument, write the appropriate statement for

Missing Statement using seekp( ) or seekg( ), whichever needed, in the above code

that would write the modified record at its proper place. 2005

10. (a) Observe the program segment given below carefully, and answer the question

that follows:

class PracFile

{

intPracno;

char PracName[20];

int TimeTaken;

int Marks;

public:

// function to enter PracFile details

void EnterPrac( );

// function to display PracFile details

void ShowPrac( ):

// function to return TimeTaken

int RTime() {return TimeTaken;}

// function to assign Marks

void Assignmarks (int M)

{ Marks = M;}

};

void AllocateMarks( )

{ fstream File;

File.open(“MARKS.DAT”,ios::binary|ios::in|ios::out);

PracFile P;

int Record = 0;

while (File.read(( char*) &P, sizeof(P)))

{

if(P.RTime()>50)

P.Assignmarks(0)

else

P.Assignmarks(10)

______//statement 1

______//statement 2

Record + + ;

}

File.close();

}

If the function AllocateMarks () is supposed to Allocate Marks for the records

in the file MARKS.DAT based on their value of the member TimeTaken.

Write C++ statements for the statement 1 and statement 2, where,

statement 1 is required to position the file write pointer to an appropriate place

in the file and statement 2 is to perform the write operation with the modified

record . 2007

11.(a).Observe the program segment given below carefully and fill in the blanks

marked as Statement 1 and Statement 2 using tellg ( ) and skeep ( ) functions for

performing the required task.

#include <fstream. h>

class c1ient

{

long Cno ;

char Name [20];

Email [30] ;

public :

//Function to allow user to enter the cno,Nme , Email.

void Enter ( ) ;

// Function to allow user to enter (modify) Email.

void modify ( ) ;

long ReturnCno( )

{

return Cno ;

}

} ;

void changeEmail ( )

{

Client C ;

fstream F ;

F. open (“INFO.DAT” , ios :: binary |ios :: in|ios :: out);

long Cnoc ; //Client’s no. whose Email needs to be changed

cin > Cnoc ;

while (F. read (( char*) &C, sizeof (C)))

{

if (Cnoc = = C.Returncno( ))

{

C.Modify( ) ;

//Statement 1

int Pos = ______//To find the current position of

//file pointer

//statement 2

______//To move the file pointer to write

//the modified record back into the

//file for the desired cnoc

F.write ((char*) &C, sizeof(C));

}

}

F.close( ) ;

} 2010

12.(a)Observe the program segment given below carefully and fill the blanks marked

as Statement 1 and Statement 2 using seekg() and tellg() functions for

performing the required task.

#include <fstream.h>

class Employee

{

int Eno;

char Ename[20];

public: //Function to count the total number of records

int Countrec();

};

int Item::Countrec()

{

fstream File;

File.open(“EMP.DAT”,ios::binary|ios::in);

______//Statement 1

int Bytes = ______//Statement 2

int Count = Bytes;

sizeof(Item);

File.close();

return Count;

} (sp)

13. (a) Observe the program segment given below carefully and fill the blanks marked as Statement 1 and Statement 2 using seekp() and seekg() functions for performing

the required task.

#include <fstream.h

class Item

{

int Ino;

char Item[20];

public:

//Function to search and display the content from a particular

//record number

void Search(int );

//Function to modify the content of a particular record number

void Modify(int);

};

void Item::Search(int RecNo)

{

fstream File;

File.open(“STOCK.DAT”,ios::binary|ios::in);

______//Statement 1

File.read((char*)this,sizeof(Item));

coutIno<”==>”<Item<endl;

File.close();

}

void Item::Modify(int RecNo)

{

fstream File;

File.open(“STOCK.DAT”,ios::binary|ios::in|ios::out);

coutIno;cin.getline(Item,20);

______//Statement 2

File.write((char*)this,sizeof(Item));

File.close();

} (sp)

14.(a) Observe the program segment given below carefully and fill the blanks marked as

Statement 1 and Statement 2 using seekp() and seekg() functions for performing

the required task.

#include <fstream.h

class Item

{

int Ino;

char Item[20];

public:

//Function to search and display the content from a particular

//record number

void Search(int );

//Function to modify the content of a particular record number

void Modify(int);

};

void Item::Search(int RecNo)

{

fstream File;

File.open(“STOCK.DAT”,ios::binary|ios::in);

______//Statement 1

File.read((char*)this,sizeof(Item));

coutIno<”==>”<Item<endl;

File.close();

}

void Item::Modify(int RecNo)

{

fstream File;

File.open(“STOCK.DAT”,ios::binary|ios::in|ios::out);

coutIno;cin.getline(Item,20);

______//Statement 2

File.write((char*)this,sizeof(Item));

File.close();

(s.p)

Q.No. 4(B)

01.

(b) Assuming the class FLOPPYBOX. write functions in C++ to perform the following:

(i) Write the object of FLOPPYBOX to a binary file.

(ii) Read objects of FLOPPYBOX from the binary and display on the screen

class FLOPPYBOX

{

int size;

char name[10];

public :

void getdata()

{

cin > size;

gets (name);

}

void showdata ()

{

cout < size < " " < name <endl;

}

}; 1998

02.

(b) Write a function COUNT_DO( ) in C++ to count the presence of a word „do‟ in a

text file “MEMO.TXT”.

Example :

If the content of the file “MEMO.TXT” is as follows:

I will do it, if you request me to do it.

It would have been done much earlier.

The function COUNT_DO( ) will display the following message:

Count of -do- in flie: 2009

03.

(b) Write a function in C++ to count the no. of “Me” or “My” words present in a

text file “DIARY.TXT”.

If the file “DIARY.TXT” content is as follows :

My first book was Me and My family. It gave me chance to be known to the world.

The output of the function should be Count of Me/ My in file :

2011

04.

(b) Assuming the class EMPLOYEE given below, write functions in C++ to perform following:

(i) Write the objects of EMPLOYEE to a binary file.

(ii) Read the objects of EMPLOYEE from binary file and display them on screen.

class EMPLOYEE

{

int ENO;

char ENAME[10];

public :

void GETIT()

{

cin > ENO;

gets (ENAME);

}

void SHOWIT()

{

cout <ENO < ENAME ;

coutendl;

}

}; 1998

05.

(b) Assuming the class FLOPPYBOX. write functions in C++ to perform the following:

(i) Write the object of FLOPPYBOX to a binary file.

(ii) Read objects of FLOPPYBOX from the binary and display on the screen.

class FLOPPYBOX

{

int size;

char name[10];

public :

void getdata()

{

cin > size;

gets (name);

}

void showdata ()

{

cout < size < " " < name ;

coutendl;

}

}; 1999

06.

(b) Assuming the class? DRINKS defined below, write functions in C++ to perform the following:

i. Write the objects of DRINKS to a binary files.

ii. Read the objects of DRINKS from binary file and display them on the screen when DNAME has value "INDY COLA".

class DRINKS

{

int DCODE;

char DNAME[13]; // Name of the drink

int DSIZE; // Size in liters

float DPRICE;

public:

void GETDRINKS()

{

cin > DCODE > DNAME > DSIZE >DPRICE;

}

void SHOWDRINKS ()

{

cout< DCODE < DNAME < DSIZE < DPRICE < endl;

}

char *GETNAME ()

{

return DNAME;

}

}; 2000

07.

b) Consider the class declaration:

class BUS

{

int bus_no;

char destination[20];

float distance;

public :

void Read(); // To read an object from the keyboard

void Write (); // To write an object into a file

void Show (); // To display the file contents on The monitor

};

Complete the member functions definitions. 2001

08.

b) Write a C++ program, which reads one line at a time from the disk file TEST.TXT, and displays it to a monitor. Your program has to read all the contents of the file. Assume the length of the line not to exceed 80 characters. You have to include all the header files if required.

2002

09.

(b) Assuming the class Computer as follows :

class computer

{

char chiptype[10];

int speed;

public:

void getdetails()

{

gets(chiptype);

cin>speed;

}

void showdetails()

{

cout<“Chip”<chiptype<“ Speed= “<speed;

}

};

Write a function readfile( ) to read all the records present in an already existing

binary file SHIP.DAT and display them on the screen, also count the number of

records present in the file. 2004

10.

b) Write a function in C++ to count and display the number of lines starting with

alphabet ‘A’ present in a text file “LINES.TXT”.

Example:

If the file “LINES.TXT” contains the following lines,

A boy is playing there.

There is a playground.

An aeroplane is in the sky.

Alphabets and numbers are allowed in the password.

The function should display the output as 3. 2005

11.

(b) Write afunction in C++ to print the count of the word is as an independent word

in at text file DIALOGUE.TXT. 2

For example, if the content of the file DIALOGUE. TXT is

This is his book. Is this book good?

Then the output of the program should be 2. 2007

12.

(b) Write afunction in C++ to print the count of the word is as an independent word

in at text file DIALOGUE.TXT.

For example, if the content of the file DIALOGUE. TXT is

This is his book. Is this book good?

Then the output of the program should be 2. 2010

12. (b) Write a function in C++ to read the content of a text file “DELHI.TXT” and diaplay all those lines on screen, which are Either starting with ‘D’ or starting with ‘M’. 2012

13.

(b) Write a function in C++ to count the number of alphabets present in a text file “NOTES.TXT”. S P 1

14.

(b) Write a function in C++ to count the number of lines present in a text file

“STORY.TXT”. S P 2

15.

(b) void CountLine()

{

ifstream FIL("STORY.TXT");

int LINES=0;

char STR[80];

while (FIL.getline(STR,80))

LINES++;

cout<"No. of Lines:"<LINES<endl;

f.close();

}

(½ Mark for opening STORY.TXT correctly)

(½ Mark for initializing a counter variable as 0)

(½ Mark for correctly reading a line from the file)

(½ Mark for correctly incrementing the counter) S P 3

Q.No. 4(C)

1. (c) Write a function in C++ to search for a laptop from a binary file

“LAPTOP.DAT” containing the objects of class LAPTOP (as defined below).

The user should enter the Model No and the function should search and

display the details of the laptop.

class LAPTOP

{

long ModelNo;

float RAM, HDD;

char Details[120];

public:

void StockEnter ( )

{

cin>Model>No>RAM>HDD;

gets(Details);

}

void StockDisplay( )