To a certain extent, this comes down to style and personal preference.
Historically, from the days of “C”, header files are for declaring and “.c”, or now, “.cpp”, are for defining and implementing.
You might have more than one file so as to divide up the project in a way that makes it easier to keep track of what is going on. And, also, make it easier to find errors.
And finding errors is an important part of programming! Remember, until a program is “finished”, you will compile it a great number of times with errors. So, a large factor in the completion of any program is finding and fixing errors quickly. The multiple file approach helps with this by the “divide and conquer” strategy.
Can you put everything in one file? Yes. There are no C++ police to knock down the door.
But I urge you as you develop your programming talents to, at least, try the multiple file approach and see, if like most people, you find it easier to keep track of everything.
By the way, the “header only class” mentioned here is an even more succinct style, you may want to investigate. It eliminates the corresponding “.cpp” file, and makes code more readable IMHO for compact classes.