Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that allows the user to navigate through the lines of text in any text file. The program prompts the user for a

Write a program that allows the user to navigate through the lines of text in any text file. The program prompts the user for a filename and copies the lines of text from the file into a list. The program then prints the number of lines in the file and prompts the user for a line number. Actual line numbers range from 1 to the number of lines in the file. If the input is 0, the program quits. Otherwise, the program prints the text in that line number.

Input validation: You must print a friendly error message and allow the user to try again if the program cannot open the requested file, and whenever the user enters an invalid line number.

Here is a sample run (user input was changed to red for improved readability):

Enter the input file name: quotes.xtxt

I cannot open the file quotes.xtxt - Please check the name and try again.

Enter the input file name: quotes.txt The file has 16 lines. Enter a line number [0 to quit]: 1

1 : Hakuna Matata!

Enter a line number [0 to quit]: -1

Try again. Line number must be between 0 and 16

Enter a line number [0 to quit]: 16

16 : Just keep swimming!

Enter a line number [0 to quit]: 17

Try again. Line number must be between 0 and 16

Enter a line number [0 to quit]: 5

5 : It's kind of fun to do the impossible.

Enter a line number [0 to quit]: A

Try again. Please enter a number between 0 and 16

Enter a line number [0 to quit]: $

Try again. Please enter a number between 0 and 16

Enter a line number [0 to quit]: 4

4 : To infinity and beyond!

Enter a line number [0 to quit]: 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

4. Devise an interview strategy from the interviewers point of view

Answered: 1 week ago