My Mac has weird lines when booting MacBook Pro, Late 2011 2.5Ghz. The Mac works perfectly fine, however, every so often, the Mac simply freezes and doesn't respond. Therefore I turn it off, and when turning it back on weird lines appear. 

The Mac loads up and then shuts down again as soon as the loading screen ends. We tried replacing the RAM because we recently had a RAM issue, but that did not fix anything. Has anyone had a similar problem?
I am suspecting that you have a GPU failure.

"Weird lines" while booting is indicative that there is a problem with the video.  Below are a couple samples of the weird lines similar to what I have seen in my travels.




However, the best way to test this out with with Apple Hardware Test (AHT).  Hold the D key while booting from a powered off state with the AC adapter connected.

It will run through a series of diagnostics - I am pretty certain that you will find you GPU is failing.  

Apple Has a Replacement Program for GPU issues.  If your GPU is in fact failing, Apple has a repair extension  program where they will repair, for free your Macbook Pro.  From the details you provided, but check with Apple to be certain.  The program runs until December 31, 2016.  See the link for details