Often times, when writing code, you are writing APIs or a set of objects / tools for yourself and other engineers to build upon. Public / Private / Protected are contracts between you and future programmers on how to interface with your code. Private variables cannot be touched (unless you expose methods to get/set them), Protected can be overwritten if you wish by child classes, and Public are the wild west.
Same with const correctness (let’s pretend const_cast doesn’t exist because, seriously, don’t use it). A member / method that is marked as const tells any future programmers that you may call that function without worrying it will modify the object in some way, where non-const methods say the opposite.
Can you write everything with only Public members? Sure. Is it good practice? Definitely not.