Exam Prep Chapter.5 Loops, Files, And Random Numbers 5e - Test Bank | Visual C# 5e by Tony Gaddis. DOCX document preview.
Starting Out with Visual C#, 5e (Tony Gaddis)
Chapter 5 Loops, Files, and Random Numbers
TRUE/FALSE
1. The do-while loop always performs at least one iteration, even if its Boolean expression is false to begin with.
2. If you are writing a while loop that has only one statement in its body, you do not have to enclose the statement in curly braces.
3. A while loop will always iterate at least once, even if the Boolean expression is initially false.
4. Counter variables are commonly used to hold Boolean values that control the number of times a loop iterates.
5. Incrementing and decrementing are so commonly done in programs that C# provides the ++ and -- unary operators for just these purposes.
6. Not only may the counter variable of a for loop be initalized in the initalization expression, but it may also be declared there.
7. A semicolon is required at the very end of a do-while loop.
8. There are always three steps that must be taken when a file is used by a program: opening the file, processing the file, and closing the file.
9. A binary file may be opened and viewed in a text editor such as Notepad.
10. A direct access file is also known as a random access file.
11. Check boxes are similar to radio buttons in that they are both mutully exclusive.
12. When the WriteLine method writes data to a file, it writes a null character immediately following the data.
13. When reading numeric data from a text file, the Parse and TryParse methods can be used to convert the items from string values to numeric data types.
14. An exception will never be thrown when a program attempts to read beyond the end of a file.
15. When keeping a running total, the accumulator variable can start with any value and still contain the correct total when the loop finishes.
16. The Next method in the Random class generates a floating-point number.
17. If a Random object uses the same seed value each time it is created, it will always generate the same series of numbers.
18. If you call Random.Next(), the resulting random values will be between 1 and 2147483647.
19. The values generated by the Random class are not really random. Instead, they are determined by a formula that only makes the numbers appear as if they were random.
20. In order for a program to work with a file on the computer's disk, the program must create a file object using code statements.
MULTIPLE CHOICE
1. Each time a loop executes its statement(s), we say the loop is performing a(n) __________.
a. | cycle | b. | pass | c. | execution | d. | iteration |
2. The statement or block of statements following the while clause is known as the __________ of the loop.
a. | assembly | b. | body | c. | definition | d. | decision |
3. The while loop is known as a __________ loop which means it tests its condition before performing each iteration.
a. | posttest | b. | pretest | c. | proactive | d. | preemptive |
4. The __________ begins with the word while, followed by a Boolean expression that is enclosed in parentheses.
a. | conditional statement | c. | while clause |
b. | logic mark | d. | loop parameter |
5. __________ are commonly used to control the number of times a loop iterates.
a. | Boolean variables | c. | Counter variables |
b. | Sentinel variables | d. | Named constants |
6. To __________ a variable means to decrease its value by 1.
a. | subtract | c. | decrement |
b. | increment | d. | supplement |
7. The ++ and -- operators can be written before their operands. This is called __________ mode.
a. | preface | b. | postfix | c. | prefix | d. | superscript |
8. The first expression appearing in the header of a for loop is the __________ expression which usually assigns a starting value to a counter variable.
a. | update | b. | test | c. | Boolean | d. | initialization |
9. Because the for loop tests its Boolean expression before it performs an iteration, it is a __________ loop.
a. | pretest | b. | pseudo | c. | posttest | d. | infinite |
10. The second expression appearing in the header of a for loop is the __________ expression which is a Boolean expression that determines whether the loop will repeat.
a. | update | b. | test | c. | control | d. | initialization |
11. The third expression appearing in the header of a for loop is the __________ expression, which executes at the end of each iteration.
a. | update | b. | test | c. | increment | d. | initialization |
12. The __________ loop is a posttest loop which means it performs an iteration before testing its Boolean expression.
a. | for | b. | while | c. | do-while | d. | do-before |
13. The __________ is specifically designed for situations requiring a counter variable to control the number of times a loop iterates.
a. | for loop | c. | while loop |
b. | if-else statement | d. | switch statement |
14. Be careful not to place a statement that modifies the counter variable inside the body of a __________.
a. | for loop | c. | while loop |
b. | if statement | d. | switch statement |
15. The term __________ is used to describe a file from which data is read.
a. | input file | c. | record file |
b. | output file | d. | record set |
16. When you work with a __________, you can jump directly to any piece of data in the file without reading the data that comes before it.
a. | file object | c. | direct access file |
b. | binary file | d. | sequential access file |
17. A(n) __________ contains data that cannot be viewed by a text editor such as Notepad.
a. | source file | c. | data file |
b. | binary file | d. | access file |
18. A(n) __________ structure is a set of statements that execute in the order in which they appear.
a. | ordered | b. | command | c. | control | d. | sequence |
19. In order to write data to a text file, you must create a file object using the __________ class.
a. | TextReader | c. | StreamReader |
b. | TextWriter | d. | StreamWriter |
20. When you want to read data from a text file, you create a file object using the __________ class.
a. | TextReader | c. | StreamReader |
b. | BufferedReader | d. | InputReader |
21. You can use the StreamWriter class's __________ method to write a line of text to a file.
a. | PrintLine | c. | WriteLine |
b. | WriteText | d. | PrintText |
22. The __________ method is a method in the StreamWriter class that writes a string to a text file without writing a newline character.
a. | c. | WriteLine | |
b. | Text | d. | Write |
23. You can use the StreamReader class's __________ method to read a line of text from a file.
a. | ReadLine | c. | GetNext |
b. | ReadText | d. | Read |
24. You can use the StreamReader class's __________ to determine if the file's read position is at the end of the file.
a. | EndOfFile property | c. | EndOfStream property |
b. | StreamEnd method | d. | EOF method |
25. To append data to an existing file, you open it with the __________ method.
a. | File.Append | c. | File.AppendText |
b. | File.AppendAll | d. | File.OpenExistingText |
26. If you specify a path in a string literal, you need to prefix the string with the __________ symbol, also known as the literal text character.
a. | # | b. | @ | c. | $ | d. | * |
27. A(n) __________ accumulates a total by adding each number in a series to a variable that holds the sum.
a. | running total | c. | active sum |
b. | numeric tally | d. | dynamic collection |
28. The variable that accumulates a total of the numbers in a running total is called a(n) __________.
a. | counter | c. | entity |
b. | sentinel | d. | accumulator |
29. If the user clicks the Open button, the OpenFileDialog control's ShowDialog method returns the value __________.
a. | Result.True | c. | DialogResult.Open |
b. | DialogResult.OK | d. | Result.OpenFile |
30. When the user selects a file with the Open dialog box, the file's path and filename are stored in the control's __________ property.
a. | FilePath | b. | Source | c. | Location | d. | Filename |
31. You can specify the directory to be initally displayed by the Open dialog box by storing its path in the __________ property.
a. | InitialDirectory | c. | Filename |
b. | Source | d. | Path |
32. You can change the default text displayed in the Open dialog box's title bar by changing the control's __________ property.
a. | Caption | c. | Title |
b. | Text | d. | Heading |
33. In code, you can display a Save As dialog box by calling the SaveFileDialog control's __________ method.
a. | SaveAs | c. | ShowDialog |
b. | Show | d. | Display |
34. If the user clicks the Cancel button, the SaveFileDialog control's ShowDialog method returns the value __________.
a. | Result.False | c. | DialogResult.Abort |
b. | DialogResult.Cancel | d. | Result.NULL |
35. The expression __________ causes an object of the Random class to be created in memory.
a. | GetRandom(int) | c. | new Random() |
b. | GenerateRandom(number) | d. | random new() |
36. Once you have created a Random object, you can call its __________ method to get a random integer number.
a. | Next | c. | GenerateNumber |
b. | GetInteger | d. | NextInteger |
37. You can call a Random object's __________ method to get a random floating-point number between 0.0 and 1.0.
a. | GetDouble | c. | NextDouble |
b. | NextFloat | d. | DoubleRand |
38. The numbers generated by the Random class are __________ calculated by a formula.
a. | pseudorandom numbers | c. | algebraic derivatives |
b. | binary encoded numbers | d. | complex variables |
39. A __________ is used in the calculation to generate random numbers.
a. | sentinel | c. | seed value |
b. | logarithmic value | d. | Random object |
40. When you run an application, the application's form is loaded into memory and an event known as the __________ event takes place.
a. | Load | b. | Launch | c. | Boot | d. | Initialization |