Students can Download 2nd PUC Computer Science Chapter 12 Data File Handling Questions and Answers, Notes Pdf, 2nd PUC Computer Science Question Bank with Answers helps you to revise the complete Karnataka State Board Syllabus and to clear all their doubts, score well in final exams.
Karnataka 2nd PUC Computer Science Question Bank Chapter 12 Data File Handling
2nd PUC Computer Science Data File Handling One Mark Questions and Answers
Question 1.
Which header file is required for file handling function on in C++?
Answer:
Fslram.h
Question 2.
What is stream?
Answer:
Streams refers to a sequence of bytes.
Question 3.
Name the streams generally used for file I/O.
Answer:
Fstream.
Question 4.
What are output streams?
Answer:
The Stream that receives the data from the program is known as output streams.
Question 5.
What are input streams?
Answer:
The Stream that supplies the data to the program is known as input streams.
Question 6.
Mention the methods of opening file within C++ program.
Answer:
- Opening file using constructor.
- Opening the file using open () member function.
Question 7.
Write the member functions belonging to f stream class.
Answer:
Open () & close ()
Question 8.
What is if stream class?
Answer:
Stream class to read from files and provides input operation for file.
Question 9.
What is ofstrem class?
Answer:
Stream class to write on file & provides output operations for fils.
Question 10.
Write the member functions belonging to ofstream class.
Answer:
Put () & Write ().
Question 11.
Write the member functions belonging to if stream class.
Answer:
Get (), getline() & read ().
Question 12.
Name the steam classes supported by C++ for file input.
Answer:
Ifstream.
Question 13.
Name the stream classes supported by C++ for output.
Answer:
Ofstream.
Question 14.
Mention file Modes.
Answer:
in, out, app.
Question 15.
What is ios :: in?
Answer:
Open files for reading only.
Question 16.
What is ios :: out?
Answer:
Open files for writing only.
Question 17.
Mention the types of file.
Answer:
Binary file & text files.
Question 18.
What is text file?
Answer:
It is a file that stores information in ASCII characters.
Question 19.
What is binary file?
Answer:
It is a file that contains information in the same format as that held in memory.
Question 20.
What is the use of writeln () function?
Answer:
It is used to write binary data to a file.
Question 21.
What is the use of writen () function?
Answer:
To write whole line of text.
Question 22.
What is the use of get () function?
Answer:
The function get () reads a single character from the associated stream.
Question 23.
Vyhat is the use of put () function?
Answer:
To write a single character to the associated stream.
Question 24.
What is the use of getline () function?
Answer:
It is used to read a whole line of text.
Question 25.
What is the use of read () function?
Answer:
It is used to read binary data from a file.
Question 26.
What is the use of seekp () function?
Answer:
Moves the puts pointer to a specified location from the beginning of a file.
Question 27.
What is the use of seekg () function?
Answer:
Moves the get pointer to the a specified location from the beginning of a file.
Question 28.
What is the use of eof () function?
Answer:
Helps in detecting the end of the file.
Question 29.
What is error handling function?
Answer:
Function used report error message or diagnostics.
2nd PUC Computer Science Data File Handling Two Marks Questions and Answers
Question 1.
What is stream? Name the streams generally used for file I/O.
Answer:
Streams refers to a sequence of bytes, fstream
Question 2.
What are the input & output streams?
Answer:
The Stream that receives the data from the program is known are output stream. The skream supplies the data to the program is known as input streams.
Question 3.
Mention the methods of opening file within C++. Discuss any one.
Answer:
- Opening file using instructor.
- Opening a file by using open () function.
Question 4.
Write the member functions belonging to fstrean class.
Answer:
Put (), write (), get (), getline () & read ().
Question 5.
Differentiate belween if stream class & of stream class.
Answer:
Ifstream:
Stream class to read from files & provides input operations for file. It inherits the function get (), getline (), read () & functions supporting random access (seekg () & tellg ()) from istream class defined inside iostream.h file.
Ofstream:
Stream class to write on file and provides output operations for file. It inherit the function put (), write () & functions supporting random access (seekp() and tellp ()) from ostream class defined inside iostream.h file.
Question 6.
Differenciate between read ( ) & write ( ).
Answer:
The function read () is used to read binary data from a file & the function write () is used to write binary data to a file. It is used to write binary data to a file.
Question 7.
Differenciate between get ( ) & getline ( ).
Answer:
The function get ( ) reads a Single character from the associated stream & the function getline () is used to read a whole line of text.
Question 8.
Write the member functions belonging to of stream class.
Answer:
Put (). write (). seekp(), tellp().
Question 9.
Write the member functions belonging to if stream class.
Answer:
get (), Getline (), read (), seekg (), tellg ().
Question 10.
Name the stream classes supported by C++ for file input and output.
Answer:
fstream base, ifstream, ofstream, fstream and filebuf.
Question 11.
What are the advantages of saving data in binary form.
Answer:
Binary file contains information in same format as in memory. It does not require translation.
2nd PUC Computer Science Data File Handling Three Marks Questions and Answers
Question 1.
Mention the methods of opening file within C++ program. Discuss.
Answer:
The Syntax of opening a file for output purpose by using an object of ofstream class & the constructor is as follows.
ofstream ofstream – object (“filaname”);
ofstream-object is an object of type ofstream & “filename is any valid identifier of a file.
ofstream fout (“)
The syntax of opening a file for input purpose by using an object of ifstream class & the constructor is as follows.
ifstream ifstream-object (“filename”)
ifstream-object is an object of type ifstream & ” file name ” is any valid identifier name of a file to opened for input.
ex:
ifstream fin (“results, dat”);
ifstream fin (“text, dat”);
Question 2.
Differentiate between ifstream class and ofstream class.
Answer:
Ifstream:
Stream class to read from files & provides input operations for file. It inherits the function get (), getline (), read () & functions supporting random access (seekg () & tellg ()) from istream class defined inside iostream.h file.
Ofstream:
Stream class to write on file and provides output operations for file. It inherit the function put (), write () & functions supporting random access (seekp() and tellp ()) from ostream class defined inside iostream.h file.
Question 3.
Differentiate between read ( ) and write ( ).
Answer:
The function read () is used to read binary data from a file & the function write () is used to write binary data to a file. It is used to write binary data to a file.
Question 4.
Differentiate between get () and getline ().
Answer:
The function get ( ) reads a Single character from the associated stream & the function getline () is used to read a whole line of text.
Question 5.
Name the stream classes supported by C++ for file input and output.
Answer:
fstream base, ifstream, ofstream, fstream and filebuf.
Question 6.
Mention the types of file. Explain any one.
Answer:
Binary file & text files:
Text file is a file that stores information in ASCLL characters. In the text files. Each line of text is termnated with the special character known as EOL (End -of-Line) character & delimiter character, when this EOL character is read or written, certain internal translations take splace.
Question 7.
What are the advantages of saving data in. bbinary form and text form.
Answer:
The records in database usually contain different data types. In such areas saving data in binary form helps to optimize storage space and file I/O would be faster when compared to text files.
2nd PUC Computer Science Data File Handling Five Marks Questions and Answers
Question 1.
What are input and output streams.
Answer:
Input stream – if stream:
Input stream class to read from files. It provides input operations for file. It inherits the function get (), getline ( ), read ( ) and functions supporting random access (seek2() and tell 2() ) from isstream class defined inside iostreum.h file.
Outstream – of stream:
This stream class to write on files. It provides output operations for file. It inherits the function put (), write () and functions supporting random access (seekp () and tell p ()) from ostream class defined inside iostreum.h file.
Question 2.
What is significance of fstream.h header file?
Answer:
In C++, file input/ output facilities are implemented through a header file Of C++ slandard library. This header file is fstream.h. The fstream library predefines a set of operations for handing files related input and output. It defines certain classes that help to perform file input file input & output. For example: ifstream class ties a file to the program for input, ofstream class ties a file to the program for output & frtream classifies a file to the program for both iripui and output.
Question 3.
Mention the methods of opening file within C++ Discuss.
Answer:
The Syntax of opening a file for output purpose by using an object of ofstream class & the constructor is as follows.
ofstream ofstream – object (“filaname”);
ofstream-object is an object of type ofstream & “filename is any valid indentifier of a file.
ofstream fout (“)
The syntax of opening a file for input purpore by using an object of ifstream class & the constructor is as follows.
ifstream ifstream-object (“filename”)
ifstream-object is an object of type ifstream & ” file name ” is any valid identifier name of a file to opened for input.
ex:
ifstream fin (“results, dat”);
ifstream fin (“text, dat”);
Question 4.
Differentiate between ifstream class and ofstream class.
Answer:
Ifstream:
Stream class to read from files & provides input operations for file. It inherits the function get (), getline (), read () & functions supporting random access (seekg () & tellg ()) from istream class defined inside iostream.h file.
Ofstream:
Stream class to write on file and provides output operations for file. It inherit the function put (), write () & functions supporting random access (seekp() and tellp ()) from ostream class defined inside iostream.h file.
Question 5.
Differenciate between read ( ) and write ( ) with example.
Answer:
read( ):
The function rad () is used to read binary data form a file.
syntax: fout. write ((char*) & variable, size of (variable));
Fout is an object of type ofstream. The function requires two arquments. The first arqument is the address if the variable. The contents of which are writhen to the file and the second arequment is the size of the variable. The addressof the variable is type casted to pointer to char type. It is because the writhe functions does not bother to know the type of variable. It requires data in terms of only bytes.
ex: Student s:
ifstream fin (“Std.dat”,ios::binary);
fin, read ((char*) &S,Size of (S));
write( ):
The function write () is used to write binary data to a file. It is used to write binary data to a file.
Syntax: fin read ((char*) & variable, sizeof (variable));
fin is an oject of ifstream. The function regeeires two arguments. The first arguement is address of the variable, the contents of which are read from the file & the second argument is the Size of the variable.
ex: Student S:
ofstream fout (“std.dat”, ios:: binary);
fout. write ((char*) & s,size of (S));
Question 6.
Differenciate between get () & getline ( ) with example.
Answer:
The function get () reads a single character from the assocated stream.
ex: Char ch = ‘a’;
ifstream fin ((“text.tex”);
fin, get (ch)
The function getline ()>is used to read a whole line of text.
ex: Char book [SIZE];
fstream fin;
fin getline (book. SIZE);
Question 7.
Explain any three file modes.
Answer:
Question 8.
Differentiate between ios :: in and ios :: out.
Answer: