Previous Years Examination Questions
1 Mark Questions
Question 1:
Find the output of the following C++ code considering that the binary file CLIENTS.DAT exists on the hard disk with a data of 200 clients: All India 2017
class CLIENTS
{
int CCode;char CName[20];
public:
void REGISTER(); void DISPLAY();
}:
void main()
(
fstream File;
File.open("CLIENTS.DAT",ios::binary|ios::in);
CLIENTS C;
File.seekg(6*sizeof(C));
File.read!(char*)&C, sizeof(C)):
cout<<"Client Number:"<<File.tellg()/sizeof(C)+1;
File.seekg(0,ios::end);
cout«"of"<<File.tellg()/sizeof(C)<<endl;
File.close();
}Answer:
Output
Client Number:8 of 200
Question 2:
Find the output of the following C++ code considering that the binary file MEM.DAT exists on the hard disk with a data of 1000 members: Delhi 2016
class MEMBER
{
int Mcode;char MName[20];
public:
void Register();void Display();
};
void main()
{
fstream MFile;
MFile.openCMEM.DAT", ios ::binary| ios :: in); .
MEMBER M;
MFile.read((char*) &M. sizeof(M));
cout<<"Rec :"<<MFile.tellg()/sizeof(M)<< endl;
MFile.read!(char*) &M, sizeof(M));
MFile.read((char*) &M, sizeof(M));
cout<<"Rec :"<<MFile.tellg()/sizeof(M)<<endl;
MFile. close();
}Answer:
Output
Rec : 1 Rec : 3
Question 3:
Find the output of the following C++ code considering that the binary file CLIENT.DAT exists on the hard disk with a data of 1000 clients: All India 2016
class CLIENT
{
int Ccode; char CName[20];
public:
void Register(); void Display():
};
void main()
{
fstream CFile;
CFile.open("CLIENT.DAT",ios::binary|ios::in);
CLIENT C;
CFile.read((char*)&C, sizeof(C));
cout<<"Rec: "<<CFile.tel 1 g()/sizeof (C)<<endl;
CFile.read((char*)&C, sizeof(C));
CFile.read((char*)&C, sizeof(C)):
cout<<"Rec:"<<CFile.tellg()/sizeof(C)<<endl;
CFile.close():
}Answer:
Output
Rec: 1 Rec: 3
Question 4:
Find the output of the following C++ code considering that the binary file CLIENT.DAT exists on the hard disk with records of 100 members. Delhi 2016
class CLIENTS
{
int Cno; char Name[20];
public:
void In(); void Out();
}:
void main()
{
fstream CF;
CF.open("CLIENTS.DAT", ios::binary|ios: :in);
CLIENTS C;
CF.read((char*)&C,sizeof(C));
CF.read((char*)&C,sizeof(C));
CF.read((char*)&C,sizeof(C));
int POS=CF.tellg()/sizeof(C);
cout<<"PRESENT RECORD: "<<P0S<<endl;
CF.close();
}Answer:
Output
PRESENT RECORD:3
Question 5:
Find the output of the following C++ code considering that the binary file MEMBER.DAT exists on the hard disk with records of 100 members. All India 2015
class MEMBER
{
int Mno; char Name[20];
public:
void In(); void Out();
};
void main()
{
fstream MF;
MF.openC"MEMBER.DAT", ios::binary|ios::in);
MEMBER M;
MF.read((char*)&M. sizeof(M));
MF.read((char*)&M, sizeof(M));
MF.read((char*)&M, sizeof(M));
int P0SITI0N=MF.tel1g()/sizeof(M);
cout<<”PRESENT RECORD: ”<<P0SITI0N<<endl ;
MF.close();
}Answer:
Output
PRESENT RECORD:3
Question 6:
Find the output of the following C++ code considering that the binary file GAME. DAT exist on the hard disk with information of around 200 games. All India 2015 c
class GAME
{
int Gno; char GName[20];
public:
void Getln(); void ShowName();
};
void main()
{
fstream GF;
GF.open("GAME.DAT",ios::binary | ios::in);
GAME G;
GF.seekg(sizeof(G)*5) ;
GF.read((char*)&G, sizeof(G)):
GF.readC(char*)&G, sizeof(G));
int REC0RDN0=GF.tel 1g()/sizeof(G);
cout<<"REC0RDN0: "<<REC0RDN0<<endl;
GF.close();
}Answer:
Output
REC0RDN0:7
Question 7:
Fill in the blanks marked as Statement 1 and Statement 2 in the program segment given below with appropriate functions for the required task. Delhi 2014
class Medical
{
int RNo; //Representative Code
char Name[20]; //Representative Name
char Mobile[12]; //Representative Mobile
public:
void Input(); //Function to enter all details
void Show(); //Function to display all details
int RRno()
{
return RNo;
}
void ChangeMobile() //Function to change Mobile
{
cout<<”Changed Mobile:";
gets(Mobile);
}
};
void RepUpdate()
{
fstream F;
F.open("REP.DAT", ios::binary|ios::in|ios::out);
int Change=0;
int URno;
cout<<"Rno(Rep No-to update Mobile):";
cin>>URno;
Medical M;
while(!Change && F.read((char*)&M,sizeof(M)))
{
if(M.RRno() == URno)
{
//Statement l:To call the function to change Mobile No.
____________________________________;
//Statement 2:To reposition file pointer to re-write
//The updated object back in the file
____________________________________;
F.write!(char*)&M,sizeof(M));
Change++;
}
}
if(Change)
cout<<"Mobile Changed for Rep"<<URno<<endl;
else
cout<<"Rep not in the Medical "<<endl;
F.close();
}Answer:
Statement 1
M.ChangeMobile()
Statement 2
F.seekp(-l*sizeof(M),ios::cur)
Question 8:
Fill in the blanks marked as Statement 1 and Statement 2 in the program segment given below with appropriate functions for the required task. All India 2014
class Agency
{
int ANo; //Agent code
char AName[20]; //Agent name
char Mobile[30]; //Agent mobile
public:
void Enter(); //Function to enter details of agent
void Disp(); //Function to display details of agent
int RAno() {return ANo;
}
void UpdateMobileO //Function to update Mobile
{
cout<<"Updated Mobile:";
gets(Mobile);
}
};
void AgentUpdateC)
{
fstream F;
F.open("AGENT.DAT",ios::binary|ios::in|ios::out);
int Updt=0;
int UAno;
cout<<"Ano (Agent No-to update Mobile):";
cin>>UAno;
Agency A;
whileUUpdt && F.read((char*)&A,sizeof(A)))
{
if (A.RAnoO == UAno)
{
//Statement 1:To call the function to Update Mobile No.
____________________________________;
//Statement 2:To reposition file pointer to re-write
//The updated object back in the file
___________________________________;
F.write((char*)&A,sizeof(A));
Updt++;
}
}
if(Updt)
cout<<"Mobile Updated for Agent"<<UAno<<endl;
else ,
cout<<"Agent not in the Agency"<<endl;
F.close();
}Answer:
Statement 1
A.UpdateMobile()
Statement 2
F.seekpC-l*sizeof(A),ios::cur)
Question 9:
Fill in the blanks.marked as Statement 1 and Statement 2 in the program segment given below with appropriate functions for the required task. All India 2013
class Club
{
long int MNo; //Member number
char MName[20]; //Member name
char Email[30]; //Email of member
public:
void Register(); //Function to register member
void Disp(); //Function to display details
void ChangeEmail() //Function to change Email
{
cout<<"Enter Changed Email:";
cin>>Email;
}
long int GetMno()
{
return MNo;
}
};
void ModifyData()
{
fstream File;
File.open("CLUB.DAT",ios::binary|ios::in|ios::out);
int Modify = 0, Position;
long int ModiMno;
cout<<MMno-whose email required to be modified:";
cin>>ModiMno;
Club CL;
whi1e(!Modify&&Fi1e.read((char*)&CL,sizeof(CL)))
{
if(CL.GetMno() == ModiMno)
{
CL.ChangeEmail();
Position = File.tellgO-sizeof(CL);
//Statement 1:To place file pointer to the required position
____________________________________;
//Statement 2:To write the object CL onto the binary file
____________________________________;
Modify++;
}
}
if(Modify)
cout<<"Email Changed..."<<endl;
else
cout<<"Member not found.. ."<<endl;
File.close();
}Answer:
Statement 1
File.seekp(Position)
Statement 2
File.write((char*)&CL,sizeof(CL))
Question 10:
Fill in the blanks marked as Statement 1 and Statement 2 in the program segment given below with appropriate functions for the required task. Delhi 2013
class Customer
{
long int CNo; //Customer number
char CName[20]; //Customer name
char Email[30]; //Email of customer
public:
void Allocate(); //Function to allocate member
void Show(); //Function to show customer data
void ModifyEmail() //Function to modify Email
{
cout<<Enter Modified Email:";
gets(Email);
}
long int GetCno()
{
return CNo;
}
};
void ChangeData()
{
fstream File;
File.open("CUST.DAT", ios::binary|ios::in|ios::out);
int Change = 0, Location;
long int ChangeCno;
cout<<"Cno-whose Email required to be modified:";
cin>>ChangeCno;
Customer CU;
while(!Change && File.read((char*)&CU,sizeof(CU)))
{
if(CU.GetCno() = ChangeCno)
{
CU.ModifyEmai1();
Location = File.tellg()==sizeof(CU);
//Statement 1:To place file pointer to the required position
______________________________;
//Statement 2:To write the object CU on to the binary file
______________________________;
Change++;
}
}
if(Change)
cout<<”Email Modified..."<<endl;
else
cout<<"Customer not found..."<<endl;
File.close();
}Answer:
Statement 1
File.seekp(Location)
Statement 2
File.write((char*)&CU,sizeof(CU))

0 comments:
Post a Comment
Thanks for leaving a comment. As soon as it's approved, it will appear.