Question: I want to add to this code upper and lower case count . ------------------------------------------------- // fileStatistics class #ifndef _FILE_STATISTICS_H_ #define _FILE_STATISTICS_H_ #include #include #include #include
I want to add to this code upper and lower case count .
-------------------------------------------------
// fileStatistics class
#ifndef _FILE_STATISTICS_H_ #define _FILE_STATISTICS_H_
#include
using namespace std;
class fileStatistics { private: string fname; // file name int wordCount; // word count in the file int uniqueWordCount; // unique word count int charCount; // number of characters in the file map
public: // constructors fileStatistics(string s); fileStatistics(string s, int tries); // processing txt from the file // update the char counts and their occurrences void update_char_occurrences(string txt); void update_char_frequencies(); // update the list of words by adding those in counts vector
// destructor ~fileStatistics() {} };
// file statistics app void fs_app();
// utility functions
// return the lower case version of a string string stolower(string s);
// debugging function- file stream state
void print_file_stream_bit_states(ifstream& fs); #endif // _FILE_STATISTICS_H_
---------------------------------------------------
// file statistics implementation
#include
using namespace std;
void fileStatistics::reset_counts() { wordCount = uniqueWordCount = 0; charCount = 0; }
void fileStatistics::reset_maps() { const int ASCII_START = 0; const int ASCII_END = 255; for(int i = ASCII_START; i <= ASCII_END; i++ ) { char c = static_cast
fileStatistics::fileStatistics(string s) { fname = s; num_tries = 3; // default value reset_counts(); reset_maps(); }
fileStatistics::fileStatistics(string s, int tries) { fname = s; num_tries = tries; reset_counts(); reset_maps(); }
void fileStatistics::update_char_occurrences(string txt) { for (unsigned int i = 0; i < txt.size(); i++) { c_occurences[txt[i]]++; charCount++; } }
void fileStatistics::update_char_frequencies() { const int ASCII_START = 0; const int ASCII_END = 255; for (int i = ASCII_START; i <= ASCII_END; ++i) { char c = static_cast
vector
int fileStatistics::determine_unique_words_count() { set
int fileStatistics::update_unique_words() { uniqueWordCount = determine_unique_words_count(); return (uniqueWordCount); }
int fileStatistics::update_char_counts(string txt) { update_char_occurrences(txt); return (charCount); }
void fs_app() {
}
string stolower(string s) { string r; for (unsigned int i = 0; i < s.length(); i++) r += tolower(s[i]); return r; }
void print_file_stream_bit_states(ifstream& fs) { cout << "DEBUGGING INFORMATION: " << endl; cout << "Good bit: " << fs.good() << endl; cout << "Bad bit: " << fs.bad() << endl; cout << "fail bit: " << fs.fail() << endl; cout << "eof bit: " << fs.eof() << endl; }
-------------------------------------------
#include
using namespace std;
void tester1();
int main() { tester1(); } void tester1() { fileStatistics fs("hello"); string x("Hello hello World!Greetings.I am ok.I love myself some chocolate."); vector
int uw = fs.update_unique_words(); cout << "Unique words: " << uw << endl;
// debugging info cout << endl << endl;
ifstream inputf("main.cc"); print_file_stream_bit_states(inputf); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
