Advertisement
Guest User

Untitled

a guest
Jan 31st, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. using namespace std;
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5. #include <cctype>
  6. #include <iomanip>
  7.  
  8.  
  9.  
  10. void CountValue(int &WordLength, int &CharCount, int FrequencyArray[]); //function prototype
  11.  
  12. int main() {
  13.  
  14. const int MAX_SIZE_OF_ARRAY = 16; //variable declaration
  15. int FrequencyArray[MAX_SIZE_OF_ARRAY] = { 0 };
  16. int CharCount = 0, WordLength = 0;
  17. char ch;
  18.  
  19. cout << "Enter words:" << endl; //first round at receiving input from either the keyboard or a file
  20. cin.get(ch);
  21.  
  22. while (cin.get() != '0') { //if the input is zero, it will exit the while loop and move to display the table
  23.  
  24. if (isalpha(ch)) //checks to see if whatever is stored in ch is alphabetical and increments wordlength if it is
  25. WordLength++;
  26.  
  27. else {
  28. CountValue(WordLength, CharCount, FrequencyArray);
  29. WordLength = 0;
  30. }
  31. cout << "enter words again" << endl;
  32. cin.get(ch);
  33. }
  34. CountValue(WordLength, CharCount, FrequencyArray);
  35.  
  36. while (cin.get() != '1') {
  37. cout << "Word Length Frequency" << endl;
  38. for (int i = 1; i < MAX_SIZE_OF_ARRAY; i++) {
  39. cout << setw(6) << right << i << " "
  40. << setw(8) << right << FrequencyArray[i] << endl;
  41. }
  42. }
  43.  
  44. // add average
  45. }
  46.  
  47. void CountValue( int &WordLength, int &CharCount, int FrequencyArray[]) {
  48. const int MAX = 16;
  49.  
  50. if (WordLength > 0) {
  51. if (WordLength > (MAX - 1))
  52. WordLength = MAX - 1;
  53. }
  54. FrequencyArray[WordLength]++;
  55. CharCount = CharCount + WordLength;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement