1. 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 File;

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

int MPno;

cout<<”product no to modify quantity:”;

cin>>MPno;

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

{

if(MPno==Pno)

{

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

cout<<”changed quantity:”;

cin>>Qty;

int Position= ; //statement 1

; //statement 2

File.write((char*)this,sizeof(PRODUCT)); //Re-writing the record

}

}

File.close();

}

Read more  

 

  1. 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( );

}

Read more

 

 

  1. Observe the program segment given below carefully, and answer the question that follows:

class PracFile

{ int Pracno;

char PracName[20];

char TimeTaken;

int Marks;

public:

//function to enter PracFile details

void EnterPrac();

//function to display PracFile details

void ShowPrac();

//function to return TimeTaken

char RTime() { return TimeTaken; }

//fuction to assign Marks

void Assignmarks(int M)

{ Marks=M;

};

};

void AllocateMarks()

{ fstream File;

File.open(“MARKS.DAT”,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 file MARKS.DAT based on their value of 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 statement 2 is to perform the write

operation with the modified record.

Read more

 

 

  1. Observe the program segment given below carefully, and answer the question that follows:

class Team

{ long TId[10]; //Team’s Id

char TName[20]; //Team’s Name

float Points; //Team’s Points

public:

void Accept();

void Show();

void PointChange(); //Function to change Points

long R_TId() {return TId; }

};

void ReplacePoints(long Id)

{ fstream File;

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

Team T;

int Record=0;Found=0;

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

{

if(Id==T.R_TId())

{ cout<<“Enter new Points”;

T.PointsChange();

________________ //Statement 1

________________ //Statement 1

Found=1;

}

Record++;

}

if(found==1)

cout<<“Record Updated”;

File.close();

}

Write the statement 1 to position the File Pointer at the beginning of the Record for which the Team’s Id matches

with the argument passed, ad statement 2 to write the updated Recode at that position.

Read more

 

 

  1. Observe the program segment given below carefully, and answer the question that follows:

class Candidate

{ long CId; //Candidate’s Id

char CName[20]; //Candidate’s Name

float Marks; //Candidate’s Marks

public:

void Enter();

void Display();

void MarksChange();

//Funcion to change marks

long R_CId() { return CId; }

};

void MarksUpdate(log ID)

{ fstream File;

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

Candidate C;

int Record=0,Found=0;

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

{ if(Id==C.R_CId())

{ cout<<“Enter new Marks”;

C.MarkChange();

______________ //Statement 1

______________ //statement 2

Found=1;

}

Record++;

}

if(found==1) cout<<“Recoed Updated”;

File.close();

}

Write the statement 1 to position the File Pointer at the beginning of the Record for which the Candidate’s Id

matches with the argument passed, ad statement 2 to write the updated Recode at that position.

Read more

 

 

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

it 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_OB())

{ _______________ //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.

 Read more

 

 

  1. Observe the program segment given below carefully and fill the blanks marked as statement 1 and Statement 2

using tellg() and seekp() functions for performing the required task.

#include<fstream.h>

class Customer

{

long Cno;

char Name[20],Mobile[12];

public:

//function to allow user to enter the Cno, Name, Mobile

void Enter();

//function to allow user to enter (modify) mobile number

void Modify();

//function to return value of Cno

long GetCno() { return Cno;}

};

void ChangeMobile()

{

Customer C;

fstream F;

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

long Cnoc; //customer no. whose mobile number needs to be changed

cin>>Cnoc;

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

{

If(Cnoc==C.GetCno())

{

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 the record back on to the file

//for the desired Cnoc

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

}

}

File.close();

}

Read more

 

 

  1. int main()

{ char ch=’A’;

fstream fileout(“data.dat”,ios::out);

fileout<<ch;

int p=fileour.tellg();

cout<<p;

return 0;

}

What is the output if the file content before the execution of the program is the string “ABC”?

(Note that ” ” are not part of the file).

Read more

 

  1. int main()

{ char ch=’A’;

fstream fileout(“data.dat”,ics::app);

fileout<<ch;

int p=fileout.tellg();

cout<<p;

return 0;

}

What is the output if the file content before the execution of the program is the string “ABC”?

(Note that ” ” are not part of the file).

Read more
  1. Observe the program segment given below carefully, and answer the question that follows:

class Labrecord

{ int Expno;

char Expriment[20];

char Checked;

int Marks;

public:

//function to enter Expriment details

void EnterExp();

//function to display Expriment details

void ShowExp();

//fuction to retur Expno

char RChecked() { return Checked; }

//fuction to assign Marks

void Assignmarks(int M)

{ Marks=M;

};

};

void ModifyMarks()

{ fstream File;

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

Labrecord L;

int Rec=0;

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

{ if(L.RChecked()==’N’)

L.Assignmarks(0);

else

L.Assignmarks(10);

_____________ //statement 1

_____________ //statement 2

Rec++;

}

File.close();

}

If the function ModifyMarks() is supposed to modify Marks for the records in file MARKS.DAT based on their

status of the member Checked (containing value either ‘Y’ or ‘N’). 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

statement 2 is to perform the write operation with the modified record.

Read more
Rate Us
error: Content is protected !!