CBSE Class 12 Computer Science Data File Handling Worksheet Set A

Read and download free pdf of CBSE Class 12 Computer Science Data File Handling Worksheet Set A. Students and teachers of Class 12 Computer Science can get free printable Worksheets for Class 12 Computer Science Data File Handling in PDF format prepared as per the latest syllabus and examination pattern in your schools. Class 12 students should practice questions and answers given here for Computer Science in Class 12 which will help them to improve your knowledge of all important chapters and its topics. Students should also download free pdf of Class 12 Computer Science Worksheets prepared by school teachers as per the latest NCERT, CBSE, KVS books and syllabus issued this academic year and solve important problems with solutions on daily basis to get more score in school exams and tests

Worksheet for Class 12 Computer Science Data File Handling

Class 12 Computer Science students should refer to the following printable worksheet in Pdf for Data File Handling in Class 12. This test paper with questions and answers for Class 12 will be very useful for exams and help you to score good marks

Class 12 Computer Science Worksheet for Data File Handling

Unit-I
Object Oriented Programming in C++

Data File Handling In C++

File: - The information / data stored under a specific name on a storage device, is called a file.

Stream: - It refers to a sequence of bytes.

Text file: - It is a file that stores information in ASCII characters. In text files, each line of text is terminated with a special character known as EOL (End of Line) character or delimiter character. When this EOL character is read or written, certain internal translations take place.

Binary file:- It is a file that contains information in the same format as it is held in memory. In binary files, no delimiters are used for a line and no translations occur here.

Classes used for different file related operation

ofstream:Object of ofstream class used to write data to the files.

ifstream: Object of ifstream class used to read data from files

fstream: Object of fstream class used to both read and write from/to files.

Opening a file

Opening file using constructor

ofstream outFile("sample.txt"); //output only

ifstream inFile(“sample.txt”); //input only

Opening File Using open ()

StreamObject.open(“filename”, [mode]);

ofstream outFile;

outFile.open("sample.txt");

ifstream inFile;

inFile.open("sample.txt");
CBSE Class 12 Computer Science Data File

All these flags can be combined using the bitwise operator OR (|). For example, if we want to open the file example.dat in binary mode to add data we could do it by the following call to member
function open():
fstream file;
file.open ("example.dat", ios::out | ios::in | ios::binary);
Closing File
outFile.close();
inFile.close();
Input and output operation
put() and get() function
the function put() writes a single character to the associated stream. Similarly, the function get()
reads a single character from the associated stream.
example :
file.get(ch);
file.put(ch);
write() and read() function
write() and read() functions write and read blocks of binary data.
example:
file.read((char *)&obj, sizeof(obj));
file.write((char *)&obj, sizeof(obj));
Determining End of File.
eof():-returns true (non zero) if end of file is encountered while reading; otherwise return false(zero)
File Pointers And Their Manipulation
All I/O stream objects have, at least, one internal stream pointer:
ifstream has a pointer known as the get pointer that points to the element to be read in the next input operation.ofstream has a pointer known as the put pointer that points to the location where the next element has to be written.fstream, inherits both, the get and the put pointers.
These internal stream pointers that point to the reading or writing locations within a stream can be manipulated using the following member functions:
CBSE Class 12 Computer Science Data File

The other prototype for these functions is:
seekg(offset, refposition );
seekp(offset, refposition );
The parameter offset represents the number of bytes(any negative or positive integer value for backward or forward movement) the file pointer is to be moved from the location specified by the parameter refposition. The refposition takes one of the following three constants defined in the ios class.
ios::beg   start of the file
ios::cur    current position of the pointer
ios::end   end of the fil
CBSE Class 12 Computer Science Data File

CBSE Class 12 Computer Science Data File

CBSE Class 12 Computer Science Data File

CBSE Class 12 Computer Science Data File

Short Answer Type Questions

1.Write a function in a C++ to count the number of lowercase alphabets present in a text file
“BOOK.txt”.
Answer. int countalpha()
{
ifstream Fin(“BOOK.txt”);
char ch;
int count=0;
while(!Fin.eof())
{ Fin.get(ch);
if (islower(ch))
count++;
}
Fin.close();
return count;
}

2. Write a function in C++ to count the number of line started with alphabet ‘a’ or ‘A’ in a text
file “LINES.TXT”.
Answer. void counter( )
{
char Aline[80];
int Count=0;
ifstream Fin (“LINES.TXT”);
while(!fin.eof())
{
Fin.getline(Aline,80, ‘\n’));
if (Aline[0]== ‘A’||Aline[0]==’a’)
Count++;
}
cout<<Count<<endl;
Fin.close( );
}

