Help plz....Goin mad!!!

0 Bishwa Nath · April 1, 2015
need help with strings.....
objective: count the no of vowels in a string:
code:

//main:

#include <iostream>
#include<string>
#include "VowelCount.h"
using namespace std;

int main()
{
    VowelCount naam('aaaa');
    cout<<CountVowel()<<endl;
    return 0;
}

//header file for the class VowelCount

#ifndef VOWELCOUNT_H
#define VOWELCOUNT_H
#include<string>

class VowelCount
{
    public:
        VowelCount(string);
        int CountVowel();
    private:
        string name;
};

//cpp file for class VowelCount

#include "VowelCount.h"
#include <iostream>
#include<string>
using namespace std;

VowelCount::VowelCount(string n)
: name(n)
{
};

int VowelCount::CountVowel()
{
    int value=0;
    for(int i=0;i<name.length();i++)
    {
        if(name.at(i)=='a'||name.at(i)=='e'||name.at(i)=='i'||name.at(i)=='o'||name.at(i)=='u'||)
        {
            value++;
        }

    }
    return value;

};


//error message:

||=== Build: Debug in name_vowel (compiler: GNU GCC Compiler) ===|

E:\C++\name_vowel\main.cpp|8|warning: multi-character character constant [-Wmultichar]|

E:\C++\name_vowel\VowelCount.h|8|error: field 'string' has incomplete type|

E:\C++\name_vowel\VowelCount.h|11|error: 'string' does not name a type|

E:\C++\name_vowel\main.cpp||In function 'int main()':|

E:\C++\name_vowel\main.cpp|8|error: no matching function for call to 'VowelCount::VowelCount(int)'|

E:\C++\name_vowel\main.cpp|8|note: candidates are:|

E:\C++\name_vowel\VowelCount.h|5|note: VowelCount::VowelCount()|

E:\C++\name_vowel\VowelCount.h|5|note:   candidate expects 0 arguments, 1 provided|

E:\C++\name_vowel\VowelCount.h|5|note: VowelCount::VowelCount(const VowelCount&)|

E:\C++\name_vowel\VowelCount.h|5|note:   no known conversion for argument 1 from 'int' to 'const VowelCount&'|

E:\C++\name_vowel\main.cpp|9|error: 'CountVowel' was not declared in this scope|

||=== Build failed: 4 error(s), 1 warning(s) (0 minute(s), 0 second(s)) ===|



i am finding it very difficult to work wit strings...plz help!!!


Post a Reply

Replies

Oldest  Newest  Rating
0 zahidul haque · April 2, 2015
make the following correction, it will work
1>  VowelCount naam("aaaa");   -> in this method you are expecting string but passing as a character. Character is considered to be constant.

2> In the main
cout<<naam.CountVowel()<<endl; -> CountVowel() is member of the class VowelCount. use object to call the class method. This is not your static method.

3> if(name.at(i)=='a'||name.at(i)=='e'||name.at(i)=='i'||name.at(i)=='o'||name.at(i)=='u')   -> here it was a typo mistake. At the end you put extra || :)

4> every where you have put ; for method defination. Remove extras ;

this will solve you issue.
0 Bishwa Nath · April 3, 2015
tnk u:D
  • 1

C++

107,111 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator