Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using namespace std;
- #include <iostream>
- #include <cstring>
- #include <cctype>
- #include <iomanip>
- void CountValue(int &WordLength, int &CharCount, int FrequencyArray[]); //function prototype
- int main() {
- const int MAX_SIZE_OF_ARRAY = 16; //variable declaration
- int FrequencyArray[MAX_SIZE_OF_ARRAY] = { 0 };
- int CharCount = 0, WordLength = 0;
- char ch;
- cout << "Enter words:" << endl; //first round at receiving input from either the keyboard or a file
- cin.get(ch);
- while (cin.get() != '0') { //if the input is zero, it will exit the while loop and move to display the table
- if (isalpha(ch)) //checks to see if whatever is stored in ch is alphabetical and increments wordlength if it is
- WordLength++;
- else {
- CountValue(WordLength, CharCount, FrequencyArray);
- WordLength = 0;
- }
- cout << "enter words again" << endl;
- cin.get(ch);
- }
- CountValue(WordLength, CharCount, FrequencyArray);
- while (cin.get() != '1') {
- cout << "Word Length Frequency" << endl;
- for (int i = 1; i < MAX_SIZE_OF_ARRAY; i++) {
- cout << setw(6) << right << i << " "
- << setw(8) << right << FrequencyArray[i] << endl;
- }
- }
- // add average
- }
- void CountValue( int &WordLength, int &CharCount, int FrequencyArray[]) {
- const int MAX = 16;
- if (WordLength > 0) {
- if (WordLength > (MAX - 1))
- WordLength = MAX - 1;
- }
- FrequencyArray[WordLength]++;
- CharCount = CharCount + WordLength;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement