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 #include #include #include #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 c_occurences; map c_frequencies; int num_tries; // tolerance level vector words; vector unique_words; // initialize the occurrences and frequencies maps void reset_maps(); // initialize the counts to zero void reset_counts(); // transform txt into a vector of tokens vector tokenize(string txt); // determine the number of unique words int determine_unique_words_count(); void ccprint();

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 update_words(string txt); // updates and return the number of unique words so far int update_unique_words(); // updates and return the number of total words so far // updates and returns the number of total characters so far int update_char_counts(string txt);

// 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 #include #include #include #include #include #include "filestatistics.h"

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 (i); c_occurences[c] = 0; c_frequencies[c] = 0; } }

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 (i); c_frequencies[c] =static_cast (c_occurences[c])/charCount; } }

vector fileStatistics::tokenize(string txt) { // add more word separators- make sure you update // this string to include all separators you may encounter // this is just an example string punctuation_symbols = " .;?-+=!@#$%^&*"; int length = txt.size(); char *cp; cp = new char[length]; for (int i = 0; i < length; i++) *(cp+i) = txt[i]; char *token = strtok(cp, punctuation_symbols.c_str()); while (token) { string s(token); words.push_back(s); token = strtok(NULL, punctuation_symbols.c_str()); } return words; } vector fileStatistics::update_words(string txt) { vector tokens = tokenize(txt); wordCount += tokens.size(); return tokens; }

int fileStatistics::determine_unique_words_count() { set wset; for (unsigned int i = 0; i < words.size(); i++) wset.insert(words.at(i)); return (wset.size()); }

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 #include #include #include "filestatistics.h"

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 v; v = fs.update_words(x); cout << v.size() << endl; for(unsigned int i = 0; i < v.size(); i++) cout << v.at(i) << endl;

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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!