Using Other People's Code
One of the things that comes up in any CS class is the use of code off the Internets in coursework. Here's my policy, which is mine — other instructors may differ. Here also are some guidelines to make your use of other people's code better.
You may use any code that you find on the Internet that meets the following conditions. That's not everything, but it's a lot.
The author must have legally and ethically allowed you to use the code.
Legally: Under international copyright law, someone who writes code owns it. You can't do anything with it (except maybe read it, if it has been published) unless they give you permission.
Permission comes as a license: the author must say that you can use the code. A license may have conditions that you must meet.
Sometimes the license is implicit: for example, posts to StackOverflow are covered by a blanket license statement from StackOverflow that the poster agrees to by posting. But you have to have a license.
Ethically: If it is clear that the author would not want you to use the code, you must not use it even if they somehow accidentally gave you a license. Your use of the code should be in a way that treats the author fairly: for example, critique of the code should be polite and honest.
You must attribute the code. That is, you must say what you got and where you got it from, in a way that allows me and others to find it later.
Usually the right way to attribute someone else's code is to put a comment in your code with the URL you retrieved it from. If the URL is potentially going to change or you got the code from somewhere else, the comment needs more detail.
You must understand the code. You shouldn't be using code unless you could write something similar yourself once you have understood what it is doing. This is extra-important for StackOverflow posts, which are usually a useful fact surrounded in terrible code with bugs and bad style.
In general it is better use of your time to look at other people's code, understand it, and write your own code using your new understanding. You must still put in attribution so that other people can find your inspiration.
If you turn in something that is mostly someone else's code, but is attributed, you will not be penalized. But you won't get many points for it, either. To get a good score you should have written most of your code yourself.
Hopefully this is clear. Have fun with the Internets!