CBSE Class 12 Informatics Practices File Handling Worksheet

Read and download the CBSE Class 12 Informatics Practices File Handling Worksheet in PDF format. We have provided exhaustive and printable Class 12 Informatics Practices worksheets for File Handling, designed by expert teachers. These resources align with the 2026-27 syllabus and examination patterns issued by NCERT, CBSE, and KVS, helping students master all important chapter topics.

Download Class 12 Informatics Practices File Handling Printable Sheet

Students of Class 12 should use this Informatics Practices practice paper to check their understanding of File Handling as it includes essential problems and detailed solutions. Regular self-testing with these will help you achieve higher marks in your school tests and final examinations.

Download Worksheet: File Handling (Class 12 Informatics Practices)

Q1. Write a function in C++ to count the number of uppercase alphabets present in a text file n“ ARTICLE.TXT”.

Q2. Write a function to count and print the number of complete words as “to” and “are” stored in a text file “ESSAY.TXT”.

Q3. Write a function in C++ to display lines starting with alphabet ‘A’ or alphabet ‘E’ present in a text file “LINES.TXT”.

TYPE 3 Question :Function write type questions Based on binary files

Q1. Given a binary file “BUS.DAT”, containing records of the following class bus type.
class bus
{ int bus_no;
char desc[40];
int distance; //in km
public:
void read( )
{ cin>>bus_no; gets(desc) ; cin>>distance; }
void display( )
{ cout<<bus_no; puts(desc); cout<<distance; }
int retdist( )
{ return distance; }
};
Write a function in C++ that would read the contents of file “BUS.DAT” and display the details of those buses which travels the distance more than 100 km.

Q2. Given a binary file Sports.dat, containing records of the following structure type:
Struct Sports
{
Char Event[20];
Char Participant[10][30];
};
Write a function in C++ that would read contents from the file Sports .dat and creates a file named Athletic.dat copying only those records from Sports.dat where the event name is “Athletics”.

Q3. Given a binary file TELEPHON.DAT, containing records of the following class Directory :
class Directory
{
char Name [20] ;
char Address [30] ;
char AreaCode[5] ;
char Phone_No[15] ;
public :
void Register ( ) ;
void Show ( ) ;
int CheckCode (char AC [ ] )
{
return strcmp ( AreaCode , AC ) ;
}
};
Write a function COPYABC ( ) in C++ , that would copy all those records having AreaCode as “123” from TELEPHON.DAT to TELEBACK.DAT.

Q4. Write a function in C++ to display object from the binary file “PRODUCT.Dat” whose product price is more than Rs 200. Assuming that binary file is containing the objects of the following class:
class PRODUCT
{
int PRODUCT_no;
char PRODUCT_name[20];
float PRODUCT_price;
public:
void enter( )
{
cin>> PRODUCT_no ; gets(PRODUCT_name) ;
cin >> PRODUCT_price;
}
void display()
{
cout<< PRODUCT_no ; cout<<PRODUCT_name ;cout<< PRODUCT_price;
}
int ret_Price( )
{
return PRODUCT_price;
}
};

Q5. Given the binary file CAR.Dat, containing records of the following class CAR type:
class CAR
{
int C_No;
char C_Name[20];
float Milage;
public:
void enter( )
{
cin>> C_No ; gets(C_Name) ; cin >> Milage;
}
void display( )
{
cout<< C_No ; cout<<C_Name ; cout<< Milage;
}
int RETURN_Milage( )
{
return Milage;
}
};
Write a function in C++, that would read contents from the file CAR.DAT and display the details of car with mileage between 100 to 150.

Q6. Write a function in C++ to search for a BookNo from a binary file “BOOK.DAT”, assuming the binary file is containing the objects of the following class.
class BOOK
{
int Bno;
char Title[20];
public:
int RBno(){return Bno;}
void Enter(){cin>>Bno;gets(Title);}
void Display(){cout<<Bno<<Title<<endl;}
};

Q7. Write a function in C++ to add new objects at the bottom of a binary file “STUDENT.DAT”, assuming the binary file is containing the objects of the following class.
class STUD
{
int Rno;
char Name[20];
public:
void Enter(){cin>>Rno;gets(Name);}
void Display(){cout<<Rno<<Name<<endl;}
};
void Addnew()
{
fstream FIL;
FIL.open(“STUDENT.DAT”,ios::binary|ios::app);
STUD S;
char CH;
do
{
S.Enter();
FIL.write((char*)&S,sizeof(S));
cout<<”More(Y/N)?”;cin>>CH;
}
while(CH!=’Y’);
FIL.close();
}

