EGR 1400 (Introduction to Programming for Engineers) EXAM 1 QUESTIONS
AND CORRECT DETAILED ANSWERS WITH WELL DETAILED RATIONALES/NEWEST
UPDATE!!!
Question 1
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. If you roll the pair of
dice 50 times and record the results, can you achieve the same experimental results by simply
selecting one random number between 2 and 12 for each roll?
A) Yes, if the Visual C# code is written to scale the single random number between 2 and 12
B) Yes, using the same scaling as before
C) No, because the probability distribution is different; rolling two dice favors middle numbers
like 7, while a single random range is uniform
D) Yes, if the random number is selected using myRand.Next(2, 13)
E) None of the above
Correct Answer: C) No, because the probability distribution is different; rolling two dice
favors middle numbers like 7, while a single random range is uniform
Rationale: When rolling two six-sided dice, the sum of 7 is much more likely than a sum of 2
because there are more combinations that result in 7 (1+6, 2+5, 3+4, etc.). If you simply
pick a random number between 2 and 12, every number has an equal (uniform) chance of
appearing. Therefore, the experimental results would not reflect the true nature of dice
physics.
Question 2
What property of a Label control would you need to set to change the words displayed in the
Label on the form?
A) The Name property
B) The Captain property
C) The Word property
D) The Text property
E) The Display property
Correct Answer: D) The Text property
Rationale: In Windows Forms, the 'Name' property is used by the programmer to identify
the control in code (e.g., lblHeader), while the 'Text' property determines what the user
actually sees on the screen.
Question 3
Which of the following is the best name for a text box that will hold a person's age within a
Visual Studio .NET project, keeping in mind the recommended naming conventions?
A) Form1
B) txtAge
C) txtText1
D) Age
, 2
E) intAge
Correct Answer: B) txtAge
Rationale: Standard C# naming conventions for GUI controls suggest using a three-letter
prefix to identify the control type (txt for TextBox) followed by a descriptive name in
PascalCase. This makes code much more readable and easier to debug.
Question 4
When the user clicks a button in a C# Windows Forms application, ________ is raised.
A) A setting
B) A method
C) A property
D) An event
E) A class
Correct Answer: D) An event
Rationale: C# is an event-driven programming language. Actions performed by the user,
such as clicking a button, hovering a mouse, or pressing a key, trigger 'events' which then
execute specific blocks of code called event handlers.
Question 5
Which of the following statements will set the variable RandNum to a value between 1 and 3,
inclusive?
A) RandNum = myRand.Next(1, 3);
B) RandNum = myRand.Next(0, 3);
C) RandNum = myRand.Next(1, 4);
D) RandNum = myRand.Next(0, 4);
E) RandNum = myRand.Next(1, 5);
Correct Answer: C) RandNum = myRand.Next(1, 4);
Rationale: The Next(min, max) method in the C# Random class is inclusive of the lower
bound but exclusive of the upper bound. Therefore, to get a 3, the upper bound must be 4.
Question 6
What is the value of the following expression: float.Parse("3.8").ToString("0.00")?
A) 3.8
B) 3.80
C) 4
D) 03.80
E) 3.800
Correct Answer: B) 3.80
Rationale: float.Parse("3.8") converts the string to a numeric float value. The
.ToString("0.00") method then formats that number back into a string with exactly two
decimal places, regardless of whether they are zero.
AND CORRECT DETAILED ANSWERS WITH WELL DETAILED RATIONALES/NEWEST
UPDATE!!!
Question 1
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. If you roll the pair of
dice 50 times and record the results, can you achieve the same experimental results by simply
selecting one random number between 2 and 12 for each roll?
A) Yes, if the Visual C# code is written to scale the single random number between 2 and 12
B) Yes, using the same scaling as before
C) No, because the probability distribution is different; rolling two dice favors middle numbers
like 7, while a single random range is uniform
D) Yes, if the random number is selected using myRand.Next(2, 13)
E) None of the above
Correct Answer: C) No, because the probability distribution is different; rolling two dice
favors middle numbers like 7, while a single random range is uniform
Rationale: When rolling two six-sided dice, the sum of 7 is much more likely than a sum of 2
because there are more combinations that result in 7 (1+6, 2+5, 3+4, etc.). If you simply
pick a random number between 2 and 12, every number has an equal (uniform) chance of
appearing. Therefore, the experimental results would not reflect the true nature of dice
physics.
Question 2
What property of a Label control would you need to set to change the words displayed in the
Label on the form?
A) The Name property
B) The Captain property
C) The Word property
D) The Text property
E) The Display property
Correct Answer: D) The Text property
Rationale: In Windows Forms, the 'Name' property is used by the programmer to identify
the control in code (e.g., lblHeader), while the 'Text' property determines what the user
actually sees on the screen.
Question 3
Which of the following is the best name for a text box that will hold a person's age within a
Visual Studio .NET project, keeping in mind the recommended naming conventions?
A) Form1
B) txtAge
C) txtText1
D) Age
, 2
E) intAge
Correct Answer: B) txtAge
Rationale: Standard C# naming conventions for GUI controls suggest using a three-letter
prefix to identify the control type (txt for TextBox) followed by a descriptive name in
PascalCase. This makes code much more readable and easier to debug.
Question 4
When the user clicks a button in a C# Windows Forms application, ________ is raised.
A) A setting
B) A method
C) A property
D) An event
E) A class
Correct Answer: D) An event
Rationale: C# is an event-driven programming language. Actions performed by the user,
such as clicking a button, hovering a mouse, or pressing a key, trigger 'events' which then
execute specific blocks of code called event handlers.
Question 5
Which of the following statements will set the variable RandNum to a value between 1 and 3,
inclusive?
A) RandNum = myRand.Next(1, 3);
B) RandNum = myRand.Next(0, 3);
C) RandNum = myRand.Next(1, 4);
D) RandNum = myRand.Next(0, 4);
E) RandNum = myRand.Next(1, 5);
Correct Answer: C) RandNum = myRand.Next(1, 4);
Rationale: The Next(min, max) method in the C# Random class is inclusive of the lower
bound but exclusive of the upper bound. Therefore, to get a 3, the upper bound must be 4.
Question 6
What is the value of the following expression: float.Parse("3.8").ToString("0.00")?
A) 3.8
B) 3.80
C) 4
D) 03.80
E) 3.800
Correct Answer: B) 3.80
Rationale: float.Parse("3.8") converts the string to a numeric float value. The
.ToString("0.00") method then formats that number back into a string with exactly two
decimal places, regardless of whether they are zero.