Amazon.com Widgets Chapter 6 Quiz
Welcome, Guest. Please login or register.
Did you miss your activation email?
July 28, 2014, 05:21:12 AM
Home Help Search chat Login Register 
News: Read this please.The Great Kangaroo Escape Looking for reviews of the 4th ed on Amazon!   Twitter:  @skochan
                     

+ Official Forum for Programming in Objective-C (the iPhone Programming Language) - Stephen Kochan
|-+ Study Group
| |-+ Objective-C Quizzes
| | |-+ Chapter 6 - Making Decisions
| | | |-+ Chapter 6 Quiz
Pages: [1] Go Down
Print
Author Topic: Chapter 6 Quiz (Read 4973 times)
skochan
Administrator
Hero Member
*****
Posts: 3114







on: April 01, 2009, 06:48:02 AM

A 10-question quiz on Chapter 6.

Chapter 6 Quiz

Cheers,

Steve Kochan

Logged
macifone
Newbie
*
Posts: 14


Email




Reply #1 on: November 01, 2009, 02:38:34 PM

In this question:
The statement

if ( x < 10 && x > 50)
   y = 100;
else
   y = 50;

I put y would be either depending on the value of x.
Why is that wrong?
Logged
toby
Full Member
***
Posts: 104






Reply #2 on: November 01, 2009, 02:46:02 PM

Because no value can be less than 10 and greater than 50 at the same time, this condition demands that x is less than 10 and it is also greater than 50 in order to be true and because that is impossible it will always be false. So in this case y will always be set to 50. If the question was:

if ( x < 10 || x > 50)
   y = 100;
else
   y = 50;

then your answer would have been correct. Remember && demands that the condition each side of it both must evaluate to true for the overall expression to be true, || demands that one of the conditions on either side is true for the overall expression to be true.
Last Edit: November 01, 2009, 02:50:07 PM by toby Logged
xjames
Newbie
*
Posts: 26






Reply #3 on: September 03, 2011, 08:57:47 AM

Hi there. you have the following quiz question:

If x and y are integers, the statement

if ( x = 5 )
    y = 0;
else
   y = 1;
------------------------
with the options being 0, 1, or invalid

I think this if statement is invalid, cause you need == to make it an equality comparison, and not an assignment,
but the quiz marks it as "wrong answer".
Am I thinking about this wrong?

EDIT: Nevermind. Reading the other threads I understand the trickiness of the question Wink Another reminder to think like the computer executing the code would "think"

Also

I loved the question

    int x = 100, y;
   
    y = (x % 2) ? 50 : 0;

It reminded me to think hard about understanding the syntax before spending 10 minutes puzzling over "what's going on here" Smiley
Last Edit: September 03, 2011, 09:07:48 AM by xjames Logged
Pages: [1] Go Up
Print
Jump to:



Login with username, password and session length

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Entire forum contents (c) 2009 classroomM.com. All rights reserved.