Q8. Write a function in C++ to search and display the details of all flights, whose destination is “Mumbai” from “FLIGHT.DAT”. Assuming the binary file is
containing objects of class.
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 ;}
};

Q9. Given a binary file GAME.DAT, containing records of the following structure type
struct Game
{
char GameName [20];
char Participant [10] [30];
};
Write a function in C++ that would read contents from the file GAME.DAT and creates a file named BASKET.DAT copying only those records from GAME.DAT where the game name is “Basket Ball”.

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

TYPE 1 QUESTION : ( Statement write type questions )

Q1. 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));
cout<<Ino<<"==>"<<Item<<endl;
File.close();
}
void Item::Modify(int RecNo)
{
fstream File;
File.open("STOCK.DAT",ios::binary|ios::in|ios::out);
cout>>Ino;cin.getline(Item,20);
______________________ //Statement 2
File.write((char*)this,sizeof(Item));
File.close();
}

Q2. 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;
}

Q3. Write the command to place the file pointer at the 10th and 4th record starting position using seekp() or seekg() command. File object is ‘file’ and record name is ‘STUDENT’.

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

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

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

Q7. Observer the program segment carefully and fill in the blanks marked as statement 1& 2
#include<fstream.h>
class MATERIAL
{
int Mno;char Mname[25]; int qty;
public:
:
void ModifyQty();
};
void MATERAIL::ModifyQty()
{
Fstream File;
Fil.open("MATERIAL.DAT",ios::binary|ios::in|ios::out);
int Mpno;
cout<<"Materail no to modify Qty :"; cin>>Mpno;
while(Fil.read((char*)this,sizeof(MATERIAL)))
{
if(Mpno==Mno)
{
cout<<"Present Qty :" <<qty<,endl;
cout<"Changed Qty :"; cin>>qty;
int Position=_________________; //(Statement 1)
___________________________: //(Statement 2)
Fil.write((char * this,sizeof (MATERIAL)); // Re-writing the record
}
}
Fil.close();
}

Q8. 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 ( ); // Function to change marks
long R_CId( ) { return CId ; }
};
void MarksUpdate ( long 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 ++ ;
}i
f ( 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
candidate’s Id matches with the argument passed, and Statement 2 to write the updated Record at that
position.

Q9. Observe the program segment given below carefully and fill the blanks marked in statement 1 using seekg( ) or seekp( ) functions for performing the required task.
#include<fstream.h>
class FILE
{ int Num;
char Name[30];
public:
void GO_Record(int); }; //function to read Nth record from the file
void FILE::GO_Record(int N)
{
FILE Rec;
Fstream File;
File.open(“STOCK”,ios::binary|ios::in);
______________________________ //statement 1
File.read((char*)&Rec,sizeof(Rec));
cout<<Rec.Num<<Rec.Name<<endl;
File.close( );
}

Q10. Observe the program segment carefully and answer the question that follows:
class stock
{
int Ino, Qty; Char Item[20];
public:
void Enter() { cin>>Ino; gets(Item); cin>>Qty;}
void issue(int Q) { Qty+=0;}
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= = ss.GetIno())
{
s.Purchase(PQty);
_______________________ // statement 1
_______________________ // statement 2
Success++;
}
}
if (success = =1)
cout<< “Purchase Updated”<<endl;
else
cout<< “Wrong Item No”<<endl;
File.close() ;
}

TOPIC : File Handling

TYPE 2 QUESTION : Function write type questions

Q1. Assume a text file “coordinate.txt” is already created. Using this file create a C++ function to count the number of words having first character capital .Also count the presence of a word ‘Do’.

Example:

Do less Thinking and pay more attention to your heart. Do Less Acquiring and pay more Attention to what you already have. Do Less Complaining and pay more Attention to giving. Do Less criticizing and pay more Attention to Complementing. Do less talking and pay more attention to SILENCE.

Output will be :

Total words with capital vowel - 16

Count of ‘Do’ in file – 5

