ENGINEERING-AND-COMPUTER-SCIENCE
1. Assume-that-x,y,-and-temp-are-integer-variables-and-x=5-and-y=8.-Which-of-the-
following-lines-of-code-swaps-the-values-of-x-and-y?
a.-x-=-y;
-y-=-x;
b.-temp-=-x;
-x-=-y;
-y-=-temp;
c.-x-=-temp;
-x-=-y;
-y-=-temp;
d.-x-=-y;
-temp-=-x;
-y-=-temp;---CORRECT-ANSWER-b.-temp-=-x;
-x-=-y;
-y-=-temp;
2. Consider-the-following-two-sets-of-code
(p)-if-((a-==-1)-&&-(b-==-1))
{
-txtBox.Text-=-"Hi";
-}
-(q)-if-(a-==-1)
-{
-txtBox.Text-=-"Hi";
-}
}
Which-one-of-the-following-statements-is-true?
a.-(p)-and-(q)-will-produce-different-outputs
b.-(q)-is-not-a-valid-set-of-Visual-C#-instructions
c.-The-two-sets-of-code-are-equivalent,-but-(p)-is-preferred-to-(q)-because-(p)-us-
clearer
d.-The-condition-statement-in-(p)-is-not-valid---CORRECT-ANSWER-c.-The-two-sets-
of-code-are-equivalent,-but-(p)-is-preferred-to-(q)-because-(p)-us-clearer
3. How-many-times-does-the-MEssage-Box-get-executed-in-a-loop-that-begins-with-
the-following-statement?-Assume-i-is-declared-by-int-i;
for-(i-=-1;-i-<=-1;-i++)
, COMPUTER-PROBLEM-SOLVING-IN -EGR-1400-EXAM-1-2023-WITH-COMPLETED-SOLUTIONS.
ENGINEERING-AND-COMPUTER-SCIENCE
{
-x-=-x-+-2;
//this-is-the-sum,-count-here
}
a.-0
b.-2
c.-3
d.-1
e.-None-of-these---CORRECT-ANSWER-d.-1
4. How-many-times-will-the-following-sum-execute?-(x-starts-at-0-with-int-x-=-0;)
while-(x-<-8)
{
-x-=-x-+-2;-
//This-is-the-sum,-count-here
}
a.-0
b.-4
c.-5
d.-6
e.-None-of-these---CORRECT-ANSWER-b.-4
Start-w/-0
2
4
6
8
5. In-C#,-you-can-simulate-rolling-two-dice-by-selecting-a-random-number-between-
1-and-6-to-represent-each-die-roll-and-then-adding-them-together-to-get-the-dice-
total.-Let,s-say-that-we-developed-a-program-to-do-this-and-we-rolled-the-pair-of-
dice-50-times-and-recorded-the-results-of-each-roll-on-a-sheet-of-paper.-Can-we-
just-select-one-random-number-between-2-and-12-and-achieve-the-same-
experimental-results-for-the-50-rolls-as-rolling-two-die-and-adding-them?
a.-No,-It's-not-possible-to-get-the-same-experimental-results-with-one-random-number
b.-Yes,-using-the-same-scaling-as-before
c.-Yes,-if-the-Visual-C#-code-is-written-to-scale-the-single-random-number-between-2-
and-12