ITSS 131

Ace your homework & exams now with Quizwiz!

Which of the following C# expressions is equivalent to a < b && b < c?

!(b <= a) && b < c

What does the following code segment display? for(t = 0; t < 3; ++t) Write("{0} ", t);

0 1 2

Assume that you have a variable declared as int var1 = 3;. What is the value of 22 % var1?

1

Consider the following catch blocks. The variable b has been initialized to 0. If a DivideByZeroException occurs in a try block just before this catch block, what is the value of b when this code completes? catch(DivideByZeroException e) {<br ++b; } catch(Exception e) { ++b; }

1

What is the value of the expression 4 + 2 * 3?

10

Assume that you have declared a variable as double hourly = 13.00;. What will the statement WriteLine(hourly); display?

13

Consider the following catch blocks. The variable c has been initialized to 0. If an IndexOutOfRangeException occurs in a try block just before this catch block, what is the value of c when this code completes?catch(IndexOutOfRangeException e) { ++c; } catch(Exception e) { ++c; } finally { ++c; }

2

Assume that you have a variable declared as int var1 = 3;. If var2 = var1++, what is the value of var2?

3

What does the following code segment display?for(f = 0; f < 3; ++f); Write("{0} ", f);

3

Assume that you have a variable declared as int var1 = 3;. If var2 = ++var1, what is the value of var2?

4

What is the output of the following code segment? s=1; while(s < 4) ++s; Write("{0} ", s);

4

What is the output of the following code segment? j = 5; while(j > 0) { Write("{0} ", j); j--; }

5 4 3 2 1

Assume that you have a variable declared as int var1 = 3;. What is the value of 22 / var1?

7

Consider the following try block. If x is 15, what is the value of a when this code completes?try { a = 99; if(x > 10) throw(new Exception()); a = 0; ++a; }

99

Which of the following is not a C# comparison operator?

=>

When you perform arithmetic operations with operands of different types, such as adding an int and a float____________________ .

C# chooses a unifying type for the result

Which of the following is a class?

Console

What is the output of the following code segment?int a = 3, b = 4;if(a > b) Write("Up");else WriteLine("Down");

Down

When you create an Exception subclass of your own, you should extend the ______________________ class.

Exception

Most exceptions you will use derive from three classes: ______________________.

Exception, SystemException, and ApplicationException

What is the output of the following code segment?int c = 6, d = 12;if(c > d); Write("Green"); WriteLine("Yellow");

GreenYellow

Which of the following is not required of a loop control variable in a correctly working loop?

It is reset to its initial value before the loop ends.

Which of the following is a method?

Main()

What is the output of the following code segment?int e = 5, f = 10;if(e < f || f < 0) Write("Purple");else Write("Gold");

Purple

What is the output of the following code segment?int c = 6, d = 12;if(c < d) if(c > 8) Write("Blue"); else Write("Red");else Write("Green");

Red

What is the major advantage of using a for loop instead of a while loop?

The loop control variable is initialized, tested, and altered all in one place.

Which of the following is true of variable declarations?

Two variables of the same type can be declared in the same statement.

Which of the following pairs is an example of a class and an object, in that order?

University and Yale

If a programmer inserts using static System.Console; at the top of a C# program, which of the following can the programmer use as an alternative to System.Console.WriteLine("Hello");?

WriteLine("Hello");

Assume that you have a variable declared as int var1 = 3;. Which of the following would display X 3X?

WriteLine("X{0,2}X", var1);

Assume that you have two variables declared as int var1 = 3; and int var2 = 8;. Which of the following would display 838?

WriteLine("{0}{1}{0}", var2, var1);

The C# method that produces a line of output on the screen and then positions the cursor on the next line is ________________ .

WriteLine()

Assume that you have declared a variable as double salary = 45000.00;. Which of the following will display $45,000?

WriteLine(salary.ToString("c0"));

What is the output of the following code segment?int a = 3, b = 4;if(a == b) Write("X"); WriteLine("Y");

Y

What is the output of the following code segment?int a = 3, b = 4;if(a < b){ Write("Y"); WriteLine("Z");}

YZ

Which of the following is not treated as a C# Exception?

You attempt to execute a C# program, but the C# compiler has not been installed.

Unicode is_____________________.

a 16-bit coding scheme

The loop control variable is checked at the bottom of which kind of loop?

a do loop

Which loop is most convenient to use if the loop body must always execute at least once?

a do loop

Which of the following expressions is equivalent to a || b && c || d?

a || (b && c) || d

Which of the following C# expressions results in TAX being added to price if the integer itemNumber is not 100?

all of these

You can place ______________________ statement(s) within a try block.

any number of

How many catch blocks might follow a try block within the same method?

any number, including zero or one

A variable declaration must contain all of the following except a(n) ______________.

assigned value

A comment in the form /* this is a comment */ is a(n)___.

block comment

A variable that can hold the two values true and false is of type ______________.

bool

Exception objects can be ______________________.

both of these

In C#, falling through a switch case is most often prevented by using the ______________ statement.