Q2. Write a function in C++ to print the count of the word as an independent word in a text file story.txt Eg: There was a tiger in the zoo. The tiger was very naughty.
The output of the program should be 2.

Q3. Write a function in C++ to count the number of uppercase alphabets present in a text file “ ARTICLE.TXT”.

Q4. Write a function to count and print the number of complete words as “to” and “are” stored in a text file “ESSAY.TXT”.
void CWORDS( )
{
ifstream fin(“ESSAY.TXT”);
char st[80];
int count=0;
while(!fin.eof())
{
      fin>>st;
      if(!fin)
      break;
      if(strcmpi(st,”to”) = =0 || strcmpi(st,”are”)= =0)
      count++;
}
cout<<”\nTotal ‘to’ & ‘are’ words = “<<count;
fin.close( );
}

Q5. Write a function in C++ to read the content of a text file “News.TXT” and display all those lines which are either starting with ‘S’ or starting with ‘W’.

Q6. Write a function in C++ to count the number of lines present in a text file “STORY.TXT”.

Q7. Write a function in C++ to count and display the no of three letter words in the file “VOWEL.TXT”.
Example:
If the file contains:
A boy is playing there. I love to eat pizza. A plane is in the sky.
Then the output should be: 4

Q8. 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 words]

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

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

 

Page 1

Topic: File Handling

seekg(), seekp(), tellg(), tellp() functions: 1 mark

  • get(), getline() and >> (input operator): 3 to 4 marks
  • read() and write() functions: 3 to 4 marks

Type 1 Questions: Text File Handling using get(), getline(), or the extraction operator (>>)

These problems generally require counting or displaying specific characters, words, or full lines from a pre-existing text file. The appropriate functions to utilize are:

  • Use the get() function to read data character-by-character.
  • Use the extraction operator (>>) to retrieve data word-by-word.
  • Use the getline() function to read data line-by-line.

 

Page 2

Question 1. Write a function in C++ to count the number of uppercase alphabets present in a text file "ARTICLE.TXT".
Answer:
Algorithmic Steps:

  • Initialize the file stream and open the target file: Create an ifstream object associated with the file "ARTICLE.TXT".
  • Declare variables: Set up a character variable to hold the read data and an integer counter initialized to zero to track uppercase letters.
  • Loop through the file: Initiate a while loop that continues as long as data remains in the file.
  • Read data character-by-character: Use the get() function to read each character, including whitespace.
  • Process characters: Test if the read character is an uppercase letter using isupper(), and if so, increment the counter.
  • Display the results: Print the final count to the console.
  • Clean up: Close the file stream using the close() method.


C++ Source Code:
void countupper()
{
    ifstream fin("ARTICLE.TXT");
    char ch;
    int ctr = 0;
    while (fin.get(ch))
    {
        if (isupper(ch))
        {
            ctr++;
        }
    }
    cout << "no. of upper case characters in file: " << ctr;
    fin.close();
}


In simple words: This function opens "ARTICLE.TXT", reads it one character at a time using fin.get(ch), checks if each character is a capital letter with isupper(), counts them, and displays the total before closing the file.

 

Exam Tip: Using fin.get(ch) is highly recommended over the extraction operator (>>) for character counting, as get() correctly processes spaces and newlines without skipping them.

 

Page 3

Question 2. Write a function to count and print the number of complete words as "to" and "are" stored in a text file "ESSAY.TXT".
Answer:
C++ Source Code:
void CWORDS()
{
    ifstream fin("ESSAY.TXT");
    char st[20];
    int count = 0;
    while (fin >> st)
    {
        if (strcmpi(st, "to") == 0 || strcmpi(st, "are") == 0)
        {
            count++;
        }
    }
    cout << "\nTotal 'to' & 'are' words = " << count;
    fin.close();
}


In simple words: This function reads words from "ESSAY.TXT" one by one using the >> operator. It compares each word to "to" and "are" using case-insensitive comparison (strcmpi), counts the matches, and prints the total.

Exam Tip: Always use strcmpi() (case-insensitive string comparison) instead of strcmp() to ensure words like "To", "TO", "Are", and "ARE" are also included in your final count.

 

