It's a gradual process. While some people can naturally get up and B.S. about anything to anyone, this is not the usual case. Public speaking is something you can learn.
First, giving a completely extemporaneous speech is one of the hardest forms of public speaking. You really need to work up to that, and while this was something forced upon you for a grade (which only makes it feel worse), it's usually easier to avoid winding up in those situations until you've mastered other forms of public speaking.
Start out by learning to read from a script to your audience. Don't worry about things like eye contact and intonation, etc., just get past the point where you can stand up in front of a group and read something out loud without turning into a jittering pile of nerves and without mumbling your way through it. Focus on the paper and pronouncing every word loudly and clearly.
When you can do that, now move onto a speech that you write out, practice by yourself until you have it memorized, and just jot notes for yourself onto notecards to serve as reminders if you get nervous and forget the next line. First practice just saying the speech from memory and work on overcoming the nervousness that you'll forget the next line (it's usually this nervousness that leads to forgetting the next line, so the more you relax, the less likely you are to make a mistake). Once you can get through an entire speech that way, work on some of the other skills. Look up at the audience, try to make eye contact with a few people (don't worry about looking at everyone yet, just find a few people to look at...maybe a best friend who you know will give you a smile of reassurance), try to work on emphasizing important words by your tone. Work on your posture. Stand up straight, don't hunch your shoulders, and get your chin up off your chest. Doing all of this will also help you project your voice further and more clearly.
Then, try to give your speech without any notes. Still memorize it all, but don't rely on any notes. If you forget a line, stop and think about it, back up in your mind and see if it comes to you, or try to ad lib a bit rather than go back to notes.
The next step after that is to be completely familiar with a topic, rehearse it a lot, but don't memorize a script word for word. This will allow you to start becoming more natural in your speaking tone. As you work to improve at this stage, in addition to all the other things you've practiced, work on ridding yourself of filler words "um" and "ah" etc. This is when they show up at their worst, when you're not always 100% sure what word will come next. Practice silent pauses when you need to think of the next word to say.
Once you've gotten through all these steps, then you are ready to start handling topics you did not rehearse. You can start out by having people ask you questions about the topic you just gave a speech about. This way, you start out with a topic you're at least familiar with. Then, you can start having them throw random, general topics at you to talk about. Practice on things that you're likely to need this skill for, such as interview type questions. Remember, "I don't know" is an acceptable answer when getting asked questions like that. When starting out speaking, it's common to feel like you're supposed to know all the answers, and the pressure of trying to find an answer to something you really don't know can completely undo you. If you think you might know if you stopped to think for a bit, you can state that as well, "I'm not sure, but I'll think about it and get back to you," or "That's a tough question to answer right now; if we have time at the end, let's come back to it then."
Once you've gotten comfortable with all those situations, there are other things to focus on. For example, starting to really look at your audience and read them. You may be going to slowly for them and need to pick up the pace, or you may be going to rapidly and need to slow down for them to keep up. You may see a lot of puzzled looks and choose to spend a little more time clarifying a particular point before moving on.
As you can imagine, this is not a rapid process. You might be able to get a group of people together who all have concerns about speaking in public and take turns practicing together, using each other as your audience. There really is no substitute for practice in front of a real audience.