Write a program which asks the user to write some text before analysing it to see how many occurrences of each vowel appears in that text, you should store the number of occurrences of each vowel in an array of size 5. (Hint: use qin for this, with the ‘Return’ key to terminate input. ASCII code for ‘Return’ is 13)

Adapt this program to produce some more statistics about the text, this may include some or all of the following...

● The vowel that occurs most/least often
● The average (mean) number of occurrences for the vowels
● A list of vowels, ordered by number of occurrences
● You could even use the Cursor and Colour controllers to draw a histogram!


REALLY DONT KNOW WHERE TO START : iv not been in uni for a month due to an unforgeable death

Recommended Answers

All 8 Replies

Try this

#include <iostream>
    #include <string>
    #include <cstring>
     
    using namespace std;
     
    void stringout();
    string input;
     
    int main()
    {
     
    cout << "Input a string of characters: " ;
    cin >> input;
    cout << "You entered: " << input << endl;
     
    stringout();
     
     
    return 0;
    }
     
    void stringout()
    {
    char ch;
    int vowel=0, consonant=0;
    int length = input.length();
     
    for (int i = 0; i < length; i++)
    {
      ch = tolower(input [i]);
      if(ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u')
      ++vowels;

      else
      ++consonant;
    }
     
     
    cout << "This has " << input.length() << " characters, " <<
    vowel << " vowels, and " << consonant << " consonants." << endl;
    }
commented: No Spoon feeding please -1
commented: This is a good starting point. +2

Try this

And what grade do you expect to get for doing sodha125's homework for him? Around here we call that cheating... Good job!

WaltP's response seems a bit harsh to me. The program posted does indeed demonstrate one way to accept input (though it doesn't look like it will appease the instructor given the comment in the instructions that the ASCII value for return key is 13, implying that input should accept all valid key input, including whitespace), and it does demonstrate one way to tell if a char is a vowel, but it doesn't demonstrate how to store information about individual vowels or how to analyze the information as requested in the instructions provided. All in all if the program as posted were presented as final project I would give it a D at best, given the mere basics it demonstrates. All in all, I would have been more comfortable if sodha125 had posted cangan's program, but as a place to start from, I found cangan's program reasonable. On the other hand I'm not a moderator nor do I have the experience WaltP does; I am just expressing my opinion as well as to express my hope that cangan doesn't feel too castigated.

The posted program doesn't solve the original question, all it does is demonstrate one way to identify vowels. The OP would have to add quite a bit of code in order to complete the assignment.

@Lerner: ditto.
@Ancient Dragon: Also ditto.
Cangan's code is a starting point. Nothing more. And that's what was asked for.
I'd replace the if statement with a switch/case block that catches vowels.
Lastly, the instructor says to use cin, but to break on the return. Cin accepts until return, but breaks the string on any whitespace. Unless you explicitly tell it otherwise. Getline, anyone? Eh, on second thought, give the instructor what they ask for, not what you think they want.

My point is we do not condone posting working programs as a starting point for a poster. We help him write his own code. The program does a large chunk of what the OP needed -- enough that the homework would not be his.

If cangan had posted psuedo-code, I would have no problem with the post.

My comment stands.

commented: Agreed +3

>>sodha125---The best way to start a project is to take a piece of paper and pencil (pen if you're bold) and write out what to do before ever setting down in front of the keyboard. For example you could start by rewriting the information in your post like this:

1) Obtain input:
 From where?
 Without or without whitespace?
2) Evaluate input char by char
   is it a vowel
    if so, increment a counter for the appropriate vowel
3) determine which vowel occurs most often in the collection of vowels
4) determine average (mean) occurence for the vowels in the collection of vowels:
     eg a = 3, e = 9, i = 6 would yield average of 6
5) display vowels in the collection in ascending order by frequency in a table listing vowel and fequencey of occurence for each vowel

Then expand each step, answering questions you initially wrote at each step, looking up techniques to accomplish a given task if needed (ask a specific question with pertinent code at a place like Daniweb if you can't find answers elsewhere) and adjusting the written language to look more like code with each iteration through the steps until you get pseudocode and then, and only then, try to write actual code. As you write the code don't write more than one step (or one part of a step) without recompiling. When you get as good as WaltP or Ancient Dragon, then you can hedge on these steps, but the basic process will remain the same, it's just that you do it in your head rather than with paper and pencil----though I suspect there is a ready supply of paper and pencil in their workspace if we had the oppotunity to look.

>>cangan---I agree with WaltP. It is not appropriate to help too much with homework. The only reason I came down on your side is that I too struggle with how much is too much help and I didn't want you to feel too intimidated. I've had the same criticisms leveled at me, correctly so, in the past. We learn as we go.

>> WaltP---I understand and respect your position. My only disagreement is with how much help is too much help.

commented: Much meaning in what you wrote +3

So, that is funny :) i arrived here by change :) i want to translate "● The average (mean) number of occurrences for the vowels" because my eanglish is not good :) and i found my problem for my challange :)) .
So, sodha125 , he can't use this method because he has not learn: void function, length = input.length(); and more about from this program, so this solution did not help.

So, sodha125 if you want, i can help you with solution, but you need to understand before you submit problem.

Here is my ideea , maybe this can help you to understand and solve problem, after you understand this , problem is very simple.

for ( i=0;i<a;i++ )
	{   
		
		qin.Echo();
		qin>>b;
		if(b!=char(13)){      // Enter is 13
		
			cuv[i]=b; } else break;
		
	} 
	
	for ( int i=0;i<a;i++ )
	{ if( cuv[i]=='a' || cuv[i]=='e' || cuv[i]=='i' || cuv[i]=='o' || cuv[i]=='u' ) { 
		muie++; 
	    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.