This is my current code, it counts the number of words that do not begin with the letter d, no matter the case. and the number of words beginning with letter d, no matter the case.
I want to add this functionality, I need help I am beginner and trying to learn, it likes it is simple but I don't understand it fully still
Query the user for file, Reporting the number of words beginning with the letter d (irrespective of case) that have one letter, the number of words having two letters, the number of words having three letters, and so on.
cout << "Number of words starting with d or D is " << dCount << endl;
cout << "Number of words not starting with d or D is: " << word_count - dCount << endl;
}
Thats nice, but i believed it wanted u to count the numbers of times the words begin with d that have one letter, then other words in the file that have two , 3 , 4 letters, 5 letters etc.
Well d/D by itself is not a word. If a word begins with d/D that have one letter, then that is just d/D with no following characters. Do you mean d/D followed by just 1 char (eg do)? What is actually required?
No its suppose to count like that only the first letter has to be D or d dont count for anything else,
So its suppose to have a maximum size for the max word length can be, so if i had a word Bundeedle i need it to count the number of letters there are in that word, has to be done for all the words in the text file, assuming max word length is whatever u want it to be. How can I make that work what is the best way can u show me the code?
The instructions aren't clear but thats what I feel like is right,
these are the instructions:
Query the user for file, Reporting the number of words beginning with the letter d (irrespective of case) that have one letter, the number of words having two letters, the number of words having three letters, and so on.
int main(void)
{ string inputFileName;
string s;
ifstream fileIn;
int word_count;
word_count=0;
cout<<"Enter name of file of characters: ";
cin>>inputFileName;
fileIn.open(inputFileName.data());
assert(fileIn.is_open());
while (fileIn>>s)
{cout<<s<<" "<<s.length()<<endl;
word_count++;
}
cout<<"Number of words in file: "<<word_count<<endl;
return 0;
}
#include <iostream>
#include <fstream>
#include <map>
#include <string>
usingnamespace std;
int main()
{
ifstream fin("test.txt");
map<int, int> length_occurrences;
string word;
while (fin >> word)
{
length_occurrences[word.length()]++;
}
for (constauto& item : length_occurrences)
{
cout << item.second << " words have " << item.first << " letters\n";
}
}
Example output:
1 words have 2 letters
4 words have 3 letters
5 words have 4 letters
5 words have 5 letters
3 words have 6 letters
2 words have 7 letters
1 words have 8 letters
Yes, I also agree with that, but it is only suppose to do it for letters that begin with d so if they have 1 letter report it if they have 2 letters report it if they have 3 letters report it, etc how do we do that? How would i specify a maximum word length of a word to count if I wanted to do that as well?