OBJ: use the apstring class
Words found in text -- 1 In 2 this 3 lab, : 50 message. The longest word in the text isFor your text file, use the example from class,.
"cabbages.txt"
.
You may obtain a copy of it from your teacher. When you write your client
program "cabbages.cpp"
, be sure to add the statement
#include "apstring.h"
and "apvector.h"
at the top.
Check that the compiler knows where to find the header file.Hint for Part 1:
void readIn ( ) { ifstream infile ("cabbages.txt"); if ( ! infile ) { cout << "File could not be opened." << endl; exit (1); } apstring temp; // for processing before putting into an array while ( infile >> temp ) // reads one contiguous stream of non-space { // characters- discards delimiters (space, eoln, eof, tab) : // print to screen with running count : }
Words sorted alphabetically with duplicates removed -- 0 a 1 after 2 all 3 been :Hint for Part 2:
void readIn ( apvector& words) { : int num, index = 0; apstring temp; // for processing before putting into an array while ( infile >> temp ) // reads one contiguous stream of non-space characters { // discards delimiters (tab, space, eoln, eof) : //Set up an empty string to concatenate into, one letter at a time words[index] = ""; : num = temp.length( ); for (int j = 0;j < num;j++) // process one character at a time { : // place only "accepted" lowercase, alphabetic characters into the string word[index] = word[index] + temp[ j ]; : index++; // increment number of "words" } // for } // while words.resize(index); // adjust size to actual length when finished reading }
grep("the longest word");would display
Line 2: rememberingIf the phrase does not appear in any line, state that., print the current word count and a space before each word. Line 3: After all the words have been read in, display with a message.
Hint for Part 3: Use the overloaded getline function to read in a line, including white space, from either the text file or the keyboard
while ( getline(infile >> temp) ) { .. } getline(cin, temp);