A computer shutting down or rebooting can be caused by a few different things. The 3 most common are a power supply going bad, motherboard going bad or the computer overheating. If it’s just shutting down then it may be a case of it over heating. You can go into the BIOS and see if you have anything set to shut off the computer at a certain temperature. This setting is to prevent the computer from being damaged from overheating. You can also let it run in the BIOS and watch the displayed temperature and see if it keeps rising.
The second is when your power supply is going bad. The power supply provides power to all of your hardware components. If it is going bad then it can just shut off as if you unplugged the computer. They are fairly easy and cheap to replace. If you have a name brand computer like a Dell it may have a special non standard power supply. Otherwise they are about $60 and will take about 20 minutes to replace if you are used to replacing components inside the computer.
The worst case scenario and unfortunately the most common is a failing motherboard. This will cause random shutdowns, reboots and Windows errors. There is no real method to check the motherboard at home and if it’s bad then it’s the hardest part to replace since everything else is connected to it. If you don't get the same type then you will have to reinstall all the motherboard drivers to get Windows to recognize the new hardware. Or if you don't need to save anything you can do a clean installation of Windows or a restore from your recovery CD. Getting a new motherboard may also require you to get a new processor and RAM to match the type of motherboard if your original motherboard was an outdated model.
You can also look at your Windows Event Viewer to see if it tells you any issues that were happening around the time of the shutdown.