Question
I/O Stream C++ practice: Write a program that reads a file and asks the user for the number of lines they want to see. the
I/O Stream C++ practice:
Write a program that reads a file and asks the user for the number of lines they want to see. the program will print the specified number of lines, and then continue to ask the user how many lines of content they want to see , until the user enters 0 or the entire file has been read You need to repeat to ask user how many lines of content they want to see until the user enters 0 or the entire file has been read If the number of lines entered by the user exceeds the total number of lines. In the file, you should print up to the last line of the file and terminate the program.
Example:
input1.txt:
This is line 1. This is line 2. This is line 3. This is line 4. This is line 5. This is line 6. This is line 7. This is line 8. This is line 9. This is line 10. This is line 11. This is line 12. This is line 13. This is line 14. This is line 15.
Example of the program:
How many lines do you want to see: 7
This is line 1. This is line 2. This is line 3. This is line 4. This is line 5. This is line 6. This is line 7.
How many lines do you want to see: 0
------------------------------------------------
Process terminated after 4.031 seconds with return value 0
example 2:
How many lines do you want to see: 5
This is line 1. This is line 2. This is line 3. This is line 4. This is line 5.
How many lines do you want to see: 10
This is line 6. This is line 7. This is line 8. This is line 9. This is line 10. This is line 11. This is line 12. This is line 13. This is line 14. This is line 15.
------------------------------------------------
Process terminated after 1.53 seconds with return value 0
example 3:
How many lines do you want to see: 5
This is line 1. This is line 2. This is line 3. This is line 4. This is line 5.
How many lines do you want to see: 7
This is line 6. This is line 7. This is line 8. This is line 9. This is line 10. This is line 11. This is line 12.
How many lines do you want to see: 8
This is line 13. This is line 14. This is line 15.
------------------------------------------------
Process terminated after 11.17 seconds with return value 0
end of example.
reminder: code in C++ only. The input is from input1.txt file.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
include iostream include fstream include string int main stdifstream fileinput1tx...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started