Question 3. Write a function in C++ to display lines starting with alphabet 'A' or alphabet 'E' present in a text file "LINES.TXT".
Answer:
C++ Source Code:
void DISPLINES()
{
    ifstream fin("LINES.TXT");
    char str[100];
    while (fin.getline(str, 100))
    {
        if (str[0] == 'A' || str[0] == 'E' || str[0] == 'a' || str[0] == 'e')
        {
            cout << "\n" << str;
        }
    }
    fin.close();
}


In simple words: This function reads "LINES.TXT" line-by-line using getline(). It checks if the first character of each line (at index 0) is 'A', 'a', 'E', or 'e', and prints the line to the screen if it matches.

Exam Tip: When checking the starting character of a line, always include checks for both uppercase and lowercase versions of the specified letters to cover all cases.

 

Page 4

Type 2 Questions: Binary File Handling

These questions involve working with binary files that store data as structured variables or class objects. The binary input/output operations are executed using the read() and write() functions.

Prototype of read and write functions:

streamname.read((char *)&objname, sizeof(objname));
streamname.write((char *)&objname, sizeof(objname));

While the overall programmatic steps follow a similar logical path as text files, binary file handling differs because we read structured data using read() and write it using write(). A local class object acts as the buffer to hold data during these transfers, and we typically access member functions of that class to evaluate and process the data fields.

 

Page 5

Question 1. Given a binary file "BUS.DAT", containing records of the following class bus type:
class bus
{
    int bus_no;
    char desc[40];
    int distance; //in km
public:
    void read()
    {
        cin >> bus_no;
        gets(desc);
        cin >> distance;
    }
    void display()
    {
        cout << bus_no;
        puts(desc);
        cout << distance;
    }
    int retdist()
    {
        return distance;
    }
};


Write a function in C++ that would read the contents of file "BUS.DAT" and display the details of those buses which travels the distance more than 100 km.
Answer:
C++ Source Code:
void disprecord()
{
    ifstream fin("BUS.DAT", ios::binary);
    bus obj;
    while (fin.read((char *)&obj, sizeof(obj)))
    {
        if (obj.retdist() > 100)
        {
            obj.display();
        }
    }
    fin.close();
}


In simple words: This function opens "BUS.DAT" as a binary input file. It reads records directly into a bus object buffer. If a bus's distance (accessed via obj.retdist()) exceeds 100 km, its details are printed using obj.display().

Exam Tip: In binary file reading, checking the return value of fin.read() inside the loop condition (e.g., while (fin.read(...))) prevents processing the final record twice and ensures proper EOF handling.

 

Question 2. Given a binary file Sports.dat, containing records of the following structure type:
struct Sports
{
    char Event[20];
    char Participant[10][30];
};


Write a function in C++ that would read contents from the file Sports.dat and creates a file named Athletic.dat copying only those records from Sports.dat where the event name is "Athletics".
Answer:
C++ Source Code:
void copyrecord()
{
    ifstream fin("Sports.dat", ios::binary);
    ofstream fout("Athletics.dat", ios::binary);
    Sports game;
    while (fin.read((char *)&game, sizeof(game)))
    {
        if (strcmpi(game.Event, "Athletics") == 0)
        {
            fout.write((char *)&game, sizeof(game));
        }
    }
    fin.close();
    fout.close();
}


In simple words: This function reads data from "Sports.dat". For each read record, if the event name is exactly "Athletics" (verified using strcmpi), it copies that record into the new file "Athletics.dat" using fout.write().

Exam Tip: Ensure you use fout.write() (not read) to write records to the target binary stream, and open both files in ios::binary mode to preserve structural integrity.

 

Page 6

Type 3 Questions: File Pointers and Seek/Tell Functions

File pointers track the current read and write offsets. You can manipulate them using the following methods:

  • tellg() / tellp(): These functions return the current index (offset) of the input or output file pointer.
  • seekg() / seekp(): These functions change the position of the input or output file pointer to a target destination.
fstream
ifstream (Input)ofstream (Output)
seekg()
tellg()
seekp()
tellp()

Syntax Prototypes:

int pos = fin.tellg(); // stores the current read position
fin.seekg(pos, mode); // moves the pointer relative to a reference mode

Standard Seek Modes:

  • ios::beg: Positions the file pointer relative to the beginning of the file (this is the default offset).
  • ios::end: Positions the file pointer relative to the end of the file.
  • ios::cur: Positions the file pointer relative to the current cursor offset.

