-
Help in C++
Hi can some one help me do this program the output will ask a user to enter a word or a pharse and the program shuld tell the number of vowels, #of consonants and the number of the digits
for exaple i enter a long word with some number ex: ILOVETOGOTOSCHOOL45 this is just example and then the computer has to tell the #of vowels in this word, # of consonants and the #of digits so if some one can help me plese i need this i soon as i can
#####################################3############ ##################################
#include <iostream.h>
#include <ctype.h>
#include "charCount.h"
//this prototype should go in in charcount.h
void charCount(char* input, int &vowels, int &consonants, int &num)
{
cout<<"Enter a pharse or a word" <<endl;
cin>>input ;
}
void main(char* argc, char* argv[])
{
int vowels=0;
int consonants=0;
int num=0;
charCount(argv[1], vowels, consonants, num);
cout << "Vowels; "<<vowels <<
"Consonants "<<"Numbers: "<< num <<endl;
}
-
You don't do homework? Neither do I!
If you have any specific problems, feel free to post them, but you have to show some effort.
-
basically:
Code:
int CountVowels(char* String)
{
int Number = 0;
for(int i=0; i<strlen(String); i++)
{
if(CharIsVowel(String[i]) == true)
{
Number++;
}
}
return Number;
}
You have to implement bool CharIsVowel(char) and the rest yourself ;).
-
Try creating a class:
Code:
class SentenceManip
{
public:
SentanceManip() { _vowels = 0; ... }
~SentanceManip() { }
void getSentence() { cin >> _phase; }
void wordCount();
void Display();
private:
string _phrase;
int _vowels;
int _consonants;
int _size;
};
inline void SentenceManip::wordCount ()
{
_size = _pharase.size();
...
}
-------------------------------------
int main()
{
SentenceManip obj;
cout << "Enter a phrase: ";
obj.getSentence();
obj.wordCount();
obj.Display();
return 0;
}
This is a general idea, but use a class concept to fit your own requirements.