2024-10-07 02:08:54 -06:00
|
|
|
#ifndef OUTPUTPROCESSOR_H
|
|
|
|
#define OUTPUTPROCESSOR_H
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
class OutputProcessor {
|
2024-10-07 18:17:46 -06:00
|
|
|
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
|
2024-10-09 17:20:26 -06:00
|
|
|
* @param PUNCTUATION A string containing punctuation to remove from the
|
2024-10-07 18:17:46 -06:00
|
|
|
* original vector of words
|
|
|
|
*/
|
|
|
|
void analyzeWords(std::vector<std::string> allWords,
|
2024-10-09 17:20:26 -06:00
|
|
|
const std::string PUNCTUATION);
|
2024-10-07 18:17:46 -06:00
|
|
|
/**
|
|
|
|
* @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();
|
2024-10-07 02:08:54 -06:00
|
|
|
|
2024-10-07 18:17:46 -06:00
|
|
|
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;
|
2024-10-07 02:08:54 -06:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // OUTPUTPROCESSOR_H
|