3. Write a function to count number of words whose word length is 8, in a file named “article.txt”.
Answer. void wordlen8( )
{
char word[20];
int count=0;
ifstream fin(“article.txt”);
while(!fin.eof())
{
fin>>word;

if(strlen(word)==8)
count++;
}
cout<<”Total number of words with word length 8 is=” << count; fin.close();
}

4. Given a binary file PHONE.DAT, containing records of the following structure type.
class phonlist
{ char Name[20] ;
char Address[30] ;
char AreaCode[5] ;
char PhoneNo[15] ;
public :
void Register( ) ;
void Show( ) ;
int CheckCode(char AC[ ])
{ return strcmp(AreaCode, AC) ;
}
} ;

Write a function TRANSFER( ) in C++, that would copy all those records which are having
AreaCode as “DEL” from PHONE.DAT to PHONBACK.DAT.
Answer. void transfer( )
{
ifstream Fin;
ofstream Fout;
Phonlist ph;
Fin.open(“PHONE.DAT”, ios::in | ios::binary);
Fout.open(“PHONBACK.DAT”, ios::out | ios:: binary);
while(Fin.read((char*)&ph, sizeof(ph)))
{
if(ph.check(“DEL”) == 0)
Fout.write((char*)&ph, sizeof(ph));
}
Fin.close();
Fout.close();
}

5.Given a binary file STUDENT.DAT, containing records of the following classStudent type
class Student
{
char S_Admno[l0]; //Admission number of student
char S_Name[30]; //Name of student
int Percentage; //Marks Percentage of student
public:
void EnterData()
{
gets(S_Admno);gets(S_Name);cin>>Percentage;
}
void DisplayData()

{
cout<<setw(12)<<S_Admno;
cout<<setw(32)<<S_Name;
cout<<setw(3)<<Percentage<<endl;
}
int ReturnPercentage(){return Percentage;}
};

