I did the challenge of this lecture much different, is it okay?

When asked to do the challenge for this lecture I made it work, but did it differently.

I would like to know if the way I did it is ok and if not, why?

In the FBullCowGame.h I declared a new function called

void PrintGameSummary ();

Then in the CPP I defined it as follows:

void FBullCowGame::PrintGameSummary()
{
if (bIsGameWon) {
std::cout << “You WON!!!\n”;
}
else
{
std::cout << “You lose :((\n”;
}
return;
}

Because I did this, I also did a #include iostream within the CPP.

then in main.cpp I just added the following to the bottom of PlayGame

// TODO summarize game
BCgame.PrintGameSummary();
return;

In coding the path to ideal code is like this

It Works -> Lets make it more readable -> lets do some more tests on it …

As a beginner for now your goal is to make the code work and follow the naming conventions that Ben teaches.

Later when you become more confident you will learn alternative ways of testing your code and making it easier to extend and modify.

Your code looks ok, you may want to remove that TODO comment since its no longer relevant.

Ok, so theoretically I could deligate all of the functions in my main.cpp over to the FBullCowGame class and have a clean main.cpp file if I wanted to? Further, is this terrible practice??

I think the idea here (and I’m kinda new at all this OOP muck too :slight_smile: ) is the opposite - to have a clean class that can slot itself into different main()s without having to really know much about it other than the header file.

So, while whatever you can get running is a win :wink: the Class thing is winninger :smiley:

Thanks for posting this Bradon. I did this challenge the same way you did as well, and wondered if there was a preferred method. Very interesting to read the replies from the other posters.

Cheers and thanks.

Privacy & Terms