What are the primary functions of an operating system in managing computer hardware and software interactions?