The file hw06-words.txt contains a list of 87,314 words. Write a program that re
ID: 3732898 • Letter: T
Question
The file hw06-words.txt contains a list of 87,314 words. Write a program that reads each word from the file and outputs the word with the most consecutive double letters. For example, the word "tooth" has one pair of double letters, the word “address" has two pairs of consecutive double nsecutive double letter may have the same most consecutive double letters. Output the number of pairs and one of them depending how you wnte the code) on sereen before the program ends You may only use standard C++ string class and its functions. Don't use c-string! You may put theExplanation / Answer
Hi... i have written c++ program for the above.
Main.cpp
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
int main()
{
string myArray[5];
ifstream file("file.txt");
if(file.is_open())
{
for(int i = 0; i < 5; ++i)
{
file >> myArray[i];
}
}
for(int i=0;i<5;i++){
string str = myArray[i];
int count = 0;
int mulcount = 0;
for (int j = 0; j < str.size(); j++){
int count = 0;
for (int i = 0; i < str.size(); i++){
if (str[j] == str[i]) count++;
}
if(count>=2){
// cout << str[j] << endl;
mulcount++;
count=0;
}
}
mulcount = mulcount/2;
if(mulcount>0){
cout << str << " word has "<<mulcount << " pairs of consecutive double letters ";
}
}
}
file.txt
abc
address
hotel
image
committee
Output:
address word has 2 pairs of consecutive double letters
committee word has 3 pairs of consecutive double letters
Please test it and let me know any issues. Thank you. All the best.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.