Assume a file named words.txt exists. The file contains exactly 50 lines, and each line contains a single word. Some of the words appear only once in the file, but some of them appear two or more times. For this project, you will write a program that reads the contents of the file and counts the number of times each unique word appears in the file. The program should use a structure that has two members: ▪ A string to hold a word from the file ▪ An int to hold the number of times the word appears in the file The program should create an array of the structures and use the array to hold all the unique words from the file and the number of times each word appears. After the program has processed the contents of the file, it should step through the array and display each unique word from the file, followed by a space, followed by the number of times that word appears in the file. Note: Your program should disregard case when processing the words from the file. For example, the words "eagle" and "EAGLE" should be considered equal. The following sample run shows an example of the expected output of the program. In this sample run, the program found 10 unique words in the file. The word "option" appears 1 time, the word "eagle" appears 1 time, the word "popular" appears 4 times, and so on. Sample Run
Sample Run option 1 eagle 1 popular 4 observation 7 formulate 2 cheat 4 cattle 9 peace 6 underline 9 simplicity 7
Assume a file named words.txt exists. The file contains exactly 50 lines, and each line contains a single word. Some of
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Assume a file named words.txt exists. The file contains exactly 50 lines, and each line contains a single word. Some of
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!