I'm not going to be the first to claim to be a good student, especially in high school, when I get bored. However, towards the end of high school and for most of collage, I've managed to find some tricks to keep me interested in my classes. For my CS classes I will take the assignments much further than the teacher ever intended. For example for my operating systems class, when the C assignments got boring, I started seeing how far the language could stretch (see below).
Code:
f(char*g){
if(*g){
putchar(*g);
f(++g);
}
}
g(){}
main(int a,char** v){
int o=&f-&g;
for(;a>0;a--,v++){
(g+o)(*v);
(g+o)(" ");
}
(g+o)("\n");
}
Doing this has helped tremendously when it comes to doing my hw. Just remember, if you're bored in your CS class, a good teacher won't complain if you go to them and tell them you need something more interesting. I went into my senior year of high school with a 3.0 gpa, I managed to get interested in my classes and got out with a 3.5.
btw: please never write serious code like that, I was purposefully attempting to obfuscate the language (which is why I will be very impressed if you can tell me what it does without compiling it).