Programming is frustrating. That's a big energy drain. Some tips.
Don't rant, throw things, or otherwise "let off steam." You'll feel good for a few minutes, but it makes things worse in the long run. Really. The research is in.
Do have reasonable expectations. Your code will not work the first time. My code doesn't work the first time, and I've been programming for decades. I don't expect it to work, so it doesn't bother me when it doesn't.
Don't leave assignments to the last minute. OK, everyone tells you that, but listen this time. Programming takes longer than you think. Something always goes wrong. If you have no time to spare, you'll start panicking. Best not to be in that situation to begin with.
Do learn how to figure out why a program isn't working. Staring at code won't help you fix it. Using the debugger will. The debugger is your friend. Follow it on Facebook and Twitter. Like it, poke it. Give it compliments, like "You must work out!" Send it flowers on St. Debugger's Day. You need the debugger in your life.
Do get help when you're stuck. Asking for help is Really Hard for some people. (I'm one of them.) Remember, it's your instructor's job to help. Your friends can help, too. Meet for coffee every Tuesday and Thursday afternoon. You can help them, they can help you.
Do remember your accomplishments. Yes, that assignment was hard, but you did it. If you did that one, you can do the next one, too. Go, you!
Do take a break. If you're very frustrated, do something else for an hour. Not just a few minutes. Give your brain time to flush the I'm-as-frustrated-as-a-monkey-who-sees-a-banana-but-can't-get-to-it chemicals. Unfortunately, exercise is a good thing to do. I say unfortunately, because I hate exercise. My friend Mark says he likes it. He's delusional. He should be on serious medication.