A3/OutputProcessor.h
2024-10-09 17:20:26 -06:00

90 lines
2.3 KiB
C++

#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,
const 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