break

In C#, an identifier _________________________ .

can contain digits

When a program creates an Exception object, you ______________________.

can handle it

Which of the following catch blocks will catch any Exception object?

catch(Exception e) {}

A program that translates high-level programs into intermediate or machine code is a(n) _______________________ .

compiler

Which of the following is equivalent to the following statement?if(m == 0) d = 0;else d = 1;

d = (m == 0) ? 0 : 1;

The body of a while loop can consist of _______________________ .

either a or b

The technique of packaging an object's attributes into a cohesive unit that can be used as an undivided entity is ______________ .

encapsulation

Any error condition or unexpected behavior in an executing program is known as an ______________________.

exception

What is the value of the expression 6 >= 7?

false

Every method in C# contains a _________________________ .

header and a body

Programming languages such as C#, Java, and Visual Basic are ____________________languages.

high-level

Which of the following expressions is equivalent to the following code segment?if(g > h) if(g < k) Write("Brown");

if(g > h && g < k) Write("Brown");

Which of the following C# expressions means, "If itemNumber is not 8 or 9, add TAX to price"?

if(itemNumber != 8 && itemNumber != 9)price = price + TAX;

Which of the following C# expressions means, "If itemNumber is 5 and zone is 1 or 3, add TAX to price"?

if(itemNumber == 5 && (zone == 1 || zone == 3))price = price + TAX;

A loop for which you do not know the number of iterations when you write it is a(n) _______________________ .

indefinite loop

A loop that never ends is called an ________________________ loop.

infinite

The three sections of the for loop are most commonly used for _________________________ the loop control variable.

initializing, testing, and incrementing

Which of the following C# types cannot contain floating-point numbers?

int

When you use a number such as 45 in a C# program, the number is a ______________.

literal constant

A series of characters that appears within double quotation marks is a(n) ______________ .

literal string

A structure that allows repeated execution of a block of statements is a(n) ___________ .

loop

Which of the following languages is least similar to C#?

machine language

Variables are _______________ .

named memory locations

In C#, a container that groups similar classes is a(n) ___________________ .

namespace

When a loop is placed within another loop, the loops are said to be ______________________ .

nested

Which of the following C# expressions means, "If itemNumber is 1 or 2 and quantity is 12 or more, add TAX to price"?

none of these

What does the following code segment display? a = 1; while (a < 5);{Write("{0} ", a);++a;}

nothing

Programs in which you create and use objects that have attributes similar to their real-world counterparts are known as ______________ programs.

object-oriented

In a for statement, the section before the first semicolon executes ______________________________ .

once

How many case labels would a switch statement require to be equivalent to the following if statement?if(v == 1) WriteLine("one");else WriteLine("two");

one

What is the output of the following code segment?int e = 5, f = 10;if(e < f && f < 0) Write("Red");else Write("Orange");

orange

Which of the following identifiers is not legal in C#?

per cent increase

A for loop is an example of a(n) __________________________ loop.

pretest

A while loop is an example of a(n) _______________________ loop.

pretest

The text of a program you write is called _________________________.

source code

A while loop with an empty body contains no ___________________________ .

statements

Which of the following declares a variable that can hold the word computer?

string device = "computer";

Which of the following compares two string variables named string1 and string2 to determine if their contents are equal?

stringl == string2

Programming errors such as using incorrect punctuation or misspelling words are collectively known as ____________________ errors.

syntax

The grammar and spelling rules of a programming language constitute its _____________ .

syntax

If your program throws an IndexOutOfRangeException, and the only available catch block catches an Exception, ______________________.

the Exception catch block executes

If the test expression in a switch does not match any of the case values, and there is no default value, then ______________.

the program continues with the next executable statement

When you design your own classes that might cause exceptions, and other classes will use your classes as clients, you should usually create your methods to ______________________.

throw exceptions but not handle them

In object-oriented terminology, a method that detects an error condition ______________________ an exception.

throws

A catch block executes when its try block ______________________.

throws an Exception of an acceptable type

In object-oriented terminology, you ______________________ a procedure that might not complete correctly.

try

When you write a block of code in which something can go wrong, and you want to throw an exception if it does, you place the code in a ______________________ block.

try

Which of the following expressions assigns true to a Boolean variable named isIDValid when idNumber is both greater than 1000 and less than or equal to 9999, or else is equal to 123456?

two of these

Which of the following is valid within a catch block with the header catch(Exception error)?

two of these

A for loop statement must contain ____________________________ .

two semicolons

If the following code segment compiles correctly, what do you know about the variable x?if(x) WriteLine("OK");

x is a Boolean variable.

If you do not use object-oriented techniques, ______________________.

you can still manage error situations


Related study sets

Statistics for Social Workers Chapter 2 Frequency Distribution/ Graphs

View Set

Nature of Science statements 11-20

View Set

CTS 110 Network Essentials Module 1 to Module 13 Quiz for Network+ Guide to Networks 8th Edition

View Set

Engine size and performance measurements

View Set

UFC1 - Chapter 4 Activity based Costing

View Set