[cs13001] I opened a sample midterm exam on the course's webpage

Mikhail Nesterenko mikhail at cs.kent.edu
Tue Oct 7 22:52:09 EDT 2014


> 
> My lab instructor showed me that I could put include directives in my
> header file.  I'm working on the lottery lab from the Monday class, and I'm
> invoking rand() in the draw function but it keeps saying it's undefined
> unless I put #include <cstdlib>, or #include "lotteryFuncs.h" in the
> programmer defined functions file.
> 
> A.  Is it OK to put the directives in the functions file like this?
> B.  Is it OK to have the header file directive inside the programmer
> defined functions file?  It feels like I'm guilty of multiple inclusion
> (#include "lotteryFuncs.h" in two places) but I do have protection from
> multiple inclusion in my header file.

You have to include cstdlib to use rand(). You can

* put the include directive in the source file or 

* centralize such includes in your own header file and include this
  header file in your source file instead.

Both approaches are perfectly correct. They are used in programming
practice often. Which one to use is a mater of style. I personally do
not like to put standard include directives in my header files unless
I have to.

Thanks,
--
Mikhail


More information about the cs13001 mailing list