PDA

View Full Version : Wow.. my teacher screwed me up on my exam..



ownaginatious
01-31-2008, 07:41 PM
I just recently finished by grade 12 first semester exams (w00t!!), but I got screwed up on my computer science exam :(. The exam was a written exam all about Java, and there were "output" problems we had to solve. Basically an output problem is a program written on a sheet of paper, and you gotta go through manually and figure out what the output is. The output is purposely nonsensical. So anyway, there was this huge one that was worth 10% of the exam, and it had a weird line that was "x += ++x;". Since I had never done something like that before in Java, I asked my teacher, and he told me what it does.

He said that it adds 1 to x, and then adds it to the new x value of (x +1), meaning that if x equals 1 before hitting that line, it would equal 4 after going through it. So I solved it that way, and there were about 20 lines of output.

Later after the exam, I asked other people what they got as the output, and they got output that was completely different from mine for the question. It turns out that "x += ++x;" means that x is incremented by 1 and then added to the ORIGINAL value of x. Therefore hitting that line with x equaling 1, you would get 3 out of it... not 4.

So I went and asked my teacher about it, and he was like "Really? I didn't know that.... Don't worry about it though, your mark won't drop by much."

Now I'm kinda pissed, cause I thought the line did what it actually does before asking my teacher, and would have gotten the output correct if I had never asked him. I know I really shouldn't have been asking about stuff during the exam... but why the hell would the creators of Java allow for the increment operator to be mixed with a other math expressions!?!! Worst of all, why is my teacher giving us a question that he doesn't even know how to properly solve...

But that's only almost as bad as what happened on my Chem. Exam. The the last questions was photocopied upside down and all faded out on the back of the last page - nearly unreadable. I asked my teacher about it, and she said "Don't worry about it", and I assumed that meant "Just skip that question". When I asked everyone about it after the exam, they said they did it. So I asked her if what she meant by "Don't worry about it", and she meant don't worry about the fact that it's upside down. Why the hell would I be worrying about that.... That's 6% lost of an already difficult exam right there.

This is why I hate exams. It's almost like they are designed to screw you over.

Just had to get that off my chest :p.

.Maleficus.
01-31-2008, 08:14 PM
Well, the "x += ++x" isn't Sun's fault. You can do that in C++ too (just tried it). It doesn't work the same as Java, but Java isn't the only language that can do that.

int x = 1;

for(int i = 1; i < 10; i++){
x += ++x;
std::cout << x;
cout << "\n";
}
gives the output 4, 10, 22, 46, 94, 190, 382, 766, 1534 for x = 1. It's like what your teacher told you (for x = 1, the output is 4, and so on). That's C++.

int x = 1;

for(int i = 1; i < 10; i++){
x += ++x;
System.out.println(x);
}
gives the output 3, 7, 15, 31, 63, 127, 255, 511, 1023, and that's Java. Maybe he got confused between the two?

It's too bad that his error cost you points though. Same with Chemistry. Miscommunication is a real pain sometimes. Especially if it causes you a grade.

ownaginatious
01-31-2008, 08:24 PM
I figured that "x+= ++x" was probably part of C# and C++ to. It really would make more sense to work the way as it does in C since the variable is pointing to the same memory location...

It seems like a weird feature in any programming language considering the fact that there aren't really instances where it would be useful other than to confuse who ever is trying to work with it.

.Maleficus.
01-31-2008, 09:16 PM
I figured that "x+= ++x" was probably part of C# and C++ to. It really would make more sense to work the way as it does in C since the variable is pointing to the same memory location...

It seems like a weird feature in any programming language considering the fact that there aren't really instances where it would be useful other than to confuse who ever is trying to work with it.
I guess, but the Java version is easier to see. Notice a pattern? Seems to me like exponential growth has a big part in it's workings... They all seem to be 2^x - 1 (x being a number, not the variable). Like you said, practical application? I don't see one. Other than number crunching and stress testing that is.

OT
I really need to get into a Java or C++ class. Head First Java was a good beginning book, but man, you can't teach yourself some of the stranger concepts (like this). No worries though, I'm talking to my school counselor to see if I can take a class at our tech university next year :D. Let's hope!
/OT

Killa_Ape
01-31-2008, 09:31 PM
Next time you have that issue with can't read the page bring the exam up and ask for either a new copy or a new page or something but make sure the teacher sees it and you state you can't do this question. Just a bad miscommunication :( next time you'll be good to go after this incident, you should also ask your teacher if she could do something about it due to the miscommunication as well as your code instructor they might be able to help you out.

mtekk
01-31-2008, 09:48 PM
Well, the "x += ++x" isn't Sun's fault. You can do that in C++ too (just tried it). It doesn't work the same as Java, but Java isn't the only language that can do that.

int x = 1;

for(int i = 1; i < 10; i++){
x += ++x;
std::cout << x;
cout << "\n";
}
gives the output 4, 10, 22, 46, 94, 190, 382, 766, 1534 for x = 1. It's like what your teacher told you (for x = 1, the output is 4, and so on). That's C++.

int x = 1;

for(int i = 1; i < 10; i++){
x += ++x;
System.out.println(x);
}
gives the output 3, 7, 15, 31, 63, 127, 255, 511, 1023, and that's Java. Maybe he got confused between the two?


That's just weird, maybe it's due to the definition of ++x as apposed to x++ in JAVA. In JAVA, it looks like the preincrement will for some reason not actually affect the stored value of x, instead a copy is made, so that when x += ++x; is done you are really getting
y = x + 1;
x += y; instead of the expected
x++;
x += x;. I can see instances that this type of implementation for the preincrement would be useful, but as a C/C++ guy I don't see it as correct.

.Maleficus.
01-31-2008, 10:37 PM
Actually... I just tested a little more. There is no difference between x++ and ++x. So it actually makes perfect sense the way it works in Java. You start with x = 1. You reach the first ++x. x now equals 2. You go back to +=, and x = 3. Then, in the next loop, x starts at 3, ++x makes it 4, and the += adds the initial 3 to it, thus making it 7. It's just a weird order of operations.

So yes, you were right. It acts as though there are 2 variables, storing the initial x, making the ++x change, and adding the initial value (y as you called it) back to x.

I take it you mean C++ reads it as x++; x += x? That would make sense for the values I got... x = 1, x++ makes it 2, x += x makes it 4. Thanks for that, I had no idea how it was computing those values!


I guess it makes sense whichever way you look at it. It can work in both Java and C++, but I guess if you're helping someone and only know one of the languages, don't even bother! It just causes major calculation errors between the two.

crenn
01-31-2008, 11:05 PM
x++ increments it after it's used.
++x increments it before it's used.

mtekk
01-31-2008, 11:14 PM
Yeah, I've never seen ++x and x++ do different things, though I guess if you ask a CS major they'd tell you there's a difference. I always use x++. I really don't see where the code x += x++; would be practical unless you wanted it to do what C/C++ does (or using something like x += x + 2; or x *=2; x += 2; which should be equivalent), otherwise it's much clearer to do x += x + 1 or x = x*2 + 1 or x *= 2; x++;. Job security through obscurity is to blame for this I guess.

Either way, both C/C++ and JAVA beat having to code in assembly and/or hand assembling stuff (especially for a PIC18f452 :banghead:).

.Maleficus.
01-31-2008, 11:18 PM
x++ increments it after it's used.
++x increments it before it's used.
Damn... and another loop to this problem! You're right crenn, x += ++x went 3, 7, 15... and x += x++ went 2, 4, 8... I only ran it with x++ and ++x, not x +=, so that's the deciding piece.

ownaginatious
01-31-2008, 11:19 PM
x++ and ++x are different in Java. If you are using it on it's own like in:
x++; or ++x; then they are the same.

If you do something like:

x = 1;
a= x++;

System.out.println(x + " " + a);

Then the output is 2 1.

If it had been ++x, the output would have been
2 2.

For some reason x += x++; will result in two, as if you never added the '++' to the end. Pretty stupid operator if you ask me. So much complication just to summarize 'x += 1'...

In regards to that thing about bringing my chemistry exam up and asking for a new page, everyone's last question was upside down. My teacher is pretty stupid for looking so unprofessional like that. The exam was so unfair and full of grammar and spelling mistakes, because a lot of the multiple choice questions were recycled from grade 13 exams and tests from the 1970's (The province I live in got rid of grade 13 years ago). So many of them weren't related to todays curriculum. It's kinds of funny - all the worksheets we get are typewriter written and have dates of 1970 something, and are full of stupid mistakes. You think over the course of 30 years, someone would have taken the initiative to make digital copies... it would take like 2 seconds with that Microsoft OCR software...

It sucks that for every teacher that actually cares, there are 20 more that don't. My teacher had like 4 months to make that stupid exam...

Greco101
01-31-2008, 11:27 PM
Teachers like working over their students on finals. Or at least it seems like it haha.

My A+ professor had a exact schedule of:

Start of week: Monday 12:05am
End of week: Sunday 11:55pm:

throughout 15 weeks... everything followed this schedule. miderterms, quizzes, "labs" etc... on the last week, he decided to cut it to Monday 12:05am - Wednesday at noon (I believe was the time...mid-day, I know that.)

I took the whole week, like anyone would to study for the final since I didn't see any hurry. Sunday afternoon came and I went to take the test and it was no longer there..... So I ended up getting a 77% instead of a 97% in the class. :down:

mtekk
01-31-2008, 11:32 PM
It sucks that for every teacher that actually cares, there are 20 more that don't. My teacher had like 4 months to make that stupid exam...

That seems to happen, and is why I took nearly all AP, accelerated, and Honors classes in High School since the teachers for those classes actually were enthusiastic about what they were teaching. In College you can do something about professors that are not good, that's what those end of the semester professor/class review forms are for :devious:

Greco101
01-31-2008, 11:40 PM
In College you can do something about professors that are not good, that's what those end of the semester professor/class review forms are for :devious:

I had to take a life skills class and the teacher liked to base her lessons on "I Love Lucy..."

So we had to watch these films to talk about how problems could have been solved. The class was ridiculous to begin with but the people in it were even worse. When you have an entire class of slackers, one persons negative review wont make much of an effect :(

ownaginatious
02-01-2008, 12:22 AM
That seems to happen, and is why I took nearly all AP, accelerated, and Honors classes in High School since the teachers for those classes actually were enthusiastic about what they were teaching. In College you can do something about professors that are not good, that's what those end of the semester professor/class review forms are for :devious:

My school doesn't offer AP classes... It's deceivingly portrayed as a technology school and in the pamphlets and stuff for new students they talk on and on about all the cool stuff we have like a "3D-Printer" and the "butterfly garden". You're only allowed to use that printer if you're willing to give up an arm, a leg and your soul to pay for it's use. The "butterfly garden" is basically a tarp lying in the rain full of weeds and crap and a dead seagull.

For some reason all the money the school gets is thrown into new dells. It's kinda weird because in the nearly 4 years I've been at this school, they have replaced the computers at least twice :?. But it doesn't really make much of a difference considering that they are running 2000....

I'm sure university will be much nicer :D

xRyokenx
02-01-2008, 12:45 AM
At least they're not throwing it all into a losing football team that's only there for the fanatical students to "fanaticize" about and make everyone else's lives miserable and it's also there for the guys that want into college just to play football... meh.

High school is BS... just do the best you can and get into a good college.

crenn
02-01-2008, 05:55 AM
http://i3.photobucket.com/albums/y81/crenn/school.gif

luciusad2004
02-01-2008, 11:17 AM
*picture*

LOL, thats great. Nice find.