I don't understand functions very well and my professor hasn't been any help. My code works perfectly for the purpose and logic. However, I don't have the correct function signature that the professor wants.
If someone could give me an explanation on how to add the correct function signature to my code that would help a lot.
The function looks like this:
class CIS14 {
public:
int countLastWordLength(const string str);
};
/**
* Assignment#5.1
* DUE: 3/6/16
* NAME: <Joshua Cisneros>
* PURPOSE: You are an awesome engineer in a company called "Awesomeness Software, Inc".
* They make word processing software. The current software in development requires that it
* produces character count on a given word as input.
* In particular, it needs to count the length of the last word in a sentence
* for some formatting feature in the future.
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <sstream>
usingnamespace std;
/**
* PURPOSE: displays number of char in last word only
* PARAMETERS:
* string in and lastword
* I am also using stringstream 'ss'
* RETURN VALUES:
* const string str
*/
int main(int argc, char *argv[]) {
string in, lastWord;
stringstream ss;
while (true) {
cout << "Enter your string: ";
getline(cin, in);
reverse(in.begin(), in.end());
ss.clear(); ss.str(in);
ss >> lastWord;
cout << lastWord.size() << endl << endl;
}
return 0;
}
class CIS14
{
public:
int countLastWordLength (const string str);
};
int CIS14::countLastWordLength (const string str)
{
//TODO place your code here to count the length of the last word and return the length
}
In your main function you create an obj of the class CIS14 and call the method.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int main (int argc, char *argv[])
{
string in;
while (true)
{
cout << "Enter your string: ";
getline (cin, in);
CIS14 obj;
cout << "Length of last word: " << obj.countLastWordLength (in);
}
return 0;
}