[CSI] Header File / Functions
Mikhail Nesterenko
mikhail at cs.kent.edu
Wed Mar 21 14:27:37 EDT 2018
> I had a question regarding the Battleship program. If our function
> prototypes are in a header file, is it stylisticly okay to have int
> main first, than the function definitions? We may have gone over
> this in CS1A, but I wanted to be sure.
Not only is it okay, but it is the preferred style. Your
battleship.cpp and game.cpp should look a follows:
// -----------battleship.cpp------------------
#include "battleship.h" // prototypes all functions to be defined later
...
// function definitions in the order of importance, implementation or,
// preferred, grouped by purpose as in the header file
// first function definition
void initialize(Ship ships[]){
....
}
// ----------------game.cpp-------------------
#include "game.h" // prototypes all functions to be invoked later
// first defined function is main()
int main(){
...
}
Thanks,
--
Mikhail
More information about the cs13001
mailing list