Let's explain it low level. You can have all of this in a single cpp file. But if you would do that, you would get a huge file filled with code and not that easy to read and understand. If you split that cpp in headers and .cpp files wouldn't it be more easy to manage?
Let's say you wrote few math functions and few sorting functions and you use it in your code. If you wanted to use the same functions in another project you have to go there and copy-paste it. But if you put these functions in a header, you can just simply get that .h/hpp file and use all the function. Project management, code reuse and a clean code policy are the most important factors. Among many others.
Thanks, yes I think I understand the use of .h and .cpp for code reause and maintainability...
But I am confused about the actual difference of a .lib and a .cpp file. Since if I make a .h and .cpp file, and I want to include it into another project, I can just add the .h and .cpp file to it (I don't need multiple files, all my projects can link to the same .h and .cpp file), but where does the .lib come into play during all of this?