MCQ with answers for (OOP) | Object Oriented Programming | 22316 [File Operations] MSBTE

Subject subject details
Program: Diploma in Computer engineering
Program Code CO
Scheme I
Semester 3
Course: Object Oriented Programming
Course Code 22316



 1. Which header file is required to use file I/O operations?

a)<ifstream>

b)<ostream>

c)<fstream>

d)<iostream> Answer: c

Explanation: <fstream> header file is needed to use file I/O operations in C++. This header file contains all the file I/O operations definition.


2. Which of the following is used to create an output stream?

a) ofstream

b) ifstream

c) iostream

d) fsstream Answer: a

Explanation: ofstream is used to create an output stream in C++ file handling operations. Ofstream objects are used to read files.


3. Which of the following is used to create a stream that performs both input and output operations?

a) ofstream

b) ifstream

c) iostream

d) fstream Answer: d

Explanation: fstream is used to create a stream that performs both input and output operations in C++ file handling.


4.. Which of the following is not used as a file opening mode?

a) ios::trunc

b) ios::binary

c) ios::in

d) ios::ate Answer: a

Explanation: ios::trunc is used to truncate a file if it exists. It is not a file opening mode.


5. By default, all the files in C++ are opened in mode.

a) Text

b) Binary

c) ISCII

d) VTC Answer: a

Explanation: By default, all the files in C++ are opened in text mode. They read the file as normal text.

 


6. Which of the following is the default mode of the opening using the ofstream class?

a) ios::in

b) ios::out

c) ios::app

d) ios::trunk Answer: b

Explanation: By default, the file is opened in ios::out mode if the file object we are using is of ofstream class.


7. What is the return type open() method?

a) int

b) char

c) bool

d) float Answer: c

Explanation: open() method returns a bool value indicating whether the file is opened or some error has occurred.


8. Which of the following is not used to seek file pointer?

a) ios::set

b) ios::end

c) ios::cur

d) ios::beg Answer: a

Explanation: ios::set is not used to seek file pointer. ios::end is used to seek from the end of the file. ios::curr from the current position. ios::beg from the beginning.


9. Which function is used in C++ to get the current position of file pointer in a file?

a) tell_p()

b) get_pos()

c) get_p()

d) tell_pos() Answer: a

Explanation: C++ provides tell_p() function to get the current position of the file pointer in a file.


10. Which stream class is to only write on files ?

A. ofstream

B. ifstream

C. fstream

D. iostream


Ans : A

Explanation: ofstream class is to only write on files.


11. It is not possible to combine two or more file opening mode in open () method.

A. TRUE

B. FALSE

C. May Be

D. Can't Say


Ans : B

Explanation: False, It is not possible to combine two or more file opening mode in open () method.

 



12. Which of these is the correct statement about eof() ?

A. Returns true if a file open for reading has reached the next character.

B. Returns true if a file open for reading has reached the next word.

C. Returns true if a file open for reading has reached the end.

D. Returns true if a file open for reading has reached the middle.Ans : C

Explanation: Returns true if a file open for reading has reached the end is the correct statement about eof().


13. Which function is used to reposition the file pointer?

a) moveg()

b) seekg()

c) changep()

d) go_p() Answer: b

Explanation: seekg() function is used to reposition a file pointer in a file. The function takes the offset and relative position from where we need to shift out pointer.


14. Which of the following true about FILE *fp

A. FILE is a structure and fp is a pointer to the structure of FILE type

B. FILE is a buffered stream

C. FILE is a keyword in C for representing files and fp is a variable of FILE type

D. FILE is a stream Answer : A

Explanation: fp is a pointer of FILE type and FILE is a structure that store following information about opened file




15. Which of the following methods can be used to open a file in file handling?

A. Using Open ( )

B. Constructor method

C. Destructor method

D. Both A and B Answer : D

Explanation: Both A and B methods can be used to open a file in file handling.


16. Which operator is used to insert the data into file?

A. >>

B. <<

C. <

D. None of the above Ans : B

Explanation: You can write information to a file from your program using the stream insertion operator <<.


17. Which is correct syntax ?

A. myfile:open ("example.bin", ios::out);

B. myfile.open ("example.bin", ios::out);

C. myfile::open ("example.bin", ios::out);

D. myfile.open ("example.bin", ios:out); Answer : B

Explanation: myfile.open ("example.bin", ios::out); is correct syntax.

 



18. What is the output of this program?


using namespace std;int main ()

{

char fine, course;

cout << "Enter a word: ";fine = cin.get(); cin.sync();

course = cin.get(); cout

<< fine << endl;

cout << course << endl; return 0;

}


A. course

B. fine

C. Returns fine 2 letter or number from the entered word

D. None of the mentioned View Answer


Answer : C

Explanation: In this program, We are using the sync function to return the fine two letters of the enteredword.


19. Which functions allow to change the location of the get and put positions ?a.sg() and sp() b.sekg() and sekp() c.gog()

and gop() d.seekg() and seekp()Answer: D


20. It is not possible to combine two or more file opening mode in open () method.

a) True

b) False

c) May be

d) None of these Answer: D

Explanation: False, It is not possible to combine two or more file opening mode in open () method.


x

download

Comments

Popular posts from this blog

Getting started with c programming (step-by-step) explanation

22413 software engineering notes [ ⚠️] pdf | Msbte 4th semester diploma

22620 Network and Information Security NIS solved lab manual pdf