Putting your entire program in one source file would make it very unorganized and would make compile time very long.
Putting a class in a header file is a very simple way to organize so that any source file that needs to use a certain class can just #include its header.