I took my phone to the apple store when my phone kept turning off and lines were appearing and they replaced it, if it is in the warranty they will check to see if there is no preventable damage caused by the owner of the phone like water damage if there is no indication of this they replace it straight away in the store.
The exact same thing has been happening to my iPhone 5. I will be on any app or just unlocking my phone and it will just turn off and on sometimes 10 times in a row and lines will appear in black and white or red and green. I took my case of and the phone seemed hotter then it should have been and so I took my plastic case of and left it for 5 minutes and it seemed to have cooled down and it has not shut down for a week after taking the case off and not putting it back on. I don't know if it was overheating or if it has something to do with the battery.