If…Else Assessment By: Yinyu Zhou, Kyle Toler, and Ben Howard.

Post on 13-Dec-2015

216 views 0 download

Tags:

Transcript of If…Else Assessment By: Yinyu Zhou, Kyle Toler, and Ben Howard.

If…Else Assessment

By: Yinyu Zhou, Kyle

Toler, and Ben Howard

Assessment

• 1. What does an if-else statement do?– A. It threatens the computer.– B. It tells the program to choose and execute a

fragment of code.– C. It tells the program what to do without input

from user.– D. It terminates the program.

Assessment

• The correct answer is B. The if-else statement tells the program to choose and execute one or another fragments of code depending on the value of some variable or expressions.

Assessment

• 2. What is conditional branching?– A. It creates a never-ending loop.– B. It branch the program to make more

possibilities in a function.– C. It is when the program jumps to another part

of the program when a condition is met.– D. It hacks into the Legislative branch.

Assessment

• The correct answer is D. No actually we lied – its C. It is when when a program jumps to a different part of a program base on a certain condition being met.

Assessment

• 3. When is the else block executed?– A. When the program starts.– B. When the user is feeling hungry.– C. When it gets there in the program– D. When the if block is false.

Assessment

• The correct answer is D. The else is block executed if the if block is false.

Assessment • 4. What is wrong with this program?

#include <iostream.h>

#include <math.h>

int main()

{

double radius;

//get user input

cout<<"Please enter the radius : ";

cin>>radius;

//act on user input

If radius < 0.0;

cout<<"Cannot have a negative radius"<<endl;

else

cout<<"The area of the circle is "<<3.1416 * pow(radius,2)<<endl;

return 0;

}

Assessment

• A. Everything is wrong.

• B. The variables aren’t correctly declared.

• C. If radius < 0.0; is wrong.

• D. Everything is right.

Assessment

• The correct answer is C. It should be if(radius < 0.0). There should be no semicolons after the parentheses and you need the parentheses.

Assessment

• 5. What is the final value of A in the following sequence of statements?

Assessment

A : = 5;

B : = 6;

if A > B then

A : = 7;

else

A : = A – 2;

end if;

Assessment

• A. 3

• B. 5

• C. 7

• D. Error

Assessment

• The correct answer is A…. 3.

Assessment

• 6. Every if statement must be paired with an else.

A. True

B. False

C. Maybe

Assessment

• The answer is B false

Assessment

• 7. Nested if statements are if statements with another if statements inside the condition.

A. True

B. False

C. Maybe

Assessment

• The answer is B which is false.

Assessment

• 8. What is the value of n after the following C++ code segment is executed?

int n = 2;

if (n) n = 0;

else n = 1;

Assessment

• The answer is 0

Assessment

• 9. What is the value of n after the following C++ code segment is executed?

int n = 1;

if (n) n = 0;

Assessment

• The answer is 0

Assessment

• 10. Write a complete C++ program that asks the user for the number of watts in a light bulb.  The program should then use a nested if-else if statement (if-else if chain) statement that assigns to the variable lumens the expected brightness of the light bulb whose wattage has been stored in variable watts.  The following table gives the brightness for standard light bulbs:

• Watts            Brightness (in Lumens)   25                     215   60                     880   75                    1000  100                   1675

Assessment

• Bonus question- What is Mr. Shaw’s favorite Simpsons episode?– A. The first Tree House of Horror episode.– B. When Mr. Burns adopted Bart Simpson.– C. When Lisa turned anorexic.– D. When George Bush moved next door.– E. All of the above.

Assessment

• The correct answer is D. It is the episode where George Bush moves next door.

Assessment

• Minus 0 = 125% You actually paid attention…. GEEK!

• Minus 1 = 75%

• Minus 2 = 50%

• Minus 3 = 25%

• Minus 4 = 0% Go back and read the PowerPoint again!