What is the difference between a gear, cog and a sprocket?

In some cases, I have seen these terms used interchangeably. Enlighten me as to the precise definition of each and what they are useful for.

Thanks!