Multiple Choice Answers

(TCO 11) Write a C# program to store an array of these integers: 11, 22, 33, 44, and 55. Use an appropriate loop to add all of the values in the list. Print out the sum.

Which of the following is a type of C# error that results from invalid use of programming language rules?
Compiler error
Logic error
Runtime error
Syntax error

What type of tool is Visual Studio.NET?
Interior design environment
Integrated development environment
Integrated design environment
Interior development environment

The _____ provides a hierarchal list of all of the projects and files in a solution.
property window
solution explorer
tool bar
class viewer

Which data types do not include decimal places?
Int, float
Int, double
Int, decimal
Int, char

A proper operator precedence, from first to last, is _____.
addition, subtraction, and multiplication
exponentiation, addition, and division
exponentiation, division, and multiplication
exponentiation, division, and subtraction
subtraction, addition, and multiplication

What is the result of this code segment?
int windows = 4;
Console.WriteLine(“The Truck has {0} windows” ,windows);
The line will not compile.
The Truck has 4 windows.
The Truck has {0} windows.
The Truck has 4.
The statement will not compile.

To print out the time and date a file called “plans.txt” was last written to, write _____.
Console.WriteLine(File.GetAccessInfo(“plans.txt”);
Console.WriteLine(GetAccessTime(“plans.txt”);
Console.WriteLine(File.GetLastWriteTime(“plans.txt”));
Console.WriteLine(GetLastWriteTime (“plans.txt”);

Similar to the _____ class method, the _____ class also offers the method ReadLine().
StreamReader, StreamWriter
StreamWriter, StreamReader
console, StreamReader
StreamReader, console

You’re writing a data decryption program. Because your C# code needs to read data from an encrypted file four bytes at a time, you decide to use the _____ member of the _____ class.
ReadByte(), BinaryReader
ReadBytes(), BinaryReader
ReadByte(), StreamReader
ReadBytes(), StreamReader

Show the source code for a C# console application named “Sibs” that prints your first and last names on the first line, and the number of siblings you have on the second line.
Declare and initialize an appropriate variable for your number of siblings.
Include at least three descriptive comments.
State how you would use the error list window to identify and correct errors in your code.

(TCO 5) Describe two types of loops that can be used to write the C# code required to print every second integer from 1 to 201 (i.e., 1, 3, 5, 7, etc.), each on its own line. Which would be a better choice

(TCO 8) Briefly describe how parameter passing by value and by reference are accomplished in memory. Write statement 1 to call Method A below. Write statement 2 to call Method B. Which method uses pass by value? Which method uses pass by reference?
static void
Main()
{
double principle = 10000.0;
double interest;

//statement 1
//statement 2

}
//method A
public
static double
calcInterest(double principle)
{
return (.02 * principle);
}
//method B
public static void calcInterest(ref
double interest, ref
double principle)
{
interest = principle * .02;
}

(TCO 9) Identify an example of one of each of the following GUI design errors in Figure 2.
Inconsistency
Misalignment
Clutter
How could each of the three errors be corrected to improve the user experience?
There is a rectangular bright red windows form that is approximately two times longer than it is tall. The text of the form as described in the title bar reads Form1. There is a menustrip object that is the length of the form from left to right approximately ¼ inch tall. There are 2 menu items on that menustrip, the text of the first reads Start and the second reads End. On the windows form titled Form1 are a total of 13 objects scattered throughout the form.

The control that is in the upper-left portion of the form is a combobox control. The combo-box control is approximately 1 inch from the left edge of the form. Just beneath the combobox is a list-box control with the background color set to green. The listbox with the green background is approximately 1 and ½ inch from the left edge of the form. Just beneath that listbox is a button control which reads Order on it. The button is approximately ½ inch from the left edge of the form. The button is very large, approximately 1 and ¼ inch tall and 3 inches long.

To the right of the 3 controls mentioned already are 3 more controls. These controls would be considered to be in the middle of the form. The first control in the middle and closest to the top of the form is a label control which reads TOTAL, the entire word is capitalized and set to bold format. Just beneath that label and slightly to the right is a groupbox control which reads Menu. Inside the groupbox control is 5 radio-button controls. The radiobutton controls have the following text from top to bottom: Hamburger, Chicken Fingers, Medium Fries, Large Fries, and Pizza. The text Chicken Fingers is a slightly larger font then the others, and the word Pizza is misspelled. Also, only the two top radiobuttons are aligned together. There is various spacing between all the radio-buttons, as well. Just outside the bottom of the group-box is a radiobutton control with the text Cheeseburger on it.

Lastly, there are 2 button controls on the right most portion of the screen. The first has the text Reset in blue letters on the gray button and the second button has the text OK with both letters capitalized.

Press the ESC key to close the image description and return to lecture
 (TCO 2) Although the following code compiles and runs, the programmer broke some major readability rules. Describe at least three changes that would make it easier for other programmers to read and understand the code.
class Program
{
static void Main() //start
{
int a;
int Integers = 10; // declare variables
for(int i = 0;i < Integers;i++) //loop
{
a=subroutine(i);
Console.WriteLine(a);
}
Console.Read();
}
public static int subroutine(int a) //a subroutine
{
return (int)(Math.Pow((double)a,2.0)); //TBD
}
}

 (TCO 4) A home improvement store is giving a discount of 20% on all purchases of more than $250. Which of the following is the appropriate structure to use to program the statement?
Loop
Method
Decision
Sequence

 (TCO 4) Which of the following is true about the IF decision structure?
An IF does not always need to be followed by an ELSE.
An IF/ELSE is also known as a “dual selection” structure.
It can be nested.
All of the above

 (TCO 5) What output will this set of statements produce?
int a = 1;
while (a > 1)
{
Console.Write(“{0}\t”, a);
a–;
}
Console.Write(“{0}\t”, a);
An infinite loop
An error
1 1
1

 (TCO 5) Your program keeps asking for Student IDs until he/she enters “AAAAA.” In this context, the “AAAAA” is used as a(n) _____.
accumulator
counter
integer data type
sentinel value

(TCOs 7, 8) What does it mean to say that a variable is local to a method?
Only Main() and the method where the variable is declared can see and use it.
Only the method where the variable is declared can see and use it.
No methods can see or use it.
Every method can use it.

(TCOs 7, 8) Because Main() and testMeth() store myVar in _____, the output of this code will be _____.

static void
Main()
{
int myVar = 6;
Console.Write(“{0} “, myVar);
testMeth(myVar);
myVar++;
Console.Write(“{0} “, myVar);
Console.Read();
}

public static void testMeth(int
myVar)
{
Console.Write(“{0} “, myVar);
myVar++;
}
different memory locations, 6 6 7
the same memory location, 6 6 7
different memory locations, 6 6 8
the same memory location, 6 6 8

(TCOs 7, 8) Which is probably a call to an accessor method?
SetNoOfYards(double yds);
double yds = GetNoOfYards();
CarpetCalculator plush = new CarpetCalculator();
double yards = yds.calcYards();

 (TCOs 9, 10) Type _____ to append “New Year’s Day” to an existing list of holidays in the “cmboHolidays” ComboBox object at run time.
cmboHolidays.Add(“New Year’s Day”);
cmboHolidays.Append(“New Year’s Day”);
cmboHolidays.Items.Add(“New Year’s Day”);
cmboHolidays.Items.Append(“New Year’s Day”);

(TCOs 9, 10) A(n) _____ calls on the operating system to perform input/output functions, whereas a _____ reacts to event notifications from the operating system.
console application, Windows application
Windows application, console application
event handler, system caller
system call, event handler

 (TCOs 9, 10) During a code walk-through, someone may suggest that this code be replaced with _____, as it is more efficient.
int val = 1;
while (val <= 10)
{
Console.WriteLine(val);
val++;
}
for(int val = 1; val <= 10; val++)
{
Console.WriteLine(val);
}
for(int val = 0; val <= 10; val++)
{
Console.WriteLine(val);
}
for(int val = 1; val <= 10; val–)
{
Console.WriteLine(val);
}
int
val = 1;
do while (val <= 10)
{
Console.WriteLine(val);
val++;
}

(TCOs 11, 12) Which of the following is not true about a C# array?
All of its elements must be initialized when declared.
It can be passed to a method for processing.
It can have multiple dimensions.
Its indexing starts at zero.

(TCOs 11, 12) To pass the first and second elements of the myData array to the DisplayItems method, replace the commented line below with _____.

static void
Main()
{
int[] myData = {1,2,3,4};
//call DisplayItems
}
public static void DisplayItems(params
int[] item)
{
for (int i=0; i<item.Length; i++)
Console.Write(“{0} “,item[i]);
}
DisplayItems(myData, 1, 2);
DisplayItems(myData[0],myData[1]);
DisplayItems(myData, 0, 1);
DisplayItems(myData[1],myData[2]);

 (TCOs 11, 12) An array is a list of data items that _____.
are of different data types
are all integers
have different names
are indexed