2023 Restrictions and Requirements No global variables may be used Your submission must contain at least 2 or more | Assignment Collections
Computer Science 2023 C++program
2023 Restrictions and Requirements No global variables may be used Your submission must contain at least 2 or more | Assignment Collections
Restrictions and Requirements
- No global variables may be used
- Your submission must contain at least 2 or more .cpp files and one or more .h files
- Your submission must have at least 3 user-defined functions in it in addition to main
Problem Description
Write a program that displays the top N most occurring words in a file along with the number of times the word appeared.
- Words should be displayed from most commonly occurring to least commonly occurring
- A word is considered to be 1 or more consecutive nonwhitespace characters
- Case does not matter when counting words
- HELLO and hello are to be considered the same word
- When displaying the most commonly occurring words they should all be displayed in lowercase
- When counting a word all leading and trailing non-alphabetical, non-numeric characters should be removed for a more accurate count
- For example
- hello
- hello,
- hello.
- hello;
- !!$#%hello<>?/ Are all considered to be the same word
- The complete list of special characters is: ,.:;”|!@#$%^&*()_+-=[]{}<>?/~`’
- For example
- If multiple words tie for most commonly occurring they should all be displayed
- These words should be displayed in alphabetical order
- You should ignore the following words when counting the most commonly occurring words because they are so frequent and aren’t interesting
- a, an, and, in, is, it the
- If there are fewer than N unique occurrences of a word all words should be displayed
- For example, if there were 5 unique words in a file but the user asked to display the top 10 words then only the top 5 will be displayed as there are only 5 words in the file
Input
All input will be valid
Command Line Arguments
- The path to the file
- Required
- N, the number of top words to find
- Optional
- If N is not given it should default to 10
Hints
- When opening the file to read from it make sure to use only an ifstream and not an fstream. This is because you only have read permissions on the files on Mimirand opening a file with an fstream requires both read and write permissions. Since you don’t have write permissions attempting to open a file with an fstream in testing will cause you to fail with weird behavior.
- The algorithm library contains many useful functions for helping to solve this problem
- You will find maps to be incredibly useful in solving this problem
- By default, a map will sort the values in ascending order. You can change this by providing a comparator function. Take a look back at the example we did in class for a refresher on how to do this.
Example
Assume that shake_it_off.txt contains the lyrics to Taylor Swift’s song “Shake it Off” which can be found here: shake_it_off.txt
./TopCommonWords shake_it_off.txt 5
1.) These words appeared 78 times: {shake}
2.) These words appeared 70 times: {i}
3.) These words appeared 44 times: {off}
4.) These words appeared 21 times: {gonna}
5.) These words appeared 15 times: {break, fake, hate, play}
We give our students 100% satisfaction with their assignments, which is one of the most important reasons students prefer us to other helpers. Our professional group and planners have more than ten years of rich experience. The only reason is that we have successfully helped more than 100000 students with their assignments on our inception days. Our expert group has more than 2200 professionals in different topics, and that is not all; we get more than 300 jobs every day more than 90% of the assignment get the conversion for payment.