CSCI 261 - Programming Concepts (C++)Summer 2018 - A6 - Sam I Am (Part I)Quick Links: Canvas | CS @ Mines | Piazza | zyBooks |
|||||||||||||||||||||||||
| Home | Contact | Syllabus | Assignments | Schedule | Resources | | |||||||||||||||||||||||||
This assignment is due by Friday, June 08, 2018, 11:59 PM. In this homework, we will focus on arrays, vectors, strings, structs, and File I/O.
OverviewHave you ever finished a book and
wondered, "Geez, I wonder how many times each word occurs in this
text?" No? This week's 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!
Program from what YOU KNOW
Did you know that most programs aren't well-designed? They really
aren't. Often, they're put together by geographically diverse people
with different styles, knowledge, programming ability and design taste.
But, the programs work. It's a freaky miracle, but they do
work.
When given a task in your engineering field that could be solved with
software, we do not expect you to be expert programmers (unless your
field is software engineering). However, we do expect you to
be able to assemble the things you know how to code into cohesive,
meaningful, useful programs.
You know how to open a file and read
data from it. You know how to declare and work with arrays. You know
that C++ can be your friend or your enemy. You know how to use a
framework to draw some simple graphics. You know how to conduct
repetitive tasks with loops. You know about data types.
Try to rely on these things that you know, before
over-complicating your own solution with things that you don't yet
know. This doesn't mean you shouldn't explore and learn more. You
should! Always! Until your last dying breath! But, start with what
you know first, and build from there.
ABCUF
Always Be Using Functions. Let that be a rule of thumb for the
remainder of the semester. When working on your programs, try to reach
an end result where
main
doesn't do much "low level stuff" but rather leverages functions in
order to do what your program needs to do.
For example, if you were to write a pizza-making program, don't write
one super-long, hard-to-read, scare-your-date-away implementation of
main
. Use functions:
int main() {
CreateShoppingList(); BuyIngredients(); GatherIngredientsInKitchen(); PourYourselfGlassOfFineChianti(); MakeDough(); MakaSauce(); //... CookPizza(); return 0; } The Specifics Part I: File I/OYou must first create a
struct
named WordCount to represent a word and the number of occurrences. It must have two
members, a count stored as an int and a word
stored as a string . Since this struct definition will be used in
multiple files, you probably would want to create this in its own header file and
then include this header in any other file that requires the use of the WordCount struct. (Hmm,
this seems similar to the Yahtzee set up).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 special
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 most frequent word is "
I " with a count of
83. The least frequent word is "IF " with a count of 1. 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.
Functional Requirements
Hints
Grading RubricYour submission will be graded according to the following rubric.
This assignment is due by Friday, June 08, 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
"Set6" folder
and only the "Set6" 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" 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 Friday, June 08, 2018, 11:59 PM. | |||||||||||||||||||||||||
Last Updated: 05/30/18 15:49
|