Study MaterialsCBSE NotesImportant Questions for Class 12 Computer Science (C++) – Data File Handling

Important Questions for Class 12 Computer Science (C++) – Data File Handling

Important Questions for Class 12 Computer Science (C++) – Data File Handling

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

    Register to Get Free Mock Test and Study Material

    +91

    Verify OTP Code (required)

    I agree to the terms and conditions and privacy policy.

    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))

    Question 11:
    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 2013C

    class Agent 
    {
    long ACode; //Agent Code
    char AName [20]; //Agent Name
    int Commission; 
    public:
    void Enter(); //Function to enter details of Agent
    void Display(); //Function to display details of Agent
    void Update(int C) //Function to modify commission
    {
    Commission = C;
    }
    int GetCommO {return Commission;} 
    long GetAcodeO {return ACode;}
    };
    void ChangeCommissiondong AC, int CM)
    //AC -> Agent Code, whose commission needs to change 
    //CM -> New commission 
    {
    fstream F;
    F.open("AGENT.DAT",ios::binary|ios::in|ios::out);
     char Changed = ' N';
    Agent A;
    while(Changed == 'N' && F.read((char*)&A,sizeof(A)))
    {
    if(A.GetAcode()==AC)
    {
    Changed = 'Y’;
    A.Update(CM);
    //Statement l:To place file pointer to the required position 
    ___________________________________;
    //Statement 2:To write the object A onto the binary file
    ___________________________________;
    }
    }
    if(Changed=='N')
    cout <<"Agent not registered..."; 
    F.close ();
    }

    Answer:
    Statement 1

    F.seekp(-1*sizeof(A),ios::cur)

    Statement 2

    F.write((char*)&A,sizeof(A))

    Question 12:
    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 2012C

    #include<fstream.h>
    class Movie
    {
    long MNo;  //Movie Hall Number
    char MName[20];   //Movie Name
    int Seats; //Number of Vacant Seats
    public:
    void MovieIn();
    void MovieOut();
    void Booking(int N) //Function to Book Seats
    {
    Seats _=N;
    }
    int RSeats()
    {
    return Seats;
    }
    long RMno()
    {
    return MNo;
    }
    };
    void BookMySeat(long MH,int S) //MH stands for Hall Number
    //S stands for Number of Tickets to purchase
    {
    fstream File;
    File.open("M0VIE.DAT", ios::binary|ios::in|ios::out); 
    int Found = 0, Booked = 0, Rec;
    Movie M;
    whileUFound && File.read((char*)&M,sizeof(M)))
    {
    if(M.RMnoC)==MH)
    {
    Found = 1;
    if((M.RSeats()-S)> 0)
    {
    M.Booking(S);
    Booked = 1;
    }
    else
    cout<<"House Full";
    }
    }
    if(Found && Booked)
    Rec = File.tellg()-sizeof(M);
    //Statement 1 : To place file pointer to the required position 
    ______________________;
    //Statement 2 : To write the object M on to the binary file
    ______________________;
    }
    if(! Found)
    cout<<"No updation done as Hall not found.";
    File.close();
    }

    Answer:
    Statement 1

    File.seekpCRec,ios: :beg)

    Statement 2

    File.write((char*)&M,sizeof(M))

    Question 13:
    Observe the program segment given below carefully and answer the questions that follow: All India 2012

    class Stock 
    {
    int Ino.Qty; 
    char Item[20]; 
    public:
    void Enter()
    {
    cin>>Ino; 
    gets(Item): 
    cin>>Qty;
    }
    void Issue(int Q) (Qty += Q;}
    void Purchase(int Q) (Qty-= Q;)
    int GetlnoO {return Ino;}
    };
    void Purchaseltem(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.Getlno())
    {
    S.Purchase(PQty);
    ____________ //Statement 1 
    ____________//Statement 2
    Success++;
    }
    }
    if(Success == 1)
    cout<<"Purchase Updated"<<endl; 
    else
    cout<<"Wrong item No."<<endl;
    File.closeO;
    }

    (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 updation is done in the binary file.

    Answer:
    Statement 1

    File.seekp(-1*sizeof(S),ios::cur);

    Statement 2

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

    Question 14:
    Observe the program segment given below carefully and answer the questions that follow: Delhi 2012

    class Inventory 
    {
    int Ano, Qty; char Article[20]; 
    public:
    void Input!()
    {
    cin>>Ano; 
    gets(Article); 
    cin>>Qty;
    }
    void Issue(int Q)HQty 4= Q;)
    void Procure(int Q) (Qty -= Q;)
    int GetAno()(return Ano:)
    };
    void ProcureArticle(int TAno, int TQty)
    {
    fstream File;
    File.open("ST0CK.DAT", ios::binary|ios::in|ios::out); 
    Inventory I; 
    int Found = 0;
    while(Found == 0 && File.read((char*)&I.sizeof(I)))
    {
    if (TAno == I.GetAno())
    {
    I.Procure(TQty);
    __________________ //Statement 1
    __________________ //Statement 2
    Found++;
    }
    if (Found == 1)
    cout<<"Procurement Updated"<<endl; 
    else
    cout<<"Wrong Article 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 Article.
    (ii) Write Statement 2 to perform the write operation, so that the updation is done in the binary file.

    Answer:
    Statement 1

    File.seekp(-1*sizeof(I),ios::cur);

    Statement 2

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

    Question 15:
    Observe the program segment given below carefully and fill in the blanks marked as Statement 1 and Statement 2 using seekg() or seekp() or tellg() or tellp() functions for performing the required task. Delhi 2011

    #include<fstream.h>
    class product
    {
    int pno;char pname[20];int qty;
    public:
    void modifyqty(); //Function is to modify quantity of product
    };
    void product::modifyqty()
    {
    fstream fil;
    file.open("product.dat",ios::binary|ios::in|ios::out);
    int mpno;
    cout<<”product number to modify quantity 
    cin>>mpno;
    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.writet(char*)this,sizeof(product));
    }
    }
    fil.close();
    }

    Answer:
    Statement 1

    fil.tellg( )-sizeof(product)

    Statement 2

    fil.seekp(Position) 
    
    or
    
    fil.seekp(-1*sizeof(product),ios::cur)

    Question 16:
    Observe the program segment given below carefully and fill in the blanks marked as
    Statement 1 and Statement 2. You can use any function from seekg(), seekp(), tellp() and tellg() for performing the required task. Delhi 2011C

    #include<fstream.h> 
    class Country
    {
    int Code; 
    char Name[20]; 
    int Population; 
    public:
    //Function to search and display the content from a particular record number
    void SearchFor(int);
    //Function to modify the content of a particular record number void Update(int);
    };
    void Country::SearchFor(int Record)
    {
    Country C; 
    fstream File;
    File.open("COUNTRY.DAT",ios::binary|ios::in);
    File.read((char*)&C,sizeof(C));
    _________ //Statement1
    cout<<C.Code<<"==>"<<C.Name<<"==>"<<C.Population<<endl;
    File.closet();
    }
    void Country::Update(int Record)
    {
    Country C;
    fstream File;
    Fi le.open("COUNTRY.DAT",ios::binary |ios::in|ios::out);
    cin>>C.Code;
    cin.getline(C.Name,20);
    cin>>C.Population;
    _________ //Statement 2
    File.write((char*)&C,sizeof(C));
    File.closet();
    }
    }

    Answer:
    Statement 1

    if(C.Code == Record);

    Statement 2

    File.seekp(-1*sizeof (C), ios:: cur);

    Question 17:
    Observe the program segment given below carefully and fill in the blanks marked as Statement 1 and Statement 2 using seekg(), seekp(), tellp() and tellg() functions for performing the required task. All India 2011

    #include<fstream.h>
    class ITEM 
    {
    int Ino; char Iname[20];
    float Price;
    public:
    void ModifyPrice(); //The function to modify price of a particular ITEM
    };
    void ITEM::ModifyPrice()
    {
    fstream File;
    File. open("ITEM.DAT",ios::binary|ios::in|ios::out); 
    int Cino;
    cout<<"Item No to modify price:"; 
    cin>>Cino;
    while(File.read((char*)this,sizeof(ITEM)))
    {
    if(Cino == Ino)
    {
    cout<<"Present Price:"<<Price<<endl;
    cout<<"Changed Price:"; 
    cin>>Price;
    int FilePos =___________; //Statement 1
    __________________; //Statement 2
    File.write((char*)this,sizeof(ITEM)); //Re-writing the record
    }
    }
    File.close();
    }

    Answer:
    Statement 1

    File.tellg()-sizeof (ITEM)

    Statement 2

    File.seekp(FilePos,ios::beg) 
    or
    File.seekp(-1*sizeof(ITEM),ios::cur)

    Question 18:
    Observe the program given below carefully and fill in the blanks marked as Statement 1 and Statement 2 using tellg() and seekp() functions for performing the required task. All India 2010

    #include<fstream.h> 
    class Customer
    {
    long Cno; char Name[20], Mobi1e[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 number whose mobile number needs to be changed
    cin>>Cnoc;
    while(F.read((char*)&C,sizeof(C)))
    {
    if(Cnoc == C.GetCno())
    C.Modify();
    //Statement 1 to find the current position of file pointer int Pos = _________________
    //Statement 2 to move the file pointer to write the 
    //modified record back onto the file for desired Cnoc
    F.write((char*)&C,sizeof(C));
    }
    F.close();
    }

    Answer:
    Statement 1

    F.tellg():

    Statement 2

    F.seekp(Pos-sizeof(C),ios::beg): 
    or
    F.seekp(-1*sizeof(C),ios::cur);

    Question 19:
    Observe the program segment given below carefully and fill in the blanks marked as Statement 1 and Statement 2 using tellg() and seekp() functions for performing the required task. Delhi 2010

    #include<fstream.h> 
    class Client 
    {
    long Cno;
    char Name[20], Email[30]; 
    public:
    void Enter(); //Function to allow user to enter the Cno.Name,Email 
    void ModifyO; //Function to allow user to enter(modify) Email 
    long ReturnCnoO (return Cno;}
    };
    void ChangeEmail ()
    {
    Client C;
    fstream F;
    F.open("INF0.DAT",ios::binary|ios::in|ios::out);
    long Cnoc; //Client’s number whose Email needs to be changed
    cin>>Cnoc;
    while(F.read((char*)&C,sizeof(C)))
    {
    if(Cnoc == C.ReturnCno())
    {
    C.Modify();
    //Statement 1 to find the current position of file pointer int Pos = ______________
    //Statement 2 to move the file pointer to write the 
    //modified record back onto the file for the desired Cnoc
    ______________
    F.write((char*)&C,sizeof(C));
    }
    }
    F.close();
    }

    Answer:
    Statement 1

    F.tellg():

    Statement 2

    F.seekp(Pos-sizeof(C),ios::beg);
    or
    F.seekp(-1*sizeof(C) ,ios: :cur);

    Question 20:
    Observe the program segment given below carefully and fill in the blanks marked as Line 1 and Line 2 using fstream function for performing the required task. All India 2009

    #include<fstream.h> 
    class Library 
    {
    long Ano; char Title[20]; 
    int Qty;
    public:
    void Enter(int): //Function to allow user to enter the data
    void Display(); //Function to display the content
    void Buy(int Tqty) //Function to increment qty
    {
    Qty += Tqty:
    }
    long GetAno() {return Ano;}
    };
    void BuyBookdong BAno,int BQty) //BAno : Ano of number of book purchased
    //QBty : Number of books purchased
    {
    Library L; 
    fstream File:
    File.open("STOCK.DAT".ios::bina ry|ios::in|ios::out); 
    int Position = -1:
    whileCPosition <<** - 1 && File.read((char*)&L,sizeof(L)))
    {
    if(L.GetAno( ) = = BAno)
    {
    L.Buy(BQty): //To update the number of books
    Position = File.tellg()-sizeof(L):
    _______________________;
    //Line 1 : to place the file pointer to the required position 
    _______________________;
    //Line 2 : to write the object L on to the binary file
    }
    if(Position == -1)
    cout<<"No updation done as required Ano not found:"; 
    File.close();
    }
    }

    Answer:
    Line 1

    File.seekp(Position)

    Line 2

    File,write((char*)&L,sizeof(L))

    Question 21:
    Observe the program segment given below carefully and fill in the blank marked as Statement 1 using seekg() or seekp() functions for performing the required task. Delhi 2009C

    #include<fstream.h> 
    class File_Object
    {
    int No;
    char Name[20]; 
    public:
    //Function to read Nth record from the file 
    void Goto_Record(int N);
    };
    void File_Object::Goto_Record(int N)
    {
    fstream File;
    File_Object Record;
    File.open("STOCK.DAT".ios::binary|ios::in);
    ____________ //Statement 1
    File.read((char*)&Record,sizeof(Record)); 
    cout<<Record. No<<Record.Name<<endl;
    }

    Answer:
    Statement 1

    File.seekg ((N -1)*sizeof (File_0bject));

    Question 22:
    Observe the program segment given below carefully and fill in the blanks marked as Line 1 and Line 2 using fstream function for performing the required task. Delhi 2009

    #include<fstream.h> 
    class Stock
    {
    long Ino; char ITem[20]; 
    int Qty; 
    public:
    void Get(int); //Function to allow user to enter the Ino, Item, Qty
    voidshow(); //Function to display the content
    void Purchase(int Tqty) //Function to increment qty 
    {
    Qty += Tqty;
    }
    long KnowIno() {return Ino;}
    void Purchaseitem(long PIno.int Pqty) //Pino : Ino of item purchased
    //Pqty : Number of item purchased
    {
    Stock S; 
    fstream File;
    File.open("ITEMS.DAT",ios:;binary|ios::in|ios:;out); 
    int Pos = -1;
    while (Pos == -1 && File.read((char*)&S,sizeof(S)))
    {
    if(S.KnowIno() == 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 object S on to the binary file*/
    }
    if(P o s == -1)
    cout<<”No updation done as required Ino Not found:";
    File.close();
    }

    Answer:
    Line 1

    File.seekp(Pos);

    Line 2

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

    Question 23:
    Polina Raj has used a text editing software to type some text in an article. After saving the article as MYNOTES.TXT, she realised that she has wrongly typed alphabet K in place of alphabet C everywhere in the article.
    Write a function definition for PURETEXT() in C++ that would display the corrected version of the entire article of the file MYNOTES. TXT with all the alphabets “K” to be displayed as an alphabet “C” on screen.
    NOTE Assuming that MYNOTES. TXT does not contain any C alphabet otherwise.
    Example:
    If Polina has stored the following content in the file MYNOTES.TXT:

    I OWN A KUTE LITTLE KAR.
    I KARE FOR IT AS MY KHILD.

    The function PURETEXT() should display the following content:

    I OWN A CUTE LITTLE CAR.
    I CARE FOR IT AS MY CHILD.

    Answer:

    void PURETEXTO 
    {
    fstream fp1;
    fp1. open("MYNOTES.txt",ios::in |ios::out);
    if(!fpl1)
    {
    cout<<"Cannot open file"<<endl;
    }
    char ch; 
    char c;
    whi1e(!fpl.eof())
    {
    c=fp1.get(); 
    if(c=='K')
    {
    fpl.seekg(-1, ios::cur); 
    fpl.put('C');
    }
    }
    fp1.clear();
    fp1.seekp(0,ios::beg); 
    cout<<"\n After replacing character\n";
    while(!fp1.eof())
    {
    fp1.get(ch); 
    cout<<ch;
    }
    fp1.close();
    }

    Question 24:
    Write a definition for function COUNTPICS() in C++ to read each object of a binary file PHOTOS.DAT, find and display the total number of PHOTOS of type PORTRAIT. Assume that the file PHOTOS.DAT is created with the help of objects of class PHOTOS, which is defined below:

    class PHOTOS
    {
    int PCODE;
    char PTYPE[20];//Photo Type as "PORTRAIT", "NATURE" 
    public:
    void ENTER()
    {
    cin>>PCODE;gets(PTYPE);
    }
    void SHOWCASE()
    {
    cout<<PC0DE<<": ”<<PTYPE<<endl;
    }
    char *GETPTYPE(){return PTYPE;}
    };

    Answer:

    void COUNTPICS( )
    {
    int count = 0:
    PHOTOS obj;
    ifstream fp1;
    fp1.open("PHOTOS.DAT", ios::binary);
    while (fp1.read((char*)&obj, sizeof(obj)))
    {
    if(strcmpi(obj.GETPTYPE!), "PORTRAIT")==0)
    count++;
    }
    cout<<"The total number of PHOTOS of type PORTRAIT is "<<count; 
    fp1.close();
    }

    Question 25:
    Write function definition fof WORD4CHAR() in C++ to read the content of a text file FUN.TXT and display all those words, which has four characters in it.
    e.g. If the content of the file FUN.TXT is as follows: Delhi 2016

    “When I was a small child, I used to play in the garden with my grand mom. Those days were amazingly funful and I remember all the moments of that time”

    The function WORD4CHAR() should display the following:

    “When used play with days were that time”

    Answer:

    void W0RD4CHAR()
    {
    ifstream fin("FUN.TXT”); 
    char word[80]; 
    while(!fin.eof())
    {
    fin>>word;
    if(strlen(word)==4&& 
    (!(word[3]<65| | (word[3]>90&& 
    word[3]<97)| | word[3]<122))) 
    cout<<word<<"";
    else if(strlen(word)==5&&((word[4] 
    <65| |word[4]>90)&&(word[4]<97| | 
    word[4]<122)))
    {
    for(inti=0;i<4;i++) 
    cout<<word[i]; 
    cout<<"";
    }
    }
    fin.close();
    }

    Question 26:
    Write a definition for function BUMPER() in C++ to read each object of a binary file GIFTS.DAT, find and display details of those gifts, which has remarks as “ON,DISCOUNT”. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below: Delhi 2016

    class GIFTS 
    {
    int ID;char Gift[20]. Remarks[20]; float Price: 
    public:
    void Takeonstock()
    {
    cin>>ID;gets(Gift) ;gets (Remarks) ;cin>>Price;
    }
    void See()
    {
    cout<<ID<<":"«Gift<<":" <<Price<< ": "<<Remarks<<endl;
    }
    char *GetRemarks() {return Remarks;
    };

    Answer:

    void BUMPER!)
    {
    GIFTS obj;
    ifstream infile!"GIFTS . DAT"); 
    while(infile.read!(char*)&obj, 
    sizeof(obj)))
    {
    if(strcmp (obj.GetRemarks(),
    "ON DISCOUNT") == 0) 
    obj See();
    }
    infile.close!);
    }

    Question 27:
    Write function definition of DISP3CHAR() in C++ to read the content of a text file KIDINME.TXT and display all those words, which has three characters in it. All India 2016
    e.g. If the content of the file KIDINME.TXT is as follows:

    ” When I was a small child, I used to play in the garden with my grand mom.
    Those days were amazingly funful and I remember all the moments of that time.”

    The function DISP3CHAR() should display the following:

    “was the mom and all the”

    Answer:

    void DISP3CHAR()
    {
    ifstream fin("KIDINME.TXT"); 
    char word[80];
    while(!fin.eof())
    {
    fin>>word;
    if(strlen(word)==3&&(! 
    (word[2]<65| |(word[2]>90&&word 
    [2]<97)| | word[2]<122))) 
    cout<<word<<"“; 
    else if(strlen(word)==4&&
    ((word[3]<65| |word[3]>90)&& 
    (word[3]<97| |word[3]>122)))
    {
    for(int i=0;i<3;i++) 
    cout<<word[i];
    cout<<" ”;
    }
    }
    fin.close();
    }

    Question 28:
    Write a definition for function ONOFFER() in C++ to read each object of a binary file TOYS.DAT, find and display details of those toys, which has status as “ON OFFER”. Assume that the file TOYS.DAT is created with the help of objects of class TOYS, which is defined below: All India 2016

    class TOYS
    {
    int TID;char Toy[20],Status[20];float MRP;
    public:
    void Getinstock()
    {
    cin>>TID;gets(Toy);gets(Status);cin>>MRP;
    }
    voidView()
    {
    cout<<TID<<": ”<<Toy<<": "<<MRP<<n": "<<Status<<endl;
    }
    char*SeeOffer()(return Status;}
    };

    Answer:

    void ONOFFER()
    {
    TOYS obj;
    ifstream i nfileCTOYS.DAT"); 
    while( infile.read((char*)&obj, 
    sizeof(obj)))
    {
    if(strcmp(obj.SeeOffer(),
    "ON OFFER")==0) 
    obj.View();
    }
    infile.closer()
    }

    Question 29:
    Write function definition for WORDABSTART ()in C++ to read the content of a text file JOY.TXT, and display all those words, which are starting with either ‘A’, ‘a’ or ‘B’, ‘b’. All India (C) 2016
    e.g. If the content of the file JOY.TXT is as follows:

    “I love to eat apples and bananas. I was travelling to Ahmedabad to buy some clothes.”

    The function WORDABSTART() should display the following:

    “apples and bananas Ahmedabad buy”

    Answer:

    void WORDABSTART()
    {
    ifstream fin("JOY.TXT"); 
    char ch[80]; 
    while (!fin.eof())
    {
    fin>>ch;
    if(ch[0]—'A' | |ch[0]='a'| |ch[0] 
    =='b' 11 chCO]—'B’) 
    cout<<ch<<'"';
    }
    fin.close();
    }

    Question 30:
    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. Delhi 2015

    NOTE -The word STORY should be an independent word
    -Ignore type cases (i.e. lower/upper case)

    e.g. 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”

    Answer:
    There is error in this question. STORY should be replaced by SUCCESS word, i.e. we have to count SUCCESS word according to output.

    void SUCCESS()
    {
    ifstream in("STORY.TXT"); 
    char ch[200];
     int count = 0; 
    while(!in.eof())
    {
    in>>ch;
    if(strcmpi(ch,"success")==0) 
    count++;
    }
    cout<<count; 
    in.close();
    }

    Question 31:
    Write a definition for function Economic() in C++ to read each record of a binary file ITEMS.DAT, find and display those items, which cost less than 2500. Assume that the file ITEMS.DAT is created with the help of objects of class ITEMS, which is defined below: Delhi 2015

    class ITEMS 
    {
    int ID; char GIFTC20]; float Cost:
    public:
    void Get()
    {
    cin>>ID; gets (GIFT) ;cin>>Cost;
    }
    void See()
    {
    cout<<ID<<": "<<GIFT<<": "<<Cost<<endl;
    }
    float GetCost(){return Cost;}
    }:

    Answer:

    void Economic() 
    {
    ifstream fcinCITEMS.DAT",ios:: in|ios::binary):
    ITEMS i; 
    float co;
    while(fcin.read((char*)&i,
     sizeof(i)))
    {
    co=i.GetCost(); 
    if(co<2500) 
    i.See();
    }
    fcin.close();
    }

    Question 32:
    Write function definition for TOWER() in C++ to read the content of a text file WRITEUP.TXT, count the presence of word TOWER and display the number of occurrences of this word. All India 2015

    NOTE – The word TOWER should be an independent word.
    – Ignore type cases (i.e. lower/upper case).
    e.g. If the content of the file WRITEUP.TXT is as follows:

    “Tower, of hanoi is an interesting problem. Mobile phone tower is away from here. Views from EIFFEL TOWER are amazing.”

    The function TOWER() should display the following :

    “3 ”

    Answer:

    void TOWER()
    {
    ifstream in("WRITEUP.TXT"); 
    char ch[200]; 
    int count = 0; 
    while(!in.eof())
    {
    i n >> c h;
    if(strcmpi (ch,"Tower") == 0) 
    count++;
    }
    cout<<count; 
    in.close ();
    }

    Question 33:
    Write a definition for function COSTLY() in C++ to read each record of a binary file GIFTS.DAT, find and display those items, which are priced more than 2000. Assume that the file GIFTS.DAT is created with the help of objects of class GIFTS, which is defined below: All India 2015

    class GIFTS 
    {
    int CODE: char ITEMC20]: float PRICE; 
    public:
    void Procure()
    {
    cin>>CODE; gets(ITEM): cin>>PRICE; 
    }
    void View()
    {
    cout<<C0DE<<": "<<ITEM<<": "<<PRICE<<endl;
    }
    float GetPrice() {return PRICE:)

    Answer:

    void COSTLY()
    {
    ifstream fcinCGIFTS.DAT", 
    ios :: in|ios :: binary); 
    GIFTS g; 
    float pr;
    while(fcin.read((char*)&g, 
    sizeof(g)))
    {
    pr=g.GetPrice(); 
    if (pr>2000)
    g.View();-
    }
    fcin.close();
    }

    Question 34:
    Write function definition for COUNTNU( )in C++ to read the content of a text file
    CONTENT.TXT, count the characters N and U (in lower case as well as upper case) present in the file. All India 2015 C
    e.g. Assume the content of the file CONTENT. TXT is as follows:

    “New research shows that our closest evolutionary relatives have all of the cognitive, capacities required for cooking except an understanding of how to control fire.”

    The function COUNTNU( )should display the following:
    “13”

    Answer:

    void COUNTNU()
    {
    ifstream fin("C0NTENT.TXT"); 
    char C; 
    int count=0; 
    while(!fin.eof())
    {
    C=fin.get();
    if(fin.eofO)
    break;
    if(C=='N'||C=='n'||C= ='U'||C= ='u'|
    count++;
    }
    fin.close(); 
    cout<<count;
    }

    Question 35:
    Write a function EUCount() in C++, which should reads each character of a text file. “IMP.TXT”, should count and display the occurrence of alphabets E and U (including small cases e and u too). Delhi 2014
    e.g. If the file contains is as follows:

    Update information is simplified by official websites.

    The EUCount() function should display the output as:

    E : 4 
    U : 1

    Answer:

    void EUCount() 
    {
    ifstream infiie("IMP.TXTn); 
    char ch;
    int countE=0,countU=0; 
    while(infile)
    {
    infile.get(ch);
     if(ch=='E' | | ch=='e')
    countE++;
    else if(ch=='U' || ch=='u') 
    countU++; '
    }
    cout<<"E ; "<<countE<<endl; 
    cout<<"U : "<<countU;
    }

    Question 36:
    Assuming the class GAMES as declared below, write a function in C++ to read the objects of GAMES from binary file “GAMES.DAT” and display the details of those GAMES, which are meant for children of AgeRange “8 to 13”. Delhi 2014

    class GAMES
    {
    int GameCode; 
    char GameName[10]; 
    char *AgeRange; 
    public:
    void Enter()
    {
    cin>>GameCode;
    gets(GameName);
    gets(AgeRange);
    }
    void Display()
    {
    cout<<GameCode<<": "<<GameName<<endl; 
    cout<<AgeRange<<endl;
    }
    char*AgeR() {return AgeRange;}
    };

    Answer:

    void READGAMES() 
    {
    GAMES obj;
    ifstream infileCGAMES.DAT"); 
    whi1e(infile.read((char*)&obj, 
    sizeof(obj)))
    {
    if(strcmp(obj.AgeR(),"8 to 13") == 0)
    obj.Display();
    }
    infile.close();
    }

    Question 37:
    Write a function AECount() in C++, which should read each character of a text file “NOTES.TXT”, should count and display the occurrence of alphabets A and E (including small cases a and e too). All India 2014
    e.g. If the file content is as follows: .

    CBSE enhanced its
    CCE guidelines further.

    The AECount() function should display the output as

    A: 1 
    E: 7

    Answer:

    void AECount()
    {
    ifstream infile(”NOTES.TXT"); 
    char ch;
    int countA=0.countE=0; 
    while(infile)
    {
    infile.get(ch);
    if(ch==' A ’ | | ch=='a') 
    countA++;
    else if(ch= = 'E' || ch= = 'e') 
    countE++;
    }
    cout<<"A : "<<countA<<endl; 
    cout<<"E : "<<countE;
    }

    Question 38:
    Assuming the class TOYS as declared below, write a function in C++ to read the objects of TOYS from binary file “TOYS.DAT” and display the details of those TOYS, which are meant for children of Age Range “5 to 8”. All India 2014

    class TOYS 
    {
    int ToyCode;
    char ToyName[10]; 
    char *AgeRange; 
    public:
    void Enter()
    {
    cin>>ToyCode; 
    gets(ToyName); 
    gets(AgeRange);
    }
    void Display() 
    {
    cout<<ToyCode<<": "<<ToyName<<endl; 
    cout<<AgeRange<<endl;
    }
    char* WhatAge()I return AgeRange;}
    };

    Answer:

    void READTOYS()
    {
    TOYS obj;
    ifstream infile!"TOYS.DAT"); 
    while(infile.read((char*)&obj, sizeof(obj)))
    {
    if(strcmp(obj.WhatAge(),
    "5 to 8") == 0) 
    obj .Display!);
    }
    infile.close();
    }

    Question 39:
    Given a binary file “SPORTS.DAT” containing records programme following class: All India (C) 2014

    class Player 
    {
    char PNO[10]; //Player number
    char Name [20]; //Name of player
    int rank; //Rank of the player
    public:
    void EnterData()
    {
    gets (PNO); gets (Name) ;cin>>rank;
    }
    void DisplayData ()
    {
    cout<<setw(12)<<PN0; 
    cout<<setw(32)<<Name; 
    cout<<setw(3)<rank<<endl;
    }
    int Ret_rank(){return rank;}
    };

    Write a function in C++ that would read contents of the file “SPORTS.DAT” and display the details of those players whose rank is above 500.

    Answer:

    void READPLAYER()
     {
    Player obj;
    ifstream infileCSPORTS.DAT"); 
    while(infile.read(char*)&obj, 
    sizeof(obj)))
    {
    if(obj.Ret_rank()>500)
    obj.DisplayDataO;
    }
    infile.close();
    }

    Question 40:
    Write a function Countaroma() to count and display the number of times “Aroma” occurs in a test file “Cook.txt”.
    All India (C) 2014
    NOTE Only complete word “Aroma“should be counted. Words like “Aromatic“should not be counted.

    Answer:

    void Countaroma()
    {
    ifstream inC'Cook.TXT"); 
    char ch[200]; 
    int count=0; 
    while(!in.eof())
    {
    in>>ch;
    if(strcmpi (ch, "aroma")=0) 
    count++;
    }
    cout<<count; 
    in.close();
    }

    Question 41:
    Write a function CountYouMef) in C++, which reads the content of a text file “story.txt” and counts the words You and Me (not case sensitive). All India 2013
    e.g. if the file contains:

    You are my best friend.
    You and me make a good team.

    The function should display the output as

    Count for You: 2 
    Count for Me: 1

    Answer:

    void CountYouMe()
    {
    ifstream Filein; 
    char arr[10]; clrscr();
    Filein.open("story.txt", ios::in);
    i f (! Filein)
    {
    cout<<"File does not exist!"; 
    exit(0);
    }
    int i=0,j=0; 
    while(!Filein.eof ())
    {
    Filein>>arr;
    if(strcmpi(arr,"You")==0) 
    i++;
    else if(strcmpi(arr,"Me")==0) 
    J++:
    }
    Filein.close();
    cout<<"Count for Yog:"<<i<<endl; 
    cout<<"Count for Me: "<<j<<endl;
    }

    Question 42:
    Write a function CountDig() in C++, which reads the content of text file “story.txt” and displays the number of digits in it.
    Delhi (C) 2013
    e.g. if the file contains:

    Amrapali was a queen of Gareware kingdom in 
    the year 1911. She had 2 daughters.
    Her palace had 200 rooms.

    Then the output on the screen should be

    Number of digits in story:8

    Answer:

    void CountDig()
    {
    int count=0; 
    char Ch;
    ifstream fcin("story.txt"); while(fcin)
    {
    fcin.get(Ch); 
    if(Ch>=48&&Ch<=57)
    {
    count++;
    }
    }
    cout<<"Number of digits in story; "<<count;
    fcin.close();
    }

    Question 43:
    Assuming the class WORKER as declared below, write a function in C++ to read the objects of WORKER from binary file named “WORKER.DAT” and display those records of workers, whose wage is less than 300. Delhi 2013C

    class WORKER
    {
    int WN0;
    char WName[30]; float Wage; 
    public:
    void EnterO (cin>>WN0;gets(WName); cin>>Wage;}
    void DISP() {cout<<WNO<<"*"<<WName<<"*"<<Wage<<endl;}
    float GetWageC) (return Wage;}
    };

    Answer:

    void SHOW()
    {
    ifstream fcin!"WORKER.DAT", ios;;in|ios::binary);
    WORKER W;
    whi le(fcin.read((char*)&W, 
    sizeof(W)))
    {
    if(W.GetWage()<300)
    {
    W.DISP();
    }
    }
    fcin.close();
    }

    Question 44:
    Write a function CountHisHer() in C++, which reads the contents of a text file “diary.txt” and counts the words His and Her (not case sensitive). Delhi 2013
    e.g. if the file contains:

    Pinaky has gone to his friend's house. His friend's name is Ravya. Her house is 12 KM from here.

    The function should display the output as

    Count for His : 2 
    Count for Her : 1

    Answer:

    void CountHisHer()
    {
    ifstream AL;
    AL.open("diary.txt",ios;:in); 
    char Word[80]; 
    int C1=0, C2=0;
    while(!AL.eof())
    {
    AL>>Word;
    if(strcmpi(Word, "His")==0)
     C1++;
    else if(strcmpi(Word, "Her")==0)
    C2++;
    }
    cout<<"Count for His :"<<C1 <<endl;
    cout<<"Count for Her : "<<C2<<endl;
    AL.close();
    }

    Question 45:
    Assuming the class VINTAGE as declared below, write a function in C++ to read the objects of VINTAGE from binary file “VINTAGE.DAT” and display those vintage vehicles, which are priced between 200000 and 250000. Delhi 2013

    class VINTAGE 
    {
    int VNO; //Vehicle Number
    char VDesc[10]: //Vehicle Description
    float Price; 
    public:
    void GET() {cin>>VN0;gets! VDesc) ;cin>>Price;}
    void VIEW()
    {
    cout<<VNO<<endl ; 
    cout<<VDesc<<endl; 
    cout<<Price<<endl;
    }
    float ReturnPrice()
    {
    return Price;
    }
    };

    Answer:

    void show()
    {
    ifstream fcin("VINTAGE.DAT", 
    ios::in|ios::binary);
    VINTAGE V; 
    float pr;
    while(fcin.read((char*)&V, sizeof(V))) 
    {
    pr = V.ReturnPrice();
    if(pr>=200000 && pr<=250000)
    {
    V.VIEW();
    }
    }
    fcin.close();
    }

    Question 46:
    Assuming the class ANTIQUE as declared below, write a function in C++ to read the objects of ANTIQUE from binary file “ANTIQUE.DAT” and display those antique items, which are priced between 10000 and 15000. All India 2013

    class ANTIQUE 
    {
    int ANO; 
    char Aname[10]; 
    float Price; 
    public:
    void BUY()
    {
    cin>>ANO.;gets(Aname); 
    cin>>Price;
    }
    void SHOW() 
    {
    cout<<AN0<<endl; 
    cout<<Aname<<endl;
    cout<<Price<<endl ;
    }
    float GetPricel){return Price;}
    };

    Answer:

    void search()
    {
    ifstream ifile("ANTIQUE.DAT”, 
    ios::in|ios::binary); 
    if (! ifile)
    {
    cout<<"could not open ANTIQUE.
    DAT; exit(-1);
    }
    else
    {
    ANTIQUE a;
    whileCifile.read((char*)&a, sizeof(a)))
    {
    if(a.GetPrice()>=10000&& 
    a.GetPrice()<=15000) 
    a.SHOW();
    }
    }
    }

    Question 47:
    Write a function in C++ to read the content of a text file “PLACES.TXT” and display all those lines on screen, which are either starting with ‘P’ or starting with ‘S’. Delhi 2012
    Answer:

    void Display()
    {
    ifstream fcin("PLACES.TXT"); 
    char Ch[100]; .
    fcin.getline(Ch.100); 
    while(!fcin.eof())
    {
    if(Ch[0]=='P'|| ChCO]=='S')
    {
    cout<<Ch<<endl;
    }
    fcin.getline(Ch,100);
    }
    fcin.close();
    }

    Question 48:
    Write a function in C++ to read the content of a text file “DELHI.TXT” and display all those lines on screen, which are either starting with ‘D’ or starting with ‘M’. All india 2012
    Answer:

    void Display()
    {
    char str[100]; 
    ifstream fcin("DELHI.TXT"); 
    fcin.getline(str,100); 
    while(!fcin.eof!)
    {
    if(str[0]=='D' | |str[0]— ’M’) 
    {
    cout<<str<<endl;
    }
    fcin.getline(str,100);
    }
    fcin.close()
    {

    Question 49:
    Write a function in C++ to search for the details (Number and Calls) of those Mobile phones, which have more than 1000 calls from a binary file “mobile.dat”. Assuming that this binary file contains records/objects of class Mobile, which is defined below. Delhi 2012

    class Mobile
    {
    char Number[10];int Calls; 
    public:
    void Enter() fgets(Number) ;cin>>Calls;}
    void Billing!) {cout<<Number<"#"<<Calls<<endl;}
    int GetCal1s() (return Calls;)
    };

    Answer:

    void Display()
    {
    Mobile M;
    ifstream fcinCmobile.dat",
    ios;; in | ios:: binary) ; 
    fcin.read!(char*)&M, sizeof(M)); 
    while(fin.eofc)
    {
    if(M.GetCalIs()>1000)
    {
    M.Billing();
    }
    fcin.read((char*)&M,sizeof(M));
    }
    fcin.close();
    }

    Question 50:
    Write a function C++ to search for the details (Phoneno and Calls) of those phones, which have more than 1000 calls from a binary file “phones.dat”. Assuming that this binary file contains records/objects of class Phone, which is defined below.
    All India 2012

    class Phone
    {
    char Phoneno[10];int Calls; 
    public:
    void get(){gets(Phoneno) ;cin>>CalIs;}
    void billing() (cout<<Phoneno<<"#”<<Calls<<endl;}
    int getCal1s()(return Calls;}
    };

    Answer:

    void show()
    {
    ifstream fcin!"phones.dat".
    ios::in|ios::binary);
    Phone P;
    fcin.read((char*)&P,sizeof(P)); 
    while(fcin)
    {
    if(P.getCalls()>1000)
    {
    P.billing();
    }
    fcin.read((char*)&P,sizeof(P));
    }
    fcin.close();
    }

    Question 51:
    Write a function in C++ to count the number of “Me” or “My” words present in a text file “DIARY.TXT”. If the file “DIARY.TXT” content is as follows: Delhi 2011

    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 : 4

    Answer:

    void count()
    {
    ifstream fin!"DIARY.TXT");
    char word[10];
    int C = 0;
    while(!fin.eof())
    {
    fin>>word; *
    if((strcmpi(word,"Me")== 0)
    ||(strcmpi(word,"My")== 0))
    C++;
    }
    cout<<Count of Me/My in file:"<<C; fin.close();
    }

    Question 52:
    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 ModelNo and the function should search and display the details of the LAPTOP. Delhi 2011

    class LAPTOP
    {
    long ModelNo; 
    float RAM,HDD; 
    char Details[120];
    public
    void StockEnter( Hcin>>ModelNo>>RAM>>HDD;gets(Detail s);}
    void StockDisplay() {cout<<Model No<<RAM<<HDD<<Details<<endl;} 
    long ReturnModelNo(){return ModelNo;}
    };

    Answer:

    void Search() 
    {
    LAPTOP L;
    long Model No; 
    if stream fin;
    cout<<"enter the model no of laptop:"; cin>>ModelNo; 
    fin.open("LAPTOP.DAT", ios:binary); 
    while(fin.read((char*)&L, sizeof(L))
    {
    if(L.ReturnModelNo() == Model No) 
    }
    L.StockDisplay();
    }
    fin.close();
    }

    Question 53:
    Write a function in C++ to count the number of “He” or “She” words present in a text file “STORY.TXT”. If the file “STORY.TXT” content is as follows. All India 2011

    He is playing in the ground. She is playing with her dolls.

    The output of the function should be

    Count of He/She in file:2

    Answer:

    void Wordcount()
    }
    ifstream finOSTORY.TXT"); 
    char word [10]; 
    int C=0;
    while(!fin.eof())
    {
    fin>>word;
    if ((strcmpi (word, "He" )== 0)
    ||(strcmpi(word,"She") == 0)) 
    C++;
    }
    cout<<"Count of He/She in file : 
    ”<<C;
    fin.close();
    }

    Question 54:
    Write a function in C++ to search for a camera from a binary file “CAMERA.DAT” containing the objects of class CAMERA (as defined below). The user should enter the ModelNo and the function should search and display the details of the camera.
    All India 2011

    class CAMERA 
    {
    long Model No; 
    float Megapixel; 
    int Zoom;
    char Detai1s[120]; .
    public;
    void Enter() (cin>>ModelNo>>MegaPixel>>Zoom; gets (Detai Is);} 
    void Display() (cout<<Model No<<MegaPixel <<Zoom<<Details<<endl;} 
    long GetModelNo(){return ModelNo;}
    };

    Answer:

    void SearchCam()
    {
    CAMERA C; 
    long Model No; 
    ifstream fin;
    cout<<"enter the camera model no:"; 
    cin>>ModelNo;
     fin.openCCAMERA.DAT", ios::binary);
    while(fin.read((char*)&C, sizeof(C)))
    {
    if (C.GetModel No()==ModelNo) 
    C.Display();
    }
    fin.close();
    }

    Question 55:
    Write a function in C++ to count the words “to” and “the” present in a text file “POEM.TXT”. (Note that the words “to” and “the” are complete words) All India 2010
    Answer:

    void Wordcount()
    {
    ifstream fin("P0EM.TXT"); 
    char word[80]; 
    || int WC=0;
    while(ifin.eof())
    {
    fin>>word;
    if((strcmp(word,"to")== 0)
    11Cstrcmp(word,"the")— 0)) 
    WC++;
    }
    cout<<"Count of to/the in file;
    "<<WC;
    fin.close();
    }

    Question 56:
    Write a function in C++ to search and display details of all trains, whose destination is “Delhi” from a binary file “TRAIN.DAT”. Assuming the binary file is containing the objects of the following class: All India 2010

    class TRAIN
    {
    int Tno; //Train number
    char From[20]; //Train starting point
    charTo[20]; //Train destinaton
    public:
    char *GetFrom()(return From;}
    char *GetTo(){return To;}
    void InputO (cin>>Tno; gets(From);gets(To):}
    void Show() {cout<<Tno<<":"<<From<<":"<<To<<endl;}
    };

    Answer:

    void Read() 
    {
    TRAIN T; 
    ifstream fin;
    fin.open("TRAIN.DAT",ios::binary); 
    while(fin.read((char*)&T,sizeof(T))) 
    {
    if(strcmpi(T.GetTo(), "Del hi")== 0)
    T.Show();
    }
    fin.close!);
    }

    Question 57:
    Write a function in C++ to count the words “this” and “these” present in a text file “ARTICLE.TXT”. [Note that the words “this” and “these” are complete word] Delhi 2010
    Answer:

    void Wordcount()
    {
    ifstream finCARTICLE.TXT"); 
    char word[80];
    int C=0;
    while!ifin.eof())
    {
    fin>>word;
    if((strcmpi(word,"this") == 0)
    ||(strcmpi(word,"these") == 0)) 
    C++;
    }
    cout<<"Number of this and these words are; "<<C; 
    fin.close();
    }

    Question 58:
    Write a function in C++ to search and display details of all flights, whose destination is “Mumbai” from a binary file “FLIGHT.DAT”. Assuming the binary file is containing the objects of the following class: Delhi 2010

    class FLIGHT
    { 
    int Fno; //flight number
    char From[20]; //flight starting point
    char To[20]; //flight destination
    public:
    char *GetFrom(){return From;}
    char *GetTo(){return To;}
    void Enter(){cin>>Fno;gets(From);gets(To);}
    void Display()(cout<<Fno<<":”<<From<<”:"<<To<<endl;}
    };

    Answer:

    void Read()
    {
    FLIGHT F;
    ifstream fin;
    fin.open("FLIGHT.DAT", ios::binary); 
    while(fin.read((char*)&F, 
    sizeof(F)))
    {
    if(strcmpi(F.GetTo(), "Mumbai") == 0)
    F.Display();
    }
    fin.close!);
    }

    Question 59:
    Write a function COUNT_TO() in C++ to count the presence of a word ‘To” in a text file “NOTES.TXT”. All India 2009
    If the content of the file “NOTES.TXT” is as:

    It is very important to know that 
    Smoking is injurious to health 
    Let us take initiative to stop it

    The function COUNT_TO() will display the following message:
    Count of-to-in file: 3
    Answer:

    void COUNT_TO
    {
    ifstream fin("N0TES.TXT"); 
    char str[10]; 
    int C=0;
    while(!fin.eof)))
    {
    fin>>str;
    if(strcmpi(str,"To")==0)
    C++;
    }
    fin.close(); 
    cout<<"Count of-to-in file: "<<C<<endl;
    }

    Question 60:
    Write a function in C++ to read and display the details of all the users whose membership type is ‘L’ or ‘M’ from a binary file “CLUB.DAT”. Assuming the binary file “CLUB.DAT” is containing objects of class CLUB, which is defined as follows: All India 2009

    class CLUB
    {
    int Mno; 
    char Mname[20]; //member name
    char Type: //member type:L Life Member M Monthly Member G Guest
    public:
    void Register(); //function to enter the content
    void Display();  //function to display all data members 
    char *WhatType() {return Type;}

    Answer:

    void DisplayMember()
    {
    CLUB C; 
    ifstream fin;
    fin.open("CLUB.DAT",ios::binary);
    while(fin.read((char*)&C,
    sizeof(C)))
    {
    if(((strcmpi(C.whatType!),"L") ==0)||(strempi(C.whatType (), "M" )==0))) 
    C.DisplayO;
    }
    fin. close();
    }

    Question 61:
    Write a function COUNT_DO() in C++ to count the presence of a word ‘do’ in a text file “MEMO.TXT”. Delhi 2009
    If the content of the file “MEMO.TXT” is as

    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 file: 2

    Answer:

    void C0UNT_D0()
    {
    ifstream fin!("MEM0.TXT"); 
    char str[10]; 
    int C = 0; 
    while(!fin.eof)))
    {
    fin>>str;
    if(strcmpi(str,"Do")== 0)
    C++;
    }
    fin.close();
    cout<<"Count of do in file:" <<C<<endl;
    }

    Question 62:
    Write a function in C++ to read and display the details of all the users whose status is ‘A’ (i.e. Active) from a binary file “USER.DAT”. Assuming the binary file “USER.DAT” is containing objects of class USER, which is defined as follows: Delhi 2009

    class USER 
    {
     int Uid;
     char Uname[20]; //username
     char Status: // user type : A active I inactive
     public:
     void Register(); //function to enter the content
     void Show(); //function to display all data members
     char *GetStatus(){return Status;}
    };

    Answer:

    void DisplayActive()
    {
    USER U;
    ifstream fin;
    fin.open("USER.DAT",ios::binary); 
    while(fin.read!(char*)&U,sizeof(U))) 
    {
    if(strcmpi(U.Get status(),
    "A”)—0)
    U.Show();
    }
    fin. close();
    }

     

    Chat on WhatsApp Call Infinity Learn

      Register to Get Free Mock Test and Study Material

      +91

      Verify OTP Code (required)

      I agree to the terms and conditions and privacy policy.