CNIT 155 QUIZ 2 QUESTIONS & ANSWERS
Which logical operator should be used in the following statement? Assume that the valid
departments are CIT and CGT.
string dept;
dept = txtDept.Text;
if (dept == "CIT" _____________ dept == "CGT")
txtOutput.Text = "Valid dept";
else
txtOutput.Text = "Invalid dept";
A. ||
B. or
C. and
D. && - Answers -Answer:
A. ||
Which statement will check if the value stored in variable "count" IS within the valid
range?
Assume:
int count;
count = int.Parse(txtInput.Text);
A.
if (count >= 0 && count <= 100)
// valid range
B.
if (count < 0 || count > 100)
// valid range
C.
if (count >= 0 || count <= 100)
// valid range
D.
if (count >=0 && count <= 100)
// valid range - Answers -Answer:
A.
if (count >= 0 && count <= 100)
// valid range
, Which statement will do a type check on the data entered in txtScore for being a whole
#?
Assume:
int score;
A.
if (int.Parse(txtScore.Text, out score) == false)
MessageBox.Show ("Enter whole #");
B.
if (int.TryParse(txtScore.Text, out score) == false)
MessageBox.Show ("Enter whole #");
C.
if (in.TryParse(txtScore.Text, score) == false)
MessageBox.Show ("Enter whole #");
D.
if (int.TryParse(txtScore.Text, out score) )
MessageBox.Show ("Enter whole #"); - Answers -Answer:
B.
if (int.TryParse(txtScore.Text, out score) == false)
MessageBox.Show ("Enter whole #");
Evaluate the following.
Assume:
int num = 110;
num >= 0 || num <= 100
T or F? - Answers -Answer:
True
Logical || means if ONE condition is true the outcome will be true. Here, num >= 0 is
true.
What will be stored in n3 by the following segment of code?
int n1, n2, n3;
n1 = 12; n2 = 15; n3 = 1;
if (n1 > n2)
n3 = n1 -n2;
else if (n2 > 10)
n3 = n2 - 10;
Which logical operator should be used in the following statement? Assume that the valid
departments are CIT and CGT.
string dept;
dept = txtDept.Text;
if (dept == "CIT" _____________ dept == "CGT")
txtOutput.Text = "Valid dept";
else
txtOutput.Text = "Invalid dept";
A. ||
B. or
C. and
D. && - Answers -Answer:
A. ||
Which statement will check if the value stored in variable "count" IS within the valid
range?
Assume:
int count;
count = int.Parse(txtInput.Text);
A.
if (count >= 0 && count <= 100)
// valid range
B.
if (count < 0 || count > 100)
// valid range
C.
if (count >= 0 || count <= 100)
// valid range
D.
if (count >=0 && count <= 100)
// valid range - Answers -Answer:
A.
if (count >= 0 && count <= 100)
// valid range
, Which statement will do a type check on the data entered in txtScore for being a whole
#?
Assume:
int score;
A.
if (int.Parse(txtScore.Text, out score) == false)
MessageBox.Show ("Enter whole #");
B.
if (int.TryParse(txtScore.Text, out score) == false)
MessageBox.Show ("Enter whole #");
C.
if (in.TryParse(txtScore.Text, score) == false)
MessageBox.Show ("Enter whole #");
D.
if (int.TryParse(txtScore.Text, out score) )
MessageBox.Show ("Enter whole #"); - Answers -Answer:
B.
if (int.TryParse(txtScore.Text, out score) == false)
MessageBox.Show ("Enter whole #");
Evaluate the following.
Assume:
int num = 110;
num >= 0 || num <= 100
T or F? - Answers -Answer:
True
Logical || means if ONE condition is true the outcome will be true. Here, num >= 0 is
true.
What will be stored in n3 by the following segment of code?
int n1, n2, n3;
n1 = 12; n2 = 15; n3 = 1;
if (n1 > n2)
n3 = n1 -n2;
else if (n2 > 10)
n3 = n2 - 10;