Question: #1218

PROG 110 Chapter 6 Review Complete Solution

PROG 110  Chapter 6 Review
Points Possible: 20
No late submissions will be accepted
Print this document, and work through the questions prior to starting the assessment. You will be submitting your answers using the Quizzes Tool, with the link labeled Chapter 6 Review. There will be a 1 hour time limit when submitting your answers, so be sure to answer all questions prior to your submission. Each question is worth 1 point unless otherwise noted
NOTE: In the assessment, the answers will be presented in a random order, so make sure you select the correct response and not the letter you circle here.
1. In an array, every element has the same ___________.
a. subscript b. data type c. memory location d. all of the above
2. The operator used to create an object is __________.
a. = b. += c. new d. create
3. The value placed within square brackets after an array name is ___________.
a. a subscript b. an index c. always an integer d. all of these
4. When an integer array ages is correctly declared and initialized using the values {20, 30, 40, 50}, then the value of ages[4] is ____.
a. 0 b. 40 c. 50 d. undefined
5. When you declare and initialize an array as
int[] temperature = new[] {0, 32, 50, 90, 212, 451};
the value of temperature.Length is _____.
a. 5 b. 6 c. 7 d. unknown
6. Two arrays that store related information in corresponding element positions are _______.
a. analogous arrays b. polymorphic arrays
c. relative arrays d. parallel arrays
7. What does the following code fragment display on the console?
int[] amount = new int[] { 2, 3, 4, 5 };
for (int index = 0; index <= 3; ++index)
{
amount[index] *= 3; Console.Write( "{0} ", amount[index]);
}
8. Write a single, valid C# statement, to declare and initialize a single-dimension integer array named pips with the data 8, 9, 10, 11, 12.
9. A two-dimension integer array with the name table has been declared that has four rows and three columns. How many elements does the array contain?
PROG 110 Page 2
10. Using a ‘for’ loop, write a valid code fragment that adds 5 to every value in a 12-element integer array named pips. Use the Array property Length. Points will be deducted if you display to the console. (2 points)
11. Using a ‘foreach’ loop, write a valid code fragment that displays to the console, on a single line, every value in a 12-element integer array named pips. (2 points)
12. Assume a single-dimension integer array named numbers has been properly declared with the values 2, 3, 4, 5.
Using a ‘for’ loop, write the valid code fragment that displays the values in the array in
reverse order on a single line. Don’t forget the space between the numbers. Use the Array property Length but do not use the Array method Reverse. Make the loop generic for any size array. (3 points)
Hint: remember that the Length property starts at 1, while the array subscript starts at 0.
13. Find and correct the error in the following code segment: (2 points)
Assume int[ ] count = new int[ 10 ];
for (int i=0; i<=count.Length; ++i)
count[i] = 1;
a. Explain what the error is.
b. Explain how to correct the error. Type the correct statement or expression only, not the entire code segment.
14. Using valid C# syntax, perform the following tasks for an array of datatype double called fractions. (2 points)
a. Assign the value 1.667 to the array element with index 4.
b. Assign the value 3.333 to the second element in the array.
Remember that this is a self-assessment; therefore, please do your own work, and I hope that you take your time in answering each of the questions. Use Visual Studio, when appropriate, to assist in determining your responses.
If you have generic, general, questions, please post in the Module 5 discussion topic. In answering another student’s question, do not post “answers”, but you may provide guidelines/hints on how to obtain the desired result.

Solution: #1215

PROG 110 Chapter 6 Review Complete Solution

This Tutorial is rated A+ p...

Tutormaster
Rating: A+ Purchased: 11 x Posted By: Vikas
Comments
Posted by: Vikas

Online Users