Thread: Help in C++

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    26

    Smile 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;

    }

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    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.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    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 .
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    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.
    Last edited by Troll_King; 10-16-2002 at 03:01 AM.

Popular pages Recent additions subscribe to a feed