Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Class name: FileLetterCounter Hints: Hint 1. To read a single character from the keyboard, you need to read a full line and then take the first character in position 0. Hint 2. To count the occurrences of a given characters in a file you need to read the file line-by-line using a while loop, then for each line check all characters in all positions and increment the character counter for each occurrence. This will require to have a for-loop nested inside the while-loop. Test Case 1 Please enter the file name or type QUIT to exit:\n QUITENTER Test Case 2 Please enter the file name or type QUIT to exit:\n badfilename.txtENTER File: badfilename.txt does not exist.\n Please enter the file name again or type QUIT to exit:\n quitENTER Test Case 3 Please enter the file name or type QUIT to exit:\n input.txtENTER Please enter a character: \n oENTER Letter 'o' occurs 4 times in the file 'input.txt'.\n Test Case 4 Please enter the file name or type QUIT to exit:\n letters.txtENTER Please enter a character: \n aENTER Letter 'a' occurs 82 times in the file 'letters.txt'.\n
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file. Class name: FileLetterCounter Hints: Hint 1. To read a single character from the keyboard, you need to read a full line and then take the first character in position 0. Hint 2. To count the occurrences of a given characters in a file you need to read the file line-by-line using a while loop, then for each line check all characters in all positions and increment the character counter for each occurrence. This will require to have a for-loop nested inside the while-loop. Test Case 1 Please enter the file name or type QUIT to exit:\n QUITENTER Test Case 2 Please enter the file name or type QUIT to exit:\n badfilename.txtENTER File: badfilename.txt does not exist.\n Please enter the file name again or type QUIT to exit:\n quitENTER Test Case 3 Please enter the file name or type QUIT to exit:\n input.txtENTER Please enter a character: \n oENTER Letter 'o' occurs 4 times in the file 'input.txt'.\n Test Case 4 Please enter the file name or type QUIT to exit:\n letters.txtENTER Please enter a character: \n aENTER Letter 'a' occurs 82 times in the file 'letters.txt'.\n
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
Chapter 4. PC #6. File Letter Counter (page 264)
Write a program that asks the user to enter the name of a file, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the file.
Class name: FileLetterCounter
Hints:
Hint 1. To read a single character from the keyboard, you need to read a full line and then take the first character in position 0.
Hint 2. To count the occurrences of a given characters in a file you need to read the file line-by-line using a while loop, then for each line check all characters in all positions and increment the character counter for each occurrence. This will require to have a for-loop nested inside the while-loop.
Test Case 1
Please enter the file name or type QUIT to exit:\n
QUITENTER
QUITENTER
Test Case 2
Please enter the file name or type QUIT to exit:\n
badfilename.txtENTER
File: badfilename.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
quitENTER
badfilename.txtENTER
File: badfilename.txt does not exist.\n
Please enter the file name again or type QUIT to exit:\n
quitENTER
Test Case 3
Please enter the file name or type QUIT to exit:\n
input.txtENTER
Please enter a character: \n
oENTER
Letter 'o' occurs 4 times in the file 'input.txt'.\n
input.txtENTER
Please enter a character: \n
oENTER
Letter 'o' occurs 4 times in the file 'input.txt'.\n
Test Case 4
Please enter the file name or type QUIT to exit:\n
letters.txtENTER
Please enter a character: \n
aENTER
Letter 'a' occurs 82 times in the file 'letters.txt'.\n
letters.txtENTER
Please enter a character: \n
aENTER
Letter 'a' occurs 82 times in the file 'letters.txt'.\n
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 4 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education