Write a function in C++, that would read contents of file STUDENT.DAT and display the
details of those Students whose Percentage is above 75
Answer.
void Distinction()
{
Student S;
fstream Fin;
Fin.open(“STUDENT.DAT”, ios::binary|ios::in);
while(Fin.read((char*)&S, sizeof(Student))
if (S.ReturnPercentage()>75)
S.DisplayData( );
Fin.close();
}

6. Given a binary file STUINFO.DAT, containing records of the following structure type.
class STUDENT
{
int rollno;
char Name[20] ;
char Address[30] ;
char PhoneNo[15] ;
public :
void enter( )
{
cin>>rollno;
cin.getline(name,20);
cin.getline(address,30);
cin.getline(phoneno,15);
}
void display( )
{
cout<<”information of student is”;
cout<<rollno<<name<<address<<phoneno;
}
} ;
Write a function stu_write( ) in C++, that would write information of students in STUINFO.DAT


Very Short Questions

1. Observe the program segment given below carefully and fill the blanks marked as Line 1 and Line 2 using fstream functions for performing the required task. 
#include <fstream.h>
class Library
{
long Ano; //Ano – Accession Number of the Book
char Title[20]; //Title – Title of the Book
int Qty; //Qty – Number of Books in Library
public:
void Enter(int); //Function to enter the content
void Display(); //Function of display the content
void Buy(int Tqty)
{
Qty+=Tqty;
} //Function to increment in Qty
long GetAno() {return Ano;}
};
void BuyBook (long BANo, int BQty)
//BANo is Accessionno of the book purchased
//BQty is Number of books purchased
{
fstream File;
File. open (“STOCK.DAT”, ios: : binary|ios: : in|ios: : out);
int Position=–1;
Library L;
while (Position = = –1 && File. read ((char*) &L, sizeof (L)))
if (L. GetAno() = =BANo)
{
L. Buy (BQty); //To update the number of Books
Positions=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. File. seekp (position, ios :: beg); // Line–1
File. write ((char *) & L, sizeof (L)); // Line–2


MULTIPLE CHOICE QUESTIONS

Question. If a text file is opened in w+ mode, then what is the initial position of file pointer/cursor?
a. Beginning of file
b. End of the file
c. Beginning of the last line of text file
d. Undetermined
Answer. A

Question. Which of the following statements are true?
a. When you open a file for reading, if the file does not exist, an error occurs
b. When you open a file for writing, if the file does not exist, a new file is created
c. When you open a file for writing, if the file exists, the existing file is overwritten with the new file
d. All of the mentioned
Answer. D

Question. To read the entire remaining contents of the file as a string from a file object myfile, we use
a. myfile.read(2)
b. myfile.read()
c. myfile.readline()
d. myfile.readlines()
Answer. B

Question. A text file is opened using the statement f = open(‘story.txt’). The file has a total of 10 lines. Which of the following options will be true if statement 1 and statement 2 are executed in order. Statement 1: L1 = f.readline( ) Statement 2: L2 = f.readlines( )
a. L1 will be a list with one element and L2 will be list with 9 elements.
b. L1 will be a string and L2 will be a list with 10 elements.
c. L1 will be a string and L2 will be a list with 9 elements.
d. L1 will be a list with 10 elements and L2 will be an empty list.
Answer. C

Question. Which function of a file object can be used to fetch the current cursor position in terms of number of bytes from beginning of file?
a. seek( )
b. bytes( )
c. tell( )
d. fetch( )
Answer. C

Question.What will be the output of the following code?
f = open(‘test.txt’, ‘w+’)
L = [‘First Line\n’, ‘Second Line\n’, ‘Third Line’]
f.writelines(L)
f.flush() f.seek(0)
O = f.readlines()
print(len(O))
a. 33
b. 31
c. 28
d. 3
Answer. D

Question. The contents of a text file named ‘quote.txt’ is as shown below:
All the kings horses and all the kings men
cannot fix what isn’t broken.
What will be the output of the following code?
fin = open('fracture.txt’) data = fin.read(10) print(data[0:3], end= ‘’)
data = fin.readline(5)
print(data[0:3] , end= ‘’) fin.seek(0)
data = fin.read(4)
print(data[0:3] , end= ‘’)
a. AllngsAll
b. AllcanAll
c. Allcancan
d. Allngscan
Answer. A

Question. What will be the most correct option for possible output of the following code, given that the code executes without any error.
f = open(‘cricket.txt’)
data = f.read(150)
print(len(data))
a. It will always be 150
b. 151
c. More than or equal to 150
d. Less than or equal to 150
Answer. D

Question. For the following python code, what will be the datatype of variables x, y, z given that the code runs without any error?
f = open(‘story.txt’)
x = f.read(1)
y = f.readline()
z = f.readlines()
a. string, list, list
b. None, list, list
c. string, string, list
d. string, string, string
Answer. C

Question. The contents of a text file named ‘fracture.txt’ is as shown below:
Do you dare stay out, Do you dare go in
How much can you lose, How much can you win
And if you go in, should you turn left or right
You will get so confused that you will start in to race
What will be the output of the following code?
fin = open('fracture.txt’)
x = 0 for line in fin:
words = line.split( )
for w in words:
if len(w)>x:
x = len(w)
print(x)
a. 12
b. 11
c. 13
d. 10
Answer. A


VERY SHORT ANSWER TYPE QUESTIONS

Question. Differentiate between file modes r+ and w+ with respect to python?
Answer: r+ opens a text file for reading and writing. w+ opens a text file for reading and writing. It overwrites the file if it exists, create a file if it doesn’t.

Question. Write a statement in Python to open a text file “ABC.TXT” in reading mode.
Answer: F=open("ABC.TXT","r")

Question. In ___________ files each line terminates with EOL or ‘\n’ or carriage return, or ‘\r\n’.
Answer: Text File

Question. Observe the following code and answer the questions that follow.
File=open(“MyData”,”a”)
_____________ #Blank1
File.close()
a) What type (text/binary) of file is MyData ?
b) Fill the Blank1 with statement to write “ABC” in the file “Mydata”
Answer: a) Text File
b) File.write(“ABC”)

Question. What are files?
Answer: A named entity, usually stored on a hard drive that contains a stream of characters are called files.


SHORT ANSWER TYPE QUESTIONS

Question. Explain seek() method in python.
In Python, seek() function is used to change the position of the File Handle to a given specific position.
Syntax: fi.seek(offset, from_where), where fi is the file pointer
Offset: This is used for defining the number of positions to move forward.
from_where: This is used for defining the point of reference. It can take
0: beginning of the file. 1: current position of the file. 2: end of the file.

More Worksheets for Class 12 Computer Science
CBSE Class 12 Computer Science Arrays Stacks Queues And Linked List Worksheet Set A
CBSE Class 12 Computer Science Arrays Stacks Queues And Linked List Worksheet Set B
CBSE Class 12 Computer Science Arrays Worksheet
CBSE Class 12 Computer Science Boolean Algebra Worksheet Set A
CBSE Class 12 Computer Science Boolean Algebra Worksheet Set B
CBSE Class 12 Computer Science C++ Programming Worksheet
CBSE Class 12 Computer Science Class And Objects Worksheet Set A
CBSE Class 12 Computer Science Class And Objects Worksheet Set B
CBSE Class 12 Computer Science Class And Objects Worksheet Set C
CBSE Class 12 Computer Science Class And Objects Worksheet Set D
CBSE Class 12 Computer Science Classes Objects Constructors And Destructors Worksheet
CBSE Class 12 Computer Science Communication And Network Concepts Worksheet
CBSE Class 12 Computer Science Computer Networking Worksheet
CBSE Class 12 Computer Science Constructors And Destructors Worksheet
CBSE Class 12 Computer Science Data File Handling Worksheet Set A
CBSE Class 12 Computer Science Data File Handling Worksheet Set B
CBSE Class 12 Computer Science Data File Handling Worksheet Set C
CBSE Class 12 Computer Science Database Concepts And Sql Worksheet
CBSE Class 12 Computer Science Dbms And Structured Query Language Worksheet
CBSE Class 12 Computer Science Flow Of Control Worksheet
CBSE Class 12 Computer Science Function Overloading Worksheet
CBSE Class 12 Computer Science Function And Structures Worksheet
CBSE Class 12 Computer Science Inheritance Extending Classes Worksheet Set A
CBSE Class 12 Computer Science Inheritance Extending Classes Worksheet Set B
CBSE Class 12 Computer Science Linked Lists Stacks And Queues Worksheet
CBSE Class 12 Computer Science Network And Communication Technology Worksheet
CBSE Class 12 Computer Science Object Oriented Programming In C++ Worksheet
CBSE Class 12 Computer Science Object Oriented Programming Worksheet
CBSE Class 12 Computer Science Oop Classes And Objects Worksheet
CBSE Class 12 Computer Science Pointer Worksheet Set A
CBSE Class 12 Computer Science Pointer Worksheet Set B
CBSE Class 12 Computer Science Program List Worksheet
CBSE Class 12 Computer Science Programming In C++ Worksheet
CBSE Class 12 Computer Science Revision Worksheet Set A
CBSE Class 12 Computer Science Revision Worksheet Set B
CBSE Class 12 Computer Science Revision Worksheet Set C
CBSE Class 12 Computer Science Revision Worksheet Set D
CBSE Class 12 Computer Science Revision Worksheet Set E
CBSE Class 12 Computer Science Revision Worksheet Set F
CBSE Class 12 Computer Science Revision Worksheet Set G
CBSE Class 12 Computer Science Revision Worksheet Set H
CBSE Class 12 Computer Science Revision Worksheet Set I
CBSE Class 12 Computer Science Revision Worksheet Set J
CBSE Class 12 Computer Science Revision Worksheet Set K
CBSE Class 12 Computer Science Revision Worksheet Set L
CBSE Class 12 Computer Science Revision Worksheet Set M
CBSE Class 12 Computer Science Revision Worksheet Set N
CBSE Class 12 Computer Science Revision Worksheet Set O
CBSE Class 12 Computer Science Revision Worksheet Set P
CBSE Class 12 Computer Science SQL Worksheet Set A
CBSE Class 12 Computer Science SQL Worksheet Set B
CBSE Class 12 Computer Science SQL Worksheet Set C
CBSE Class 12 Computer Science SQL Worksheet Set D
CBSE Class 12 Computer Science Stacks Queues And Linked List Worksheet
CBSE Class 12 Computer Science Sure Shot Questions Worksheet Set A
CBSE Class 12 Computer Science Sure Shot Questions Worksheet Set B
CBSE Class 12 Computer Science Sure Shot Questions Worksheet Set C
CBSE Class 12 Computer Science Sure Shot Questions Worksheet Set D
CBSE Class 12 Computer Science Text Files Worksheet
CBSE Class 12 Computers Boolean Algebra Worksheet
CBSE Class 12 Computers Classes And Objects Worksheet
CBSE Class 12 Computers Constructors And Destructors Worksheet
CBSE Class 12 Computers Data Structures Worksheet
CBSE Class 12 Computers Files Worksheet
CBSE Class 12 Computers Inheritance Worksheet Set A
CBSE Class 12 Computers Inheritance Worksheet Set B
CBSE Class 12 Computers Networking Worksheet
CBSE Class 12 Computers Object Oriented Programming Worksheet
CBSE Class 12 Computers Pointers Worksheet

More Study Material

CBSE Class 12 Computer Science Data File Handling Worksheet

We hope students liked the above worksheet for Data File Handling designed as per the latest syllabus for Class 12 Computer Science released by CBSE. Students of Class 12 should download in Pdf format and practice the questions and solutions given in the above worksheet for Class 12 Computer Science on a daily basis. All the latest worksheets with answers have been developed for Computer Science by referring to the most important and regularly asked topics that the students should learn and practice to get better scores in their class tests and examinations. Studiestoday is the best portal for Class 12 students to get all the latest study material free of cost.

Worksheet for Computer Science CBSE Class 12 Data File Handling

Expert teachers of studiestoday have referred to the NCERT book for Class 12 Computer Science to develop the Computer Science Class 12 worksheet. If you download the practice worksheet for one chapter daily, you will get higher and better marks in Class 12 exams this year as you will have stronger concepts. Daily questions practice of Computer Science worksheet and its study material will help students to have a stronger understanding of all concepts and also make them experts on all scoring topics. You can easily download and save all revision worksheet for Class 12 Computer Science also from www.studiestoday.com without paying anything in Pdf format. After solving the questions given in the worksheet which have been developed as per the latest course books also refer to the NCERT solutions for Class 12 Computer Science designed by our teachers

Data File Handling worksheet Computer Science CBSE Class 12

All worksheets given above for Class 12 Computer Science have been made as per the latest syllabus and books issued for the current academic year. The students of Class 12 can be rest assured that the answers have been also provided by our teachers for all worksheet of Computer Science so that you are able to solve the questions and then compare your answers with the solutions provided by us. We have also provided a lot of MCQ questions for Class 12 Computer Science in the worksheet so that you can solve questions relating to all topics given in each chapter. All study material for Class 12 Computer Science students have been given on studiestoday.

Data File Handling CBSE Class 12 Computer Science Worksheet

Regular worksheet practice helps to gain more practice in solving questions to obtain a more comprehensive understanding of Data File Handling concepts. Worksheets play an important role in developing an understanding of Data File Handling in CBSE Class 12. Students can download and save or print all the worksheets, printable assignments, and practice sheets of the above chapter in Class 12 Computer Science in Pdf format from studiestoday. You can print or read them online on your computer or mobile or any other device. After solving these you should also refer to Class 12 Computer Science MCQ Test for the same chapter.

Worksheet for CBSE Computer Science Class 12 Data File Handling

CBSE Class 12 Computer Science best textbooks have been used for writing the problems given in the above worksheet. If you have tests coming up then you should revise all concepts relating to Data File Handling and then take out a print of the above worksheet and attempt all problems. We have also provided a lot of other Worksheets for Class 12 Computer Science which you can use to further make yourself better in Computer Science

Where can I download latest CBSE Printable worksheets for Class 12 Computer Science Data File Handling

You can download the CBSE Printable worksheets for Class 12 Computer Science Data File Handling for latest session from StudiesToday.com

Can I download the Printable worksheets of Data File Handling Class 12 Computer Science in Pdf

Yes, you can click on the links above and download Printable worksheets in PDFs for Data File Handling Class 12 for Computer Science

Are the Class 12 Computer Science Data File Handling Printable worksheets available for the latest session

Yes, the Printable worksheets issued for Class 12 Computer Science Data File Handling have been made available here for latest academic session

How can I download the Class 12 Computer Science Data File Handling Printable worksheets

You can easily access the links above and download the Class 12 Printable worksheets Computer Science Data File Handling for each chapter

Is there any charge for the Printable worksheets for Class 12 Computer Science Data File Handling

There is no charge for the Printable worksheets for Class 12 CBSE Computer Science Data File Handling you can download everything free

How can I improve my scores by solving questions given in Printable worksheets in Class 12 Computer Science Data File Handling

Regular revision of practice worksheets given on studiestoday for Class 12 subject Computer Science Data File Handling can help you to score better marks in exams

Are there any websites that offer free test sheets for Class 12 Computer Science Data File Handling

Yes, studiestoday.com provides all latest NCERT Data File Handling Class 12 Computer Science test sheets with answers based on the latest books for the current academic session

Can test papers for Class 12 Computer Science Data File Handling be accessed on mobile devices

Yes, studiestoday provides worksheets in Pdf for Data File Handling Class 12 Computer Science in mobile-friendly format and can be accessed on smartphones and tablets.

Are worksheets for Data File Handling Class 12 Computer Science available in multiple languages

Yes, worksheets for Data File Handling Class 12 Computer Science are available in multiple languages, including English, Hindi