the task is to use a class |
A ‘struct’ is a class where members are public by default. In JLBorges’s code you could just turn the word ‘struct’ into ‘class’ and than add a ‘public:’ as first statement.
...and the functions GetCharacterCount(), GetSpaceCount(), GetLineCount() |
Just add them. Move “analyse()” inside the class, tweak it, and define those new three functions. They just need to return “num_chars”, “num_spaces” and “num_new_lines”.
If you decided to stuck to your code, have a look at it: you’ve declared a class, but you hardly use it.
If you want to use it, there should be at least three functions which increment number-of-characters, number-of-spaces and number-of-lines.
Ex.
void increaseCharCount() { ++number_of_characters; }
To invoke them, you’d need an instance of the class
FileAnalyzer fa;
to be used more or less this way:
fa.increaseCharCount();
Anyway, that could be a good starting point, but it’s basic design.
If you call your class “FileAnalyzer”, well, it is supposed to be the one which analyse the file, isn’t it? So it should carry out all the hard tasks (I mean, open the file, get through, count the characters...), while main() should do nearly nothing, apart from ‘prompting’ FileAnalyzer.
In case you’re stuck, ask again.
Happy coding!