Jaypee University of Engineering and Technology, Guna
Jaypee University of Engineering and Technology, Guna
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.
12. Write a program in C++ to merge two files and write it in a new file.