Finish all but printing
This commit is contained in:
commit
b2e3fbc645
17 changed files with 5047 additions and 0 deletions
43
.clang-format
Normal file
43
.clang-format
Normal file
|
@ -0,0 +1,43 @@
|
|||
# Tyler's personal code-style formatting file, make sure to use the class version before turning in
|
||||
IndentWidth: 4
|
||||
UseTab: Always
|
||||
TabWidth: 4
|
||||
InsertBraces: false
|
||||
SortIncludes: true
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
# System headers from C (hardcoded, it isn't really possible to automatically detect them with regex)
|
||||
- Regex: '<c(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)>'
|
||||
Priority: 3
|
||||
# System headers without extension.
|
||||
- Regex: '<([A-Za-z0-9\Q/-_\E])+>'
|
||||
Priority: 2
|
||||
# Local headers with extension.
|
||||
- Regex: '"([A-Za-z0-9\Q/-_\E])+\.h(pp)?"'
|
||||
Priority: 1
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
IndentCaseLabels: true
|
||||
IntegerLiteralSeparator:
|
||||
Binary: 0
|
||||
Decimal: 3
|
||||
Hex: -1
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Right
|
||||
QualifierAlignment: Left
|
43
.class-clang-format
Normal file
43
.class-clang-format
Normal file
|
@ -0,0 +1,43 @@
|
|||
# A clang-format config to follow CSCI200's style guide, use before turning in
|
||||
IndentWidth: 2
|
||||
UseTab: Never
|
||||
TabWidth: 2
|
||||
InsertBraces: true
|
||||
SortIncludes: true
|
||||
IncludeBlocks: Regroup
|
||||
IncludeCategories:
|
||||
# System headers from C
|
||||
- Regex: '<c(assert|complex|ctype|errno|fenv|float|inttypes|iso646|limits|locale|math|setjmp|signal|stdalign|stdarg|stdatomic|stdbool|stddef|stdint|stdio|stdlib|stdnoreturn|string|tgmath|threads|time|uchar|wchar|wctype)>'
|
||||
Priority: 3
|
||||
# System headers without extension.
|
||||
- Regex: '<([A-Za-z0-9\Q/-_\E])+>'
|
||||
Priority: 2
|
||||
# Local headers with extension.
|
||||
- Regex: '"([A-Za-z0-9\Q/-_\E])+\.h(pp)?"'
|
||||
Priority: 1
|
||||
BraceWrapping:
|
||||
AfterCaseLabel: false
|
||||
AfterClass: false
|
||||
AfterControlStatement: Never
|
||||
AfterEnum: false
|
||||
AfterFunction: false
|
||||
AfterNamespace: false
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
BeforeLambdaBody: false
|
||||
BeforeWhile: false
|
||||
SplitEmptyFunction: false
|
||||
SplitEmptyRecord: false
|
||||
SplitEmptyNamespace: false
|
||||
IndentCaseLabels: true
|
||||
IntegerLiteralSeparator:
|
||||
Binary: -1
|
||||
Decimal: -1
|
||||
Hex: -1
|
||||
DerivePointerAlignment: false
|
||||
PointerAlignment: Left
|
||||
QualifierAlignment: Left
|
14
.gitignore
vendored
Normal file
14
.gitignore
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Ignore extensionless files
|
||||
*
|
||||
!*.*
|
||||
!*/
|
||||
|
||||
# Allow makefile
|
||||
!Makefile
|
||||
|
||||
# Packed files
|
||||
*.tar.gz
|
||||
|
||||
# Compiled files
|
||||
*.o
|
||||
*.out
|
13
.vscode/launch.json
vendored
Normal file
13
.vscode/launch.json
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "Launch",
|
||||
"type": "lldb",
|
||||
"request": "launch",
|
||||
"program": "${workspaceFolder}/${workspaceFolderBasename}",
|
||||
"args": [],
|
||||
"preLaunchTask": "make"
|
||||
}
|
||||
]
|
||||
}
|
5
.vscode/settings.json
vendored
Normal file
5
.vscode/settings.json
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"clang-tidy.compilerArgsBefore": [
|
||||
"-xc++"
|
||||
]
|
||||
}
|
12
.vscode/tasks.json
vendored
Normal file
12
.vscode/tasks.json
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
// See https://go.microsoft.com/fwlink/?LinkId=733558
|
||||
// for the documentation about the tasks.json format
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "make",
|
||||
"type": "shell",
|
||||
"command": "make"
|
||||
}
|
||||
]
|
||||
}
|
56
InputProcessor.cpp
Normal file
56
InputProcessor.cpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
#include "InputProcessor.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
InputProcessor::InputProcessor() {
|
||||
_fileIn = std::ifstream();
|
||||
_allWords = std::vector<std::string>();
|
||||
}
|
||||
|
||||
bool InputProcessor::openStream() {
|
||||
std::string file;
|
||||
std::cout << "What is the name of the file you would like to read? ";
|
||||
std::cin >> file;
|
||||
|
||||
if (std::cin.fail()) {
|
||||
std::cout << "Invalid file input";
|
||||
return false;
|
||||
}
|
||||
|
||||
_fileIn.open(file);
|
||||
if (_fileIn.fail()) {
|
||||
std::cout << "Unable to open file, does it exist?" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void InputProcessor::closeStream() { _fileIn.close(); }
|
||||
|
||||
void InputProcessor::read() {
|
||||
std::string characterBuffer = "";
|
||||
char currentChar;
|
||||
while (_fileIn.get(currentChar)) {
|
||||
switch (currentChar) {
|
||||
case ' ':
|
||||
case '\n':
|
||||
_allWords.push_back(characterBuffer);
|
||||
characterBuffer.clear();
|
||||
break;
|
||||
default:
|
||||
characterBuffer += currentChar;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Flush the rest of the buffer if the file doesn't end with a space or
|
||||
// newline
|
||||
if (!characterBuffer.empty()) {
|
||||
_allWords.push_back(characterBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> InputProcessor::getAllWords() { return _allWords; }
|
54
InputProcessor.h
Normal file
54
InputProcessor.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef INPUTPROCESSOR_H
|
||||
#define INPUTPROCESSOR_H
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class InputProcessor {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a new InputProcessor, initializing internal fields to
|
||||
* defaults
|
||||
*
|
||||
*/
|
||||
InputProcessor();
|
||||
/**
|
||||
* @brief Prompts the user for the file to open, and opens it as an ifstream
|
||||
*
|
||||
* @return true The stream was opened successfully
|
||||
* @return false The stream was unable to be opened successfully
|
||||
*/
|
||||
bool openStream();
|
||||
/**
|
||||
* @brief Closes the open file stream
|
||||
*
|
||||
*/
|
||||
void closeStream();
|
||||
/**
|
||||
* @brief Reads all words from the currently open stream, and stores them
|
||||
* internally in a vector of all words
|
||||
*
|
||||
*/
|
||||
void read();
|
||||
/**
|
||||
* @brief Returns all the words parsed by this InputProcessor
|
||||
*
|
||||
* @return std::vector<std::string> The vector containing all words
|
||||
*/
|
||||
std::vector<std::string> getAllWords();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief The raw file input stream to read from
|
||||
*
|
||||
*/
|
||||
std::ifstream _fileIn;
|
||||
/**
|
||||
* @brief The vector containing all parsed words from the input stream
|
||||
*
|
||||
*/
|
||||
std::vector<std::string> _allWords;
|
||||
};
|
||||
|
||||
#endif // INPUTPROCESSOR_H
|
20
LICENSE.md
Normal file
20
LICENSE.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or
|
||||
sell copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
85
Makefile
Normal file
85
Makefile
Normal file
|
@ -0,0 +1,85 @@
|
|||
TARGET = A3
|
||||
SRC_FILES = main.cpp InputProcessor.cpp OutputProcessor.cpp
|
||||
|
||||
# Tyler's custom makefile extensions for CSCI200 (anyone can use these if they want)
|
||||
.DEFAULT_GOAL := all # Necessary so `make` doesn't run the "pack" target, as it is declared before "all"
|
||||
.PHONY: pack clean-run c run fmt
|
||||
|
||||
## Adds only the necessary files for build into a .tar.gz file, named appropriately
|
||||
ARCHIVED_FILES = Makefile $(SRC_FILES) $(SRC_FILES:.cpp=.h) $(SRC_FILES:.cpp=.hpp)
|
||||
pack: fmtc
|
||||
tar --ignore-failed-read -czvf $(TARGET).tar.gz $(shell echo $(ARCHIVED_FILES) | xargs ls -d 2>/dev/null)
|
||||
|
||||
## Runs the pack target and then attempts to build & run the program to make sure it functions correctly
|
||||
pack-test: pack
|
||||
$(eval TMP := $(shell mktemp -d))
|
||||
tar -xvzf $(TARGET).tar.gz --directory $(TMP)
|
||||
make -C $(TMP)
|
||||
$(TMP)/$(TARGET)
|
||||
rm -rf $(TMP)
|
||||
|
||||
## An extension of the clean command that is shorter to type and removes a potential .tar.gz file
|
||||
c: clean
|
||||
$(DEL) -f $(TARGET).tar.gz
|
||||
|
||||
## Simply builds and then executes the program
|
||||
run: all
|
||||
./$(TARGET)
|
||||
|
||||
## Formats all cpp, h, and hpp files with clang-format, using my personal clang-format config
|
||||
fmt:
|
||||
find . -iname '*.hpp' -o -iname '*.h' -o -iname '*.cpp' | xargs clang-format --style=file:.clang-format -i
|
||||
|
||||
## Formats all cpp, h, and hpp files with clang-format, using the class clang-format config
|
||||
fmtc:
|
||||
find . -iname '*.hpp' -o -iname '*.h' -o -iname '*.cpp' | xargs clang-format --style=file:.class-clang-format -i
|
||||
|
||||
## Modifies the SRC_FILES variable to have all .cpp files in the repo
|
||||
setupsrc:
|
||||
sed -i "0,/SRC_FILE.\{0\}S = .*/ s//SRC_FILES = $(shell find . -iname '*.cpp' -printf '%P\n')/" Makefile
|
||||
|
||||
## Alias to setup SRC_FILES and then dependencies
|
||||
setup: setupsrc depend
|
||||
|
||||
# NO EDITS NEEDED BELOW THIS LINE
|
||||
|
||||
CXX = g++
|
||||
CXXFLAGS = -O2
|
||||
CXXFLAGS_DEBUG = -g
|
||||
CXXFLAGS_WARN = -Wall -Wextra -Wunreachable-code -Wshadow -Wpedantic
|
||||
CPPVERSION = -std=c++17
|
||||
|
||||
OBJECTS = $(SRC_FILES:.cpp=.o)
|
||||
|
||||
ifeq ($(shell echo "Windows"), "Windows")
|
||||
TARGET := $(TARGET).exe
|
||||
DEL = del
|
||||
Q =
|
||||
else
|
||||
DEL = rm -f
|
||||
Q = "
|
||||
endif
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
$(TARGET): $(OBJECTS)
|
||||
$(CXX) -o $@ $^
|
||||
|
||||
.cpp.o:
|
||||
$(CXX) $(CXXFLAGS) $(CPPVERSION) $(CXXFLAGS_DEBUG) $(CXXFLAGS_WARN) -o $@ -c $<
|
||||
|
||||
clean:
|
||||
$(DEL) -f $(TARGET) $(OBJECTS) Makefile.bak
|
||||
|
||||
depend:
|
||||
@sed -i.bak '/^# DEPENDENCIES/,$$d' Makefile
|
||||
@$(DEL) sed*
|
||||
@echo $(Q)# DEPENDENCIES$(Q) >> Makefile
|
||||
@$(CXX) -MM $(SRC_FILES) >> Makefile
|
||||
|
||||
.PHONY: all clean depend
|
||||
|
||||
# DEPENDENCIES
|
||||
main.o: main.cpp InputProcessor.h OutputProcessor.h
|
||||
InputProcessor.o: InputProcessor.cpp InputProcessor.h
|
||||
OutputProcessor.o: OutputProcessor.cpp OutputProcessor.h
|
92
OutputProcessor.cpp
Normal file
92
OutputProcessor.cpp
Normal file
|
@ -0,0 +1,92 @@
|
|||
#include "OutputProcessor.h"
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
OutputProcessor::OutputProcessor() {
|
||||
_fileOut = std::ofstream();
|
||||
_allWords = std::vector<std::string>();
|
||||
_uniqueWords = std::vector<std::string>();
|
||||
_letterCounts = std::vector<unsigned int>(26, 0);
|
||||
_wordCounts = std::vector<unsigned int>();
|
||||
_totalLetterCount = 0;
|
||||
_totalWordCount = 0;
|
||||
}
|
||||
|
||||
void OutputProcessor::analyzeWords(std::vector<std::string> allWords,
|
||||
std::string punctuation) {
|
||||
// Iterate over all words, processing incrementally
|
||||
for (size_t wordIdx = 0; wordIdx < allWords.size(); wordIdx++) {
|
||||
std::string& word = allWords.at(wordIdx);
|
||||
|
||||
// Remove punctuation from word
|
||||
size_t punctuationIdx = 0;
|
||||
while ((punctuationIdx = word.find_first_of(punctuation)) !=
|
||||
std::string::npos) {
|
||||
word.erase(punctuationIdx, 1);
|
||||
}
|
||||
|
||||
// Save word internally
|
||||
_allWords.push_back(word);
|
||||
|
||||
// Check all unique words for a match, and if so increment the count
|
||||
bool foundUnique = false;
|
||||
for (size_t uniqueWordIdx = 0; uniqueWordIdx < _uniqueWords.size();
|
||||
uniqueWordIdx++) {
|
||||
if (_uniqueWords.at(uniqueWordIdx) == word) {
|
||||
_wordCounts.at(uniqueWordIdx)++;
|
||||
foundUnique = true;
|
||||
}
|
||||
}
|
||||
// If no unique word exists, add it to both vectors
|
||||
if (!foundUnique) {
|
||||
_uniqueWords.push_back(word);
|
||||
_wordCounts.push_back(1);
|
||||
}
|
||||
|
||||
// Add letter count for each letter in the word
|
||||
for (size_t letterIdx = 0; letterIdx < word.length(); letterIdx++) {
|
||||
char letter = word.at(letterIdx);
|
||||
// Normalize to uppercase
|
||||
if (letter >= 'a' && letter <= 'z') {
|
||||
letter -= 32;
|
||||
}
|
||||
// Subtracting an uppercase letter by 65 creates its alphabetical
|
||||
// index
|
||||
letter -= 65;
|
||||
_letterCounts.at(letter)++;
|
||||
}
|
||||
|
||||
// Sum total letter count
|
||||
_totalLetterCount += word.length();
|
||||
|
||||
// Increment total word count
|
||||
_totalWordCount++;
|
||||
}
|
||||
}
|
||||
|
||||
bool OutputProcessor::openStream() {
|
||||
std::string file;
|
||||
std::cout << "What is the name of the file you would like to write to? ";
|
||||
std::cin >> file;
|
||||
|
||||
if (std::cin.fail()) {
|
||||
std::cout << "Invalid file input";
|
||||
return false;
|
||||
}
|
||||
|
||||
_fileOut.open(file);
|
||||
if (_fileOut.fail()) {
|
||||
std::cout << "Unable to open file, does it exist?" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void OutputProcessor::closeStream() { _fileOut.close(); }
|
||||
|
||||
void OutputProcessor::write() {
|
||||
// TODO
|
||||
}
|
89
OutputProcessor.h
Normal file
89
OutputProcessor.h
Normal file
|
@ -0,0 +1,89 @@
|
|||
#ifndef OUTPUTPROCESSOR_H
|
||||
#define OUTPUTPROCESSOR_H
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
class OutputProcessor {
|
||||
public:
|
||||
/**
|
||||
* @brief Constructs a new OutputProcessor, setting internal fields to their
|
||||
* initial state
|
||||
*
|
||||
*/
|
||||
OutputProcessor();
|
||||
/**
|
||||
* @brief Removes punctuation from the list of allWords, stores this
|
||||
* internally, and then computes the list of all unique words in the
|
||||
* original vector. In addition, it will compute the amount of occurrences
|
||||
* of all words in the text, and the amounts of letters in each word in the
|
||||
* text.
|
||||
*
|
||||
* @param allWords The vector containing all read words from the text
|
||||
* @param punctuation A string containing punctuation to remove from the
|
||||
* original vector of words
|
||||
*/
|
||||
void analyzeWords(std::vector<std::string> allWords, std::string punctuation);
|
||||
/**
|
||||
* @brief Prompts the user for the filename of the file they wish to open
|
||||
* for outputting to, and then opens an output stream to that file
|
||||
*
|
||||
* @return true The stream was opened successfully
|
||||
* @return false The stream was unable to be opened successfully
|
||||
*/
|
||||
bool openStream();
|
||||
/**
|
||||
* @brief Closes the open output stream
|
||||
*
|
||||
*/
|
||||
void closeStream();
|
||||
/**
|
||||
* @brief Nicely prints the computed data to the output stream as specified
|
||||
*
|
||||
*/
|
||||
void write();
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief The output stream to write to
|
||||
*
|
||||
*/
|
||||
std::ofstream _fileOut;
|
||||
/**
|
||||
* @brief The list of all words with punctuation removed
|
||||
*
|
||||
*/
|
||||
std::vector<std::string> _allWords;
|
||||
/**
|
||||
* @brief The list of all unique words, parsed from the full set
|
||||
*
|
||||
*/
|
||||
std::vector<std::string> _uniqueWords;
|
||||
/**
|
||||
* @brief A vector containing information on how often each letter occurs in
|
||||
* the text. The index corresponds to the alphabetical value minus one (A is
|
||||
* 0, B is 1, C is 2, etc)
|
||||
*
|
||||
*/
|
||||
std::vector<unsigned int> _letterCounts;
|
||||
/**
|
||||
* @brief A vector containing information on how common each unique words is
|
||||
* in the list of all words. The index for each word in _uniqueWords is the
|
||||
* same as the index for the same word in this vector.
|
||||
*
|
||||
*/
|
||||
std::vector<unsigned int> _wordCounts;
|
||||
/**
|
||||
* @brief The total amount of letters in the text
|
||||
*
|
||||
*/
|
||||
unsigned int _totalLetterCount;
|
||||
/**
|
||||
* @brief The total amount of words in the text
|
||||
*
|
||||
*/
|
||||
unsigned int _totalWordCount;
|
||||
};
|
||||
|
||||
#endif // OUTPUTPROCESSOR_H
|
23
input/aliceChapter1.txt
Normal file
23
input/aliceChapter1.txt
Normal file
|
@ -0,0 +1,23 @@
|
|||
Alice was beginning to get very tired of sitting by her sister on the
|
||||
bank, and of having nothing to do: once or twice she had peeped into the
|
||||
book her sister was reading, but it had no pictures or conversations in
|
||||
it, "and what is the use of a book," thought Alice, "without pictures or
|
||||
conversation?"
|
||||
|
||||
So she was considering in her own mind (as well as she could, for the
|
||||
hot day made her feel very sleepy and stupid), whether the pleasure
|
||||
of making a daisy-chain would be worth the trouble of getting up and
|
||||
picking the daisies, when suddenly a White Rabbit with pink eyes ran
|
||||
close by her.
|
||||
|
||||
There was nothing so VERY remarkable in that; nor did Alice think it so
|
||||
VERY much out of the way to hear the Rabbit say to itself, "Oh dear!
|
||||
Oh dear! I shall be late!" (when she thought it over afterwards, it
|
||||
occurred to her that she ought to have wondered at this, but at the time
|
||||
it all seemed quite natural); but when the Rabbit actually TOOK A WATCH
|
||||
OUT OF ITS WAISTCOAT-POCKET, and looked at it, and then hurried on,
|
||||
Alice started to her feet, for it flashed across her mind that she had
|
||||
never before seen a rabbit with either a waistcoat-pocket, or a watch
|
||||
to take out of it, and burning with curiosity, she ran across the field
|
||||
after it, and fortunately was just in time to see it pop down a large
|
||||
rabbit-hole under the hedge.
|
131
input/greeneggsandham.txt
Normal file
131
input/greeneggsandham.txt
Normal file
|
@ -0,0 +1,131 @@
|
|||
I AM SAM. I AM SAM. SAM I AM.
|
||||
|
||||
THAT SAM I AM! THAT SAM I AM! I DO NOT LIKE THAT SAM I AM!
|
||||
|
||||
WOULD YOU LIKE GREEN EGGS AND HAM?
|
||||
|
||||
I DO NOT LIKE THEM, SAM I AM.
|
||||
I DO NOT LIKE GREEN EGGS AND HAM.
|
||||
|
||||
WOULD YOU LIKE THEM HERE OR THERE?
|
||||
|
||||
I WOULD NOT LIKE THEM HERE OR THERE.
|
||||
I WOULD NOT LIKE THEM ANYWHERE.
|
||||
I DO NOT LIKE GREEN EGGS AND HAM.
|
||||
I DO NOT LIKE THEM, SAM I AM.
|
||||
|
||||
WOULD YOU LIKE THEM IN A HOUSE?
|
||||
WOULD YOU LIKE THEM WITH A MOUSE?
|
||||
|
||||
I DO NOT LIKE THEM IN A HOUSE.
|
||||
I DO NOT LIKE THEM WITH A MOUSE.
|
||||
I DO NOT LIKE THEM HERE OR THERE.
|
||||
I DO NOT LIKE THEM ANYWHERE.
|
||||
I DO NOT LIKE GREEN EGGS AND HAM.
|
||||
I DO NOT LIKE THEM, SAM I AM.
|
||||
|
||||
WOULD YOU EAT THEM IN A BOX?
|
||||
WOULD YOU EAT THEM WITH A FOX?
|
||||
|
||||
NOT IN A BOX. NOT WITH A FOX.
|
||||
NOT IN A HOUSE. NOT WITH A MOUSE.
|
||||
I WOULD NOT EAT THEM HERE OR THERE.
|
||||
I WOULD NOT EAT THEM ANYWHERE.
|
||||
I WOULD NOT EAT GREEN EGGS AND HAM.
|
||||
I DO NOT LIKE THEM, SAM I AM.
|
||||
|
||||
WOULD YOU? COULD YOU? IN A CAR?
|
||||
EAT THEM! EAT THEM! HERE THEY ARE.
|
||||
|
||||
I WOULD NOT, COULD NOT, IN A CAR.
|
||||
|
||||
YOU MAY LIKE THEM. YOU WILL SEE.
|
||||
YOU MAY LIKE THEM IN A TREE!
|
||||
|
||||
I WOULD NOT, COULD NOT IN A TREE.
|
||||
NOT IN A CAR! YOU LET ME BE.
|
||||
I DO NOT LIKE THEM IN A BOX.
|
||||
I DO NOT LIKE THEM WITH A FOX.
|
||||
I DO NOT LIKE THEM IN A HOUSE.
|
||||
I DO NOT LIKE THEM WITH A MOUSE.
|
||||
I DO NOT LIKE THEM HERE OR THERE.
|
||||
I DO NOT LIKE THEM ANYWHERE.
|
||||
I DO NOT LIKE GREEN EGGS AND HAM.
|
||||
I DO NOT LIKE THEM, SAM I AM.
|
||||
|
||||
A TRAIN! A TRAIN! A TRAIN! A TRAIN!
|
||||
COULD YOU, WOULD YOU ON A TRAIN?
|
||||
|
||||
NOT ON TRAIN! NOT IN A TREE!
|
||||
NOT IN A CAR! SAM! LET ME BE!
|
||||
I WOULD NOT, COULD NOT, IN A BOX.
|
||||
I WOULD NOT, COULD NOT, WITH A FOX.
|
||||
I WILL NOT EAT THEM IN A HOUSE.
|
||||
I WILL NOT EAT THEM HERE OR THERE.
|
||||
I WILL NOT EAT THEM ANYWHERE.
|
||||
I DO NOT EAT GREEN EGGS AND HAM.
|
||||
I DO NOT LIKE THEM, SAM I AM.
|
||||
|
||||
SAY! IN THE DARK? HERE IN THE DARK!
|
||||
WOULD YOU, COULD YOU, IN THE DARK?
|
||||
|
||||
I WOULD NOT, COULD NOT, IN THE DARK.
|
||||
|
||||
WOULD YOU COULD YOU IN THE RAIN?
|
||||
|
||||
I WOULD NOT, COULD NOT IN THE RAIN.
|
||||
NOT IN THE DARK. NOT ON A TRAIN.
|
||||
NOT IN A CAR. NOT IN A TREE.
|
||||
I DO NOT LIKE THEM, SAM, YOU SEE.
|
||||
NOT IN A HOUSE. NOT IN A BOX.
|
||||
NOT WITH A MOUSE. NOT WITH A FOX.
|
||||
I WILL NOT EAT THEM HERE OR THERE.
|
||||
I DO NOT LIKE THEM ANYWHERE!
|
||||
|
||||
YOU DO NOT LIKE GREEN EGGS AND HAM?
|
||||
|
||||
I DO NOT LIKE THEM, SAM I AM.
|
||||
|
||||
COULD YOU, WOULD YOU, WITH A GOAT?
|
||||
|
||||
I WOULD NOT, COULD NOT WITH A GOAT!
|
||||
|
||||
WOULD YOU, COULD YOU, ON A BOAT?
|
||||
|
||||
I COULD NOT, WOULD NOT, ON A BOAT.
|
||||
I WILL NOT, WILL NOT, WITH A GOAT.
|
||||
I WILL NOT EAT THEM IN THE RAIN.
|
||||
NOT IN THE DARK! NOT IN A TREE!
|
||||
NOT IN A CAR! YOU LET ME BE!
|
||||
I DO NOT LIKE THEM IN A BOX.
|
||||
I DO NOT LIKE THEM WITH A FOX.
|
||||
I WILL NOT EAT THEM IN A HOUSE.
|
||||
I DO NOT LIKE THEM WITH A MOUSE.
|
||||
I DO NOT LIKE THEM HERE OR THERE.
|
||||
I DO NOT LIKE THEM ANYWHERE!
|
||||
I DO NOT LIKE GREEN EGGS AND HAM!
|
||||
I DO NOT LIKE THEM, SAM I AM.
|
||||
|
||||
YOU DO NOT LIKE THEM. SO YOU SAY.
|
||||
TRY THEM! TRY THEM! AND YOU MAY.
|
||||
TRY THEM AND YOU MAY, I SAY.
|
||||
|
||||
SAM! IF YOU LET ME BE,
|
||||
I WILL TRY THEM. YOU WILL SEE.
|
||||
|
||||
SAY! I LIKE GREEN EGGS AND HAM!
|
||||
I DO! I LIKE THEM, SAM I AM!
|
||||
AND I WOULD EAT THEM IN A BOAT.
|
||||
AND I WOULD EAT THEM WITH A GOAT...
|
||||
AND I WILL EAT THEM, IN THE RAIN.
|
||||
AND IN THE DARK. AND ON A TRAIN.
|
||||
AND IN A CAR. AND IN A TREE.
|
||||
THEY ARE SO GOOD, SO GOOD, YOU SEE!
|
||||
SO I WILL EAT THEM IN A BOX.
|
||||
AND I WILL EAT THEM WITH A FOX.
|
||||
AND I WILL EAT THEM IN A HOUSE.
|
||||
AND I WILL EAT THEM WITH A MOUSE.
|
||||
AND I WILL EAT THEM HERE AND THERE.
|
||||
SAY! I WILL EAT THEM ANYWHERE!
|
||||
I DO SO LIKE GREEN EGGS AND HAM!
|
||||
THANK YOU! THANK YOU, SAM I AM.
|
4
input/happybirthday.txt
Normal file
4
input/happybirthday.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
Happy birthday to you,
|
||||
Happy birthday to you,
|
||||
Happy birthday to Bjourne,
|
||||
Happy birthday to you!
|
4316
input/romeoandjuliet.txt
Normal file
4316
input/romeoandjuliet.txt
Normal file
File diff suppressed because it is too large
Load diff
47
main.cpp
Normal file
47
main.cpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
#include "InputProcessor.h" // our custom InputProcessor class
|
||||
#include "OutputProcessor.h" // our custom OutputProcessor class
|
||||
|
||||
#include <iostream> // for cout, endl
|
||||
#include <string> // for string
|
||||
#include <vector> // for vector
|
||||
using namespace std; // so we don't have to type std:: every time
|
||||
|
||||
int main() {
|
||||
// create an input processor object
|
||||
InputProcessor iProcessor;
|
||||
|
||||
// open a stream to input from
|
||||
if (!iProcessor.openStream()) {
|
||||
// if stream failed to open, quit the program
|
||||
cerr << "Shutting down..." << endl;
|
||||
return -1;
|
||||
}
|
||||
// read the data on the stream
|
||||
iProcessor.read();
|
||||
// close the input stream
|
||||
iProcessor.closeStream();
|
||||
|
||||
// retrieve all the words read from the stream
|
||||
std::vector<std::string> inputWords = iProcessor.getAllWords();
|
||||
|
||||
// create an output processor object
|
||||
OutputProcessor oProcessor;
|
||||
// analyze the words and ignore the specified punctuation
|
||||
oProcessor.analyzeWords(inputWords, "?!.,;:\"()_-'&[]");
|
||||
// open a stream to output to
|
||||
if (!oProcessor.openStream()) {
|
||||
// if stream failed to open, quit the program
|
||||
cerr << "Shutting down..." << endl;
|
||||
return -2;
|
||||
}
|
||||
// write the data to the stream
|
||||
oProcessor.write();
|
||||
// close the output stream
|
||||
oProcessor.closeStream();
|
||||
|
||||
// signal to user program has completed
|
||||
cout << "Analysis complete, check file for results" << endl;
|
||||
|
||||
// end our program!
|
||||
return 0;
|
||||
}
|
Loading…
Reference in a new issue