Example Configurations:

1. Setting the file pointer at the very start:

fin.seekg(0); // or fin.seekg(0, ios::beg);

2. Shifting the pointer 5 bytes backward from the end:

fin.seekg(-5, ios::end);

 

Page 7

3. Moving the file pointer 10 bytes ahead from its current location:

fin.seekg(10, ios::cur);

4. Setting the file pointer directly to the end of the file:

fin.seekg(0, ios::end);

Record Modification inside Binary Files:

Questions testing binary file updates often require replacing or editing a specific record in place. Let us analyze this process visually:

Record NameR1R2R3R4R5
Byte Offset Range0 - 45 - 89 - 1213 - 1617 - 20

Workflow to Modify a Record:

  1. Retrieve target data: Read the record to be updated (e.g., R4, situated at bytes 13 to 16) into a memory-allocated buffer object.
  2. Update values locally: Make the necessary modifications to the object's fields.
  3. Reposition the file pointer: Move the output stream pointer (using seekp) back to the starting byte of that specific record (byte 13 in this example).
  4. Overwrite: Execute a write() command to save the updated object back to the file stream.

 

Page 8

Coding Steps for Modification

Method 1: Explicit Position Storage

long pos = file.tellg();
file.read((char *)&obj, sizeof(obj));
obj.modify();
file.seekp(pos);
file.write((char *)&obj, sizeof(obj));

Method 2: Relative Offsets

file.read((char *)&obj, sizeof(obj));
obj.modify();
file.seekp(-1 * sizeof(obj), ios::cur);
file.write((char *)&obj, sizeof(obj));

Method 3: Combining tellg() and sizeof

file.read((char *)&obj, sizeof(obj));
obj.modify();
file.seekp(file.tellg() - sizeof(obj));
file.write((char *)&obj, sizeof(obj));

Exam Tip: When solving fill-in-the-blank questions on record modification, verify whether the code records the file position before or after reading the target record. Choose your seek command (Method 1, 2, or 3) accordingly to ensure the correct relative offset is calculated.

Practice Questions & Worksheets for Class 12 Informatics Practices File Handling

CBSE Informatics Practices Class 12 File Handling Worksheet

Enhance your test readiness by practicing the targeted questions provided for File Handling. Authored by experienced teachers in compliance with the recent 2026 CBSE guidelines for Class 12, these resources encourage active learning. We advise Class 12 students to complete these exercises regularly to reinforce core principles in Informatics Practices.

File Handling Solutions & NCERT Alignment

Built using specifications from the active NCERT book for Class 12 Informatics Practices, these worksheets mirror authentic academic structures. Comparing your completed work with our expert-verified solutions ensures you learn standard formatting for CBSE exams. Supplement your study routine with the provided MCQ questions for Informatics Practices to touch upon every essential learning objective.

Effective Revision Strategies for School Exams

Regular practice of this Class 12 Informatics Practices study material helps you to be familiar with the most regularly asked exam topics. If you find any topic in File Handling difficult then you can refer to our NCERT solutions for Class 12 Informatics Practices. All revision sheets and printable assignments on studiestoday.com are free and updated to help students get better scores in their school examinations.

FAQs

Where can I download the 2026-27 CBSE printable worksheets for Class 12 Informatics Practices File Handling?

You can download the latest chapter-wise printable worksheets for Class 12 Informatics Practices File Handling for free from StudiesToday.com. These have been made as per the latest CBSE curriculum for this academic year.

Are these File Handling Informatics Practices worksheets based on the new competency-based education (CBE) model?

Yes, Class 12 Informatics Practices worksheets for File Handling focus on activity-based learning and also competency-style questions. This helps students to apply theoretical knowledge to practical scenarios.

Do the Class 12 Informatics Practices File Handling worksheets have answers?

Yes, we have provided solved worksheets for Class 12 Informatics Practices File Handling to help students verify their answers instantly.

Can I print these File Handling Informatics Practices test sheets?

Yes, our Class 12 Informatics Practices test sheets are mobile-friendly PDFs and can be printed by teachers for classroom.

What is the benefit of solving chapter-wise worksheets for Informatics Practices Class 12 File Handling?

For File Handling, regular practice with our worksheets will improve question-handling speed and help students understand all technical terms and diagrams.