Hello all,
OK, here's the deal. I have this assignment where I am trying to implement a class method. In it I am trying to calculate the total of uppercase letters in a string. My problem is that I can't grasp how to pass the string to the accessor function. At the moment my program will not even compile giving me this error;
Here is my code as it stands now;Code:71 C:\C++Course\A1-1.cpp invalid conversion from `char*' to `int'
Now I've been reading a lot but somehow can't find exactly what I'm looking for. My instructor suggested that I declare a char* input. Initialize it with say input= new char[25]; but I am not sure exactly how to go about it and my instructor won't be available for several more days and I would really like to go forward with this. Can someone point me to a link or explain how to proceed with a simple example?Code:#include <iostream> #include <cctype> // Not sure if this is really needed here #include <string> using namespace std; class Word // Declaring the class object { public: // public section int GetNumberOfUppercase(); // accessor function void SetNumberOfUppercase(int UppercTotal); // accessor function private: // begin private section int UppercaseTotal; // member variable }; //--------------------------------------------------- // GetNumberOfUppercase, public accessor function // return number of uppercase letters //--------------------------------------------------- int Word::GetNumberOfUppercase() { return UppercaseTotal; } //-------------------------------------------------- // Definition of SetNumberOfUppercase, public // accessor function // return sets UppercaseTotal member //-------------------------------------------------- void Word::SetNumberOfUppercase(int UppercTotal) { char WordArray[25]; int i,UpperTotal; int size = strlen(WordArray); for(int i=0; i<size; i++) { if (isupper(WordArray[i])) UpperTotal++; } UppercaseTotal = UpperTotal; } //---------------------------- // begin main processing //---------------------------- int main() { char line[25]; //---------------------------------------------------------------------- // Want to pass this value to SetNumberOfUppercase ????? // ----------------------------------------------------------------------- cout<<"Enter a string 25 Char. long Max : "; cin >> line; Word Input; // Compile error here Input.SetNumberOfUppercase(line); cout<< "The word you entered " << line << " has " << endl; cout<< Input.GetNumberOfUppercase() << " Uppercase Letters" << endl; // Pause to look at the results system("pause"); return 0; } // end main
Thanks in advance,
.



LinkBack URL
About LinkBacks


