File Handling in C++ - Questions
Questions
1.
2.
3.
4.
5.
6.
7.
stand by a file in the context of programming?
Provide two examples of different types of files.
How do we store files on a computer?
What is meant by the size of a file?
Create a text file called "BOOK.txt".
Insert some sample text into the file "BOOK.txt".
Write a C++ function to count the number of uppercase letters in
"BOOK.txt".
8. Write a C++ function to count the number of letters in "BOOK.txt".
9. Write a C++ function to count the number of digits in "BOOK.txt".
10. Write a C++ function to count the number of white spaces in "BOOK.txt".
11. Write a C++ function to count the number of vowels in "BOOK.txt".
Understanding Files and File Types
12. Explain the types of files in the context of file handling in C++.
13. Provide one example of each type of file (binary and text files).
14. Discuss the role of a file name in file handling.
15. Differentiate between text files and binary files.
Working with Streams and File Operations in C++
16. What are streams in C++ and how do they relate to file handling?
17. Explain the concept of file streams (ifstream, ofstream, fstream) and their
usage.
18. What are the common modes for opening files in C++ (e.g., ios::in, ios::out)?
19. How does the tellg() function work in C++? Provide an example
demonstrating its use.
20. What does the eof() function do in C++ file handling?
21. Write a C++ program to read text from a file and display it on the screen
character by character.
Binary File Handling
22. Explain the difference between text files and binary files with examples.
23. Write a C++ program that creates a binary file called "student.dat" using a
structure.
24. Write a program to read a binary file "student.dat" and display the records
on the screen.
25. Write a C++ program that writes and reads values from a binary file using
fstream.
26. What is the significance of seekg() and seekp() in file handling?
File Manipulation and Record Management
27. Write a C++ function to add new objects to the bottom of a binary file
"STUDENT.DAT".
28. Write a C++ function that copies records from one binary file
"PHONE.DAT" to another "PHONBACK.DAT", based on a specific
condition (e.g., area code).
29. Write a C++ program that reads a binary file and creates a new file
"ATHLETIC.DAT" containing only the records with the event name
"Athletics".
30. Explain how to delete a record from a file and update the file accordingly in
C++.
31. Demonstrate the use of random access in binary files. How can you directly
access a specific record in a file?
Practical Application and Advanced File Handling
32. Write a C++ function to search for records in a binary file "phones.dat"
where the number of calls is more than 800.
33. Explain how to use eof() to detect the end of a file and handle file read
errors effectively.
34. Write a C++ program to use << operator to write information to a file and
then demonstrate its use in real-world scenarios.
35. What is the process for updating a record in an existing file? How would you
implement this in C++?