I searched from internet. They said have 2 ways to create sub-function file,
first way is : using header file which is easier to write.
second way is: using cpp file which will increase the compilation time.
But my lecturer say using header file to write sub-function is a wrong method.

So which is the correct way?

Your teacher is correct. You do not put executable code in header files (there are a few exceptions) because the code gets duplicated in each *.cpp file in which the header file is included. Lets say you have two *.cpp files, and each one of those includes the header file. The compiler won't complain when compiling those two *.cpp files, but the linker will produce duplicate declaration errors.

The simplest way to solve the problem is to put the implementation code in one of the *.cpp files, and put a function prototype in the header file.