10 Replies - 836 Views - Last Post: 17 December 2011 - 01:56 AM Rate Topic: -----

#1 lemonco   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-December 11

Questions I got wrong on my final.

Posted 16 December 2011 - 10:37 AM

Hey, I got a few questions wrong on my final. I can't really do anything about it at the moment, but I was wondering if someone could explain how I got them wrong so it could help me next semester and not keep me up at night.

1. One was about
int x, y = 2;
float z= 4.2;
x = y * z;

The value stored in x is..

I put 8.4 xP

2. A ______ expression is using greater-than, less-than, greater-than-or-equal-to,etc.
I put mathematical

3.
how many times "hello world" will print out
for ( int i = 0; i < 5; i++)
for ( int j = 0; j < 5; j++)
cout << "hello world" << endl;

4. mathematical operators in c/c++ are evaluated in a specific order, which is correct?
i put multiplication/division/mod, addition/subtraction, unary operators

help on any of these will be great! thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Questions I got wrong on my final.

#2 r.stiltskin   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2034
  • View blog
  • Posts: 5,436
  • Joined: 27-December 05

Re: Questions I got wrong on my final.

Posted 16 December 2011 - 10:43 AM

The teacher told you you were wrong but wouldn't tell you the correct answers?
Was This Post Helpful? 0
  • +
  • -

#3 lemonco   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-December 11

Re: Questions I got wrong on my final.

Posted 16 December 2011 - 10:45 AM

no, it was an electronic test via computer
Was This Post Helpful? 0
  • +
  • -

#4 r.stiltskin   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2034
  • View blog
  • Posts: 5,436
  • Joined: 27-December 05

Re: Questions I got wrong on my final.

Posted 16 December 2011 - 10:48 AM

For #1, you forgot that x is an int. Now, what do you think the answer is?

For #3, what do you think?

For #2 and #4, were these multiple choice questions? If so, what were the choices?
Was This Post Helpful? 0
  • +
  • -

#5 lemonco   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-December 11

Re: Questions I got wrong on my final.

Posted 16 December 2011 - 10:52 AM

View Postr.stiltskin, on 16 December 2011 - 10:48 AM, said:

For #1, you forgot that x is an int. Now, what do you think the answer is?

For #3, what do you think?

For #2 and #4, were these multiple choice questions? If so, what were the choices?


sorry, this is my first class in programming and it's an online class, so i can't explain it in complex terms so excuse my simple wording.

#1, x must be 2 because it's declared as an int

#2 i really don't remember the choices. our teacher gives us the one we got wrong but not the answer.

#3 i put 4

#4 it was those three (multi/div/mod, add/sub, unary operators) <- but i had to put them in order by which came first
Was This Post Helpful? 0
  • +
  • -

#6 sepp2k   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2756
  • View blog
  • Posts: 4,416
  • Joined: 21-June 11

Re: Questions I got wrong on my final.

Posted 16 December 2011 - 11:01 AM

#1 Why 2? That makes no sense at all.

#2 As far as I'm concerned x < y is a mathematical expression (though the term isn't really well defined), but so are x + y and other arithmetic expressions, which weren't mentioned. So I'm assuming the options also included a more specific term that would not also apply to x + y (like say: "comparisons" or "boolean expressions").

#3 First of all a for loop from 0 (inclusive) to 5 (exclusive) will execute 5 times, no 4. Second you need to notice that the two loops are nested. I.e. on each iteration of the outer loop the inner loop will execute 5 times.

#4 Do you think - 4 + 5 * 6 is equivalent to - (4 + (5 * 6)) or (-4) + (5*6)?
Was This Post Helpful? 0
  • +
  • -

#7 r.stiltskin   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2034
  • View blog
  • Posts: 5,436
  • Joined: 27-December 05

Re: Questions I got wrong on my final.

Posted 16 December 2011 - 11:05 AM

#1: When a floating point value is assigned to an int variable, it is truncated, which means the fractional part is discarded and the int is assigned the whole-number part. So 8.4 becomes 8 and that becomes the value of x.

#2 is a little ambiguous. It might be 'boolean' or 'comparison' or 'loop control'. Are any of those familiar? Depends on what choices were offered.

#3: How did you get 4? Describe how you think the loops work.

#4: google "c++ operator precedence"

This post has been edited by r.stiltskin: 16 December 2011 - 11:06 AM

Was This Post Helpful? 0
  • +
  • -

#8 jjl   User is offline

  • Engineer
  • member icon

Reputation: 1271
  • View blog
  • Posts: 4,998
  • Joined: 09-June 09

Re: Questions I got wrong on my final.

Posted 16 December 2011 - 11:25 AM

Quote

It might be 'boolean' or 'comparison' or 'loop control'

Those are a little ambiguous, since these are mathamatical relationships - not all of order - I would consider them relational operators.

This post has been edited by Loundy: 16 December 2011 - 11:36 AM

Was This Post Helpful? 0
  • +
  • -

#9 Martyr2   User is online

  • Programming Theoretician
  • member icon

Reputation: 5509
  • View blog
  • Posts: 14,498
  • Joined: 18-April 07

Re: Questions I got wrong on my final.

Posted 16 December 2011 - 11:41 AM

2) I think the word they wanted is "relational". While relational expressions are mathematical in nature, one could argue that relations are also a piece of philosophy as much as they are mathematical. What is the definition of value? How might value be determined? But the word they wanted was relational since those operators are called relational operators and are used to create relational expressions.

:)
Was This Post Helpful? 2
  • +
  • -

#10 Karel-Lodewijk   User is offline

  • D.I.C Addict
  • member icon

Reputation: 455
  • View blog
  • Posts: 864
  • Joined: 17-March 11

Re: Questions I got wrong on my final.

Posted 16 December 2011 - 12:59 PM

Most of them are presumably answered already but I'd say

1)8, you forgot the cast to int
2)in C++ they are referred to as boolean expressions
3)25
4)unary takes preference over the arithmetic ones
Was This Post Helpful? 0
  • +
  • -

#11 lemonco   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 16-December 11

Re: Questions I got wrong on my final.

Posted 17 December 2011 - 01:56 AM

Oh..I figured some of them out when I went back to my professor! I'm so sorry for wasting time. :( Thank you so much though! Really!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1