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

a C++ which to print all of the words in the English language of a given length,

ID: 3634902 • Letter: A

Question

a C++ which to print all of the words in the English language of a given length, with the length being supplied by the user.

it will prompt the user for positive, integer word length. It will continue to prompt the user until a positive, non-zero value is provided. Upon receiving a valid value, it will read an entire dictionary file, line by line, where each line has a single word (it is acceptable that some of the “words” contain spaces). For each word that is of the length entered by the user, your program will print the word to the screen. Before terminating, your program will print the total number of words found for the given length.

Consider using the istream& getline(istream&, string&) function to read in the words from the file. (Remember that when the end of the file is reached the function will evaluate to false).
Don’t forget that there is a member function on a string object which returns the size of a string.



Words of Length 23

$ ./lengthy
What length words would you like to find? 23

anthropomorphologically
blepharosphincterectomy
epididymodeferentectomy
formaldehydesulphoxylic
gastroenteroanastomosis
hematospectrophotometer
macracanthrorhynchiasis
pancreaticoduodenostomy
pathologicohistological
pericardiomediastinitis
phenolsulphonephthalein
philosophicotheological
Pseudolamellibranchiata
pseudolamellibranchiate
scientificogeographical
thymolsulphonephthalein
transubstantiationalist

Found 17 words of length 23.
$
Invalid Word Lengths

$ ./lengthy
What length words would you like to find? -3
What length words would you like to find? 0
What length words would you like to find? 24

formaldehydesulphoxylate
pathologicopsychological
scientificophilosophical
tetraiodophenolphthalein
thyroparathyroidectomize

Found 5 words of length 24.
$
No dictionary.txt File

$ ./lengthy
Could not open dictionary.
$
No Words of Length
Input File Output File

$ ./lengthy
What length words would you like to find? 30

There were no words of length 30 found.
$

Explanation / Answer

/*Program to Count the number of words present in a text file with given length*/ //header files #include //needed for I/O operations #include //needed for file operations #include //needed for string operations using namespace std; int main() { //variable to hold word from file string line; //variables for processing int count=0, wordlength; //variable to hold a file ifstream infile; //opening a files infile.open("dictionary.txt"); //check the file exist or not if (!infile.is_open()) cout
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