CSCI 261 - Programming ConceptsFall 2018 - A7 - Sam I AmQuick Links: Canvas | Mines | Piazza | zyBooks |
|||||||||||||||||||||
| Home | Contact | Syllabus | Assignments | Schedule | Resources | | |||||||||||||||||||||
This assignment is due by Thursday, November 15, 2018, 11:59 PM. · Instructions · Rubric · Submission · In this homework, we will focus on arrays, vectors, strings, structs, File I/O, and SFML.
OverviewHave you ever finished a book and
wondered, "Geez, I wonder how many times each word occurs in this
text?" No? This assignment illustrates a fundamental use of the
array & vector: storing related values in a single data structure, and then
using that data structure to reveal interesting facts about the data.
For this assignment, you will read in a text file
containing the story Green Eggs and Ham. You will then need to count the number of
occurrences of each word and display the frequencies. You'll be amazed at the results!
The Specifics Part I: File I/OWe'll want to use the same
WordCount struct from the prior assignment.Next, you need to open the following file using an input file stream:
greeneggsandham.txt. Read this
file one word at a time. Every time you read a word in, before you do anything you must remove the punctuation
characters from the word (if present):
. ? ! , ( ) - ; ' " _ : We'll want to have created a vector of WordCount to store all of our words and their counts.
Once you have stripped out each of the above characters, if this is the first time you are seeing a word then you need
to insert it into your vector. Otherwise, if you have seen this word before then you will need to increment the count.
(Hint: you'll need to use a searching algorithm on your vector)
After you have read all of the words in the file, you will then need to sort the vector
alphabetically by words. (Hint: you'll need to use a sorting algorithm on your vector). Print out all the words and their
counts using the following format (substituting the actual words and counts):
# 1 AWORD : 3
# 2 WORDS2 : 14 ... #21 WORDS21 : 1 Most Frequent: WORDS2 (14) Least Frequent: WORDS21 ( 1) Note how the data is aligned and words are alphabetical. Finally, print out the least frequent word with its
count along with the most frequenct word and its count. To verify your output, the word "
A " appers 56 times.
The word "EAT " appears 23 times. Additionally, there are
50 unique words. (Hint: you'll need to use the minMax
algorithm)
We used a vector to store the words and in that context it was an appropriate choice. We are next interested in the frequency of all the letters
that appear in the book.
For this use case, an array is more appropriate (think about why). We want to be sure we are treating uppercase and lowercase letters the same
in our counting. Once the counts for each letter have been stored in an array (what is the appropriate type and size of the array?),
print out the letter and frequency in the following format (using 3 decimal places). Also, print the most and least frequent letter with their
counts. In the event that two letters have the same frequency, report the letter that comes first alphabetically. To verify your program is running
properly, E occurs 277 times (11.58%) and J occurs 0 times (0.0%).
A: 30.123% B: 0.532% C: 10.001% ... Z: 5.330% Most Frequent: Q (1000) Least Frequent: E (0)
You will want to make your program as general as possible and not having any assumptions about the data hardcoded in. We will run
your program against the greeneggsandham.txt input file. We will also run your
program against a second secret input file to ensure your program is flexible and will work on any input file.
The Specifics Part II: SFMLNow that we have processed all of the data, it's time
to display it visually. Ready for the GUI part of your homework? Fasten your seat belt and
enjoy the ride! In this part you will draw a window that shows a bar
for each letter in the book, with its height proportional to the
corresponding frequency. The bar that corresponds
to the most frequent letter should be colored with a different color. The bar that corresponds
to the least frequent letters should be colored with yet a third color.
Step I - Drawing the Bars
To draw the bars of the GUI you will use the RectangleShape class and create an
object called bar. For each letter you should draw a bar with a
height proportional to the letter frequency. All bars should have the
same width, can you guess what it is?
To set the bar's size you should use the object's setSize
function. In a similar way, to set the bar's position you should use
the object's setPosition function. The following example shows
how to change the size of the bar object using the values width=20
and height=100 AND the position of the bar object using the
values x=80 and y=250. Note that because you will be
drawing a bar for each word using a loop, you should use variables
like width, height, x, and y to set the bar's properties accordingly.
bar.setSize(Vector2f((float)20, (float)100));
bar.setPosition(Vector2f((float)80, (float)250));
To set the bar's color you should use the setFillColor function.
Remember to set a different color to the bar that corresponds to the
most and least frequent letters. After setting the bar's size, position, and
color, you should draw the object on your window using the window's draw
function, illustrated in the code that follows.
bar.setFillColor(Color::White);
window.draw(bar);
Use a loop to traverse your frequencies array. At
each iteration, draw a bar for the correspondent
letter. Let's say that you are using a variable named height to
compute the height of the 'to be drawn' bar. You can then use the
height of your window (i.e., a HEIGHT constant) divided by the
frequency of the most frequent letter as a scaling factor to compute
the height of each bar. After the bar's height is computed, determining
its y coordinate is a piece of cake: just subtract the
bar's height from the window HEIGHT.
Lastly, we want to display text at the base of each bar that corresponds to the letter for that bar.
When you've drawn all the bars for all your letters, you should have a result similar to below (colors & size may vary, but
results should be proportionally the same):
![]() Functional Requirements
Hints
Grading RubricYour submission will be graded according to the following rubric.
This assignment is due by Thursday, November 15, 2018, 11:59 PM. SubmissionAlways, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available. The following instructions are copied from How to Submit Homework. It is critical that you follow these steps when submitting homework.
If you do not follow these instructions, your assignment
will receive a major deduction. Why all the fuss? Because we have
several hundred of these assignments to grade, and we use
computer tools to automate as much of the process as possible.
If you deviate from these instructions, our grading tools will
not work. And that makes us very unhappy. And when we're
unhappy, we give penalties. Thus, make us happy.
Submission Instructions Here are step-by-step instructions for submitting your homework properly:
In summary, you must zip the
"Set7" folder
and only the "Set7" folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this
homework, and you must click the "Submit Assignment" button. Not doing these steps is like bringing your
homework to class but forgetting to hand it in. No concessions will be made for
incorrectly submitted work. If you incorrectly submit your homework, we will not be able to
give you full credit. And that makes us unhappy. This assignment is due by Thursday, November 15, 2018, 11:59 PM. | |||||||||||||||||||||
Last Updated: 10/26/18 17:09
|