Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ Goals Problem solving and debugging. Function decomposition. C++ strings. Do

ID: 3813067 • Letter: C

Question

C++ Goals

Problem solving and debugging.

Function decomposition.

C++ strings.

Documentation of program.

A text file contains a series of "words" that are to be reformatted.

Design a C++ program that when given the file (via Linux redirection) will do the following

count the number of non-whitespace characters found in the file (before words are reformatted)

count the number of vowels (upper and lower case) found in the file

count the number of letters (upper and lower case) found in the file

count the number of digits found in the file

for each "word" read,

convert all letters to lower case

remove any leading characters that are not letters or digits

remove any trailing characters that are not letters or digits

display the formatted words (to the screen) in 4 columns (left justified)

determine the longest words in the file (before the leading/trailing characters have been removed and after)

compute the average length of the formatted words (after the leading/trailing characters have been removed)

display the counts, the longest words, and the average length of the formatted words with labels (do not set precision for average, leave at least one blank line between end of table and start of counts)

REQUIREMENTS

The program MUST make use of functions to solve the problem. Identify subtasks and use functions to implement them. Minimum of 3 meaningful functions (in addition to main).

Arrays and/or vectors and/or structs and/or classes CANNOT be used in this program.

DO NOT use global variables. DO NOT use goto statements.

Assumptions/Definitions

a "word" is any series of consecutive non-whitespace characters

          sample words before reformatting:
          world, (2008) %#we're non-whitespace<+!> <{([r2d2])}>!!!

each word in the file will contain at least one letter or one digit

after the word is reformatted it must start and end with a letter or digit

sample reformatted words:    
world 2008 we're non-whitespace r2d2

the "words" in the file will be separated by at least one blank space

each line in the file, including the last line of the file, will be terminated by a linefeed

the following letters will be considered vowels: A, E, I, O, U, a, e, i, o, u

maximum length of a word to be displayed will be 15 characters

the longest words in the file (both before and after formatting) will be unique

the input file will not be empty


Test your program adequately!

Documentation
When the program compiles and runs correctly, add the following documentation (comments) to your source file (.cpp file).

When a named constant and/or major variable is declared, provide a meaningful description of what it represents in the program.

For each function, clearly state what will be passed into the function and what will be passed out or returned by the function. Document important local variables. (See function documentation handout.)

Sample terminal session: eys] S more data. 4three This is a test of the program. let's see what haPPens r2D2 23 skidoo WHEN some data is proces seda 33 Good-bye THE END! keys] s g assign 03 cpp keys S a., out data 4three Word List the program what happens when data processed good-bye the Non-whitespace characters: 113 vowels: 31 Letters: 85 Digits: 4 Longest word before formatting program Longest word after formatting r2d2 23 skidoo Average length of formatted words 4.6 test. let's r2d2 23 skidoo end

Explanation / Answer

#include <iostream>
#include <string>

using namespace std;

string format(string unformatted) {

};

int main()
{
   string data = "";  
   string output = "";
  
   int tot_chars                {0},
       tot_alpha                {0},  
       tot_vowels                {0},  
       tot_digits                {0},
       max_len                {0},
       max_len_after_format    {0};
  
   while (cin)
   {
       cin >> data;      
       tot_chars += data.length();
       string::iterator it;
       int non_numeric {0};
       for (it = data.begin(); it < data.end(); ++it)
       {
           char letter = (int)*it;
           if (
               ((int)letter > 64 && (int)letter < 91) ||
               ((int)letter > 96 && (int)letter < 123) )
           {
               // If it is a vowel
               switch ((int)letter) {
                   case 65:
                   case 69:
                   case 73:
                   case 79:
                   case 85:
                   case 97:
                   case 101:
                   case 105:
                   case 111:
                   case 117:
                       ++tot_vowels;
               }
               ++tot_alpha;
           }              
           else if (
               (int)letter > 47 && (int)letter < 58)
           {
               ++tot_digits;
           }
       }
   }

  
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote