• Home
  • Textbooks
  • Microsoft Visual C# 2017: An Introduction to Object-Oriented Programming
  • Making Decisions

Microsoft Visual C# 2017: An Introduction to Object-Oriented Programming

Joyce Farrell

Chapter 4

Making Decisions - all with Video Answers

Educators


Chapter Questions

Problem 1

What is the output of the following code segment?
```
int a = a, b = b;
if(a == b)
Write("X");
WriteLine("Y");
```
a. $\mathrm{X}$
c. $\mathrm{XY}$
b. $\mathrm{Y}$
d. nothing

Check back soon!

Problem 2

What is the output of the following code segment?
```
int a = a, b = ;
if(a<b)
{
Write("Y");
WriteLine("Z");
}
```
a. $\mathrm{Y}$
c. $Y Z$
b. Z
d. nothing

Check back soon!

Problem 3

What is the output of the following code segment?
```
int a = 3, b = <;
if(a>b)
Write("Up");
else
WriteLine("Down");
```
a. Up
c. UpDown
b. Down
d. nothing

Check back soon!
01:19

Problem 4

If the following code segment compiles correctly, what do you know about the variable $x$ ? if(x) WriteLine("OK");
a. $\mathrm{x}$ is an integer variable.
c. $x$ is greater than 0 .
b. $\mathrm{x}$ is a Boolean variable.
d. none of these

Suman Saurav Thakur
Suman Saurav Thakur
Numerade Educator

Problem 5

What is the output of the following code segment?
```
int c = 6, d = 12;
if(c > d);
Write("Green");
WriteLine("Ye11ow");
```
a. Green
c. GreenYellow
b. Yellow
d. nothing

Check back soon!

Problem 6

What is the output of the following code segment?
```
int c = 6, d = 12;
if(c<d)
if(c > 8)
Write("B7ue");
e7se
Write("Red");
e1se
Write("Green");
```
a. Blue
c. Green
b. Red
d. nothing

Check back soon!
01:49

Problem 7

What is the output of the following code segment?
```
int e = 5, f = 10;
if(e<f&& f f < < f o />
Write("Red");
e1se
Write("Orange");
```
a. Red
c. RedOrange
b. Orange
d. nothing

Ernest Castorena
Ernest Castorena
Numerade Educator
01:49

Problem 8

What is the output of the following code segment?
```
int e = 5, f = 10;
if(e< f || f<0)
Write("Purp1e");
e7se
Write("Go7d");
```
a. Purple
c. PurpleGold
b. Gold
d. nothing

Ernest Castorena
Ernest Castorena
Numerade Educator
02:11

Problem 9

Which of the following expressions is equivalent to the following code segment?
```
if( g<k)
Write("Brown");
```
a. if $(g>h \& \& k<k)$ Write("Brown");
b. if $(g>h \& \&<k)$ Write("Brown");
c. if $(g>\mathrm{h} \| \mathrm{g}<\mathrm{k})$ Write("Brown");
d. two of these

Ernest Castorena
Ernest Castorena
Numerade Educator
02:11

Problem 10

Which of the following expressions assigns true to a Boolean variable named isIDValid when idNumber is both greater than 1000 and less than or equal to 9999 , or else is equal to 123456 ?
a. isIDValid $=$ (idNumber $>1000 \& \&$ idNumber $<=9999 \& \&$
idNumber $==123456$ )
b. isIDValid = (idNumber $>1000$ \&\& idNumber <= 9999 ||
idNumber $==123456)$
c. isIDValid = ((idNumber $>1000$ \& idNumber <= 9999) ||
idNumber $==123456$ )
d. two of these

Ernest Castorena
Ernest Castorena
Numerade Educator
00:47

Problem 11

Which of the following expressions is equivalent to a \| b \&\& $\mathrm{c} \| \mathrm{d}$ ?
a. a \&\& b $\| \mid c \& \& d$
c. a $\|$ (b $\& \&$ c) $\| d$
b. (a
b) $\& \&(c||$
d)
d. two of these

Victor Salazar
Victor Salazar
Numerade Educator
01:22

Problem 12

How many case labels would a swi tch statement require to be equivalent to the following if statement?
```
WriteLine("one");
else
WriteLine("two");
```
a. zero
c. two
b. one
d. impossible to tell

Ernest Castorena
Ernest Castorena
Numerade Educator
01:22

Problem 13

In C\#, falling through a switch case is most often prevented by using the __________statement.
a. break
c. case
b. default
d. end

Ernest Castorena
Ernest Castorena
Numerade Educator
01:22

Problem 14

If the test expression in a switch does not match any of the case values, and there is no defau1t value, then $\qquad$
a. a compiler error occurs
b. a runtime error occurs
c. the program continues with the next executable statement
d. the expression is incremented and the case values are tested again

Ernest Castorena
Ernest Castorena
Numerade Educator
03:34

Problem 15

Which of the following is equivalent to the following statement?
$$
\begin{aligned}
\text { if }(m & =0) \\
d & =0 ; \\
\text { e1se } & \\
d & =1 ;
\end{aligned}
$$
a. $d=(m=0): d=0, d=1$;
b. $m$ ? $(d=0) ;(d=1)$;
c. $m=0 ; d=0 ; d=1$ ?
d. $d=(m==0) ? 0: 1$;

Ernest Castorena
Ernest Castorena
Numerade Educator
03:17

Problem 16

Which of the following C\# expressions is equivalent to $\mathrm{a}<\mathrm{b}$ \&\& $\mathrm{b}<\mathrm{c}$ ?
a. $c>b>a$
c. $!(b<=a)$ \& $b<c$
b. $\mathrm{a}<\mathrm{b} \& \& \mathrm{c}>=\mathrm{b}$
d. two of these

Samriddhi Singh
Samriddhi Singh
Numerade Educator
03:34

Problem 17

Which of the following C\# expressions means, "If itemNumber is not 8 or 9, add TAX to price"?
a. if(itemNumber $!=8$ || itemNumber $!=9$ )
price $=$ price + TAX;
b. if(itemNumber $I=8$ \&\& itemNumber $I=9$ )
price = price + TAX;
c. if(itemNumber $!=8$ \&\& $!=9$ )
price = price + TAX;
d. two of these

Ernest Castorena
Ernest Castorena
Numerade Educator
03:34

Problem 18

Which of the following C\# expressions means, "If itemNumber is 1 or 2 and quantity is 12 or more, add TAX to price"?
a. if(itemNumber $=1||$ itemNumber $=2$ \& quantity $>=12$ )
price $=$ price + TAX;
b. if(itemNumber $==1||$ itemNumber $==2||$ quantity $>=12$ )
price = price + TAX;
c. if(itemNumber $==1$ \&\& itemNumber $==2$ \&\& quantity $>=12$ )
price = price + TAX;
d. none of these

Ernest Castorena
Ernest Castorena
Numerade Educator
03:34

Problem 19

Which of the following C\# expressions means, "If itemNumber is 5 and zone is 1 or 3 , add TAX to price"?
a. if(itemNumber $==5$ \&\& zone $=1||$ zone $=-3$ )
price $=$ price + TAX;
b. if(itemNumber $==5 \&($ zone $==1 \|$ zone $==3)$ )
price $=$ price + TAX;
c. if(itemNumber $==5$ \& $($ zone $==1$ || 3))
price $=$ price + TAX;
d. two of these

Ernest Castorena
Ernest Castorena
Numerade Educator
03:34

Problem 20

Which of the following C\# expressions results in TAX being added to price if the integer itemNumber is not 100 ?
a. if(itemNumber $1=100)$
price $=$ price + TAX;
b. if(! (itemNumber $==100)$ )
price $=$ price + TAX;
c. if(itemNumber $<100 \|$ | itemNumber $>100$ )
price $=$ price + TAX;
d. all of these

Ernest Castorena
Ernest Castorena
Numerade Educator