My laptop is also a Compaq and has a dodgy jack socket, sometimes is the jack plug is making repeatedly intermittent contact it also just switches off.
Does it ever do it when just running off battery, mine doesn't.
Other thing that also did it on mine was a knackered memory card, luckily it had two fitted and so running it with one it was ok, running it with just the other would sometimes switch off. New memory card and it was fixed.
My desktop computer manages to do this when I access a specific file on an external USB drive. I have still to find any possible reason for this, nothing down USB should be able to do an immediate shutdown of the PC so I am guessing it is a driver problem. Annoyingly this is 100% predictable which should make fault finding easier but with no error log generated and the time to boot it up again has made me give up - one day etc.
In a time of universal deceit - telling the truth is a revolutionary act. George Orwell
When the debate is lost, slander becomes the tool of the loser. Socrates