0% found this document useful (0 votes)
257 views

Jaypee University of Engineering and Technology, Guna

This document contains 14 questions related to file handling in C++. It covers topics like reading and writing to files, manipulating file pointers, merging and encrypting files. Some questions ask to write programs that read/write to files, display file contents, copy and merge files. Other questions are about file stream objects, opening and closing files, using seekg() to position the file pointer.

Uploaded by

Rahul Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
257 views

Jaypee University of Engineering and Technology, Guna

This document contains 14 questions related to file handling in C++. It covers topics like reading and writing to files, manipulating file pointers, merging and encrypting files. Some questions ask to write programs that read/write to files, display file contents, copy and merge files. Other questions are about file stream objects, opening and closing files, using seekg() to position the file pointer.

Uploaded by

Rahul Singh
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Jaypee University of Engineering and Technology, Guna

Department of Computer Science and Engineering


Object Oriented Programming (18B11CI211)
Tutorial – 9
(Console I/O and File handling)

1. Write C++ program for displaying ‘*’ for each input password character entered by the user.
Also validate the password by comparing entered password with existing password.
2. Write C++ program to create ‘tab’ manipulator equivalent to ‘\t’. Use this manipulator to
format the output.
3. What does the following statement do?
cout.write(s1,m).write(s2,n);
4. What is the difference between opening a file with a constructor function and opening a file
with open() function? When is one method preferred over the other? 
5. Write a statement that will create an object called fob for writing, and associate it with a file
name DATA. 
6. How many file objects would you need to create to manage the following situations?
(a) To process four files sequentially.
(b) To merge two sorted files into a third file. Explain.
7. Write a program that creates a text file “TEXT.txt”on the disk. Write text on this file. Read this
file and display the following information on the screen in two columns:
 Number of lines
 Number of words
 Number of characters
Strings should be left-justified and numbers should be right-justified in a suitable field width.
8. Two file named ‘Source1’ and ‘Source2’ contain sorted list of integers. Write a program that
reads the contents of both the files and stores the merged list in sorted form in a new file
named ‘Target’.
9. In a loop, prompt the user to enter name data consisting of a first name, middle initial, last
name, and employee number (type unsigned long). Then, using formatted I/O with the
insertion (<<) operator, write these four data items to an ofstream object. Don’t forget that
strings must be terminated with a space or other whitespace character. When the user indicates
that no more name data will be entered, close the ofstream object, open an ifstream object, read
and display all the data in the file, and terminate the program.

10. Write a program in C++ to read the file and store the lines into an array.

11. Write a program in C++ to copy a file in another name.

12. Write a program in C++ to merge two files and write it in a new file.

13. Write a program in C++ to encrypt a text file.

14. Write statements using seekg() to achieve the following: 


(a) To move the pointer by 15 positions backward from current position.
(b) To go to the beginning after an operation is over.
(c) To go backward by 20 bytes from the end.
(d) To go to byte number 50 in the file.

You might also like