Chapter 1 - 7 C#

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

The default label is required in the switch section statement (T/F)

False. The default label is optional. If no default action is needed, then there's no need for a default label.

______________ begins a single line comment.

//

state that an app performs a simple payroll calculation (ie. use text that helps to document an app)

// This application performs a simple payroll calculation.

State that an app will calculate the product of three integers.

//Calculating the product of three integers

Explain the purpose of a method parameter. What is the difference between a parameter and an argument?

A parameter represents additional information that a method requires to perform its task. Each parameter required by a method is specified in the method's declaration. An argument is the actual value that's passed to a method parameter when a method is called.

A valid C# arithmetic expression with no parentheses is evaluated from left to right

False. The expression is evaluated according to operator precedence and associativity.

The arithmetic operators *,/,%,+ and - all have the same level of precedence. (T/F)

False. The operators *,/, and % are on the same level of precedence, and the operators + and - are on lower level of precedence.

X toggles auto-hide for a window (T/F)

False. The pin icon toggles auto-hide. X closes a window.

The remainder operator (%) can be used only with integer operands. (T/F)

False. The remainder operator also can be used with nonintegrer operands in C#.

The unary cast operator (double) creates a temporary integer copy of its operand. (T/F)

False. The unary cast operator (double) creates a temporary floating-point copy of its operand.

C# is available only on Microsoft Windows (T/F)

False. There are ports of C# for other platforms, such as Linux

The .NET Framework Class Library has millions of valuable prebuilt classes that have been tested and tuned to maximize performance. (T/F)

False. Thousands, not millions, of prebuilt classes

Visual C# files use the file extension .csharp. (T/F)

False. Visual C# files use the file extension .cs.

The information carrying capacity of communications lines on the internet has increased tremendously, while hardware costs have increased (T/F)

False: Hardware costs have decreased

Microsoft's ASP.WEB technology is used to create web apps (T/F)

False: It's ASP.NET Technology

Tim Berners-Lee developed the ________ for sharing information via "hyperlinked" text documents on the web.

HyperText Markup Language (HTML)

The expression ((x>y) && (a<b)) is true if either (x>y) or (a<b) is true. (T/F)

False, both of the relational expressions must be true for this entire expression to be true when using the && operator.

A form's ___________ property specifies the text displayed in the form's title bar.

Text.

The ___________ property specifies how text is aligned within a label's boundaries.

TextAlign

The smallest data item in a computer can assume the value 1 or the value 2. Such a data item is called a bit (short for "binary digit"—a digit that can assume either of two values). (T/F)

False. Such items have the value 0 or 1

Variables declared in the body of a particular method are known as instance variables and can be used in all methods of the class. (T/F)

False. Such variables are called local variables and can be used only in the method in which they're declared.

The toolbar contains icons that represent controls you can drag onto a form. (T/F)

False. The Toolbox contains icons that represent such controls.

A(n) _____________ begins the body of every method, and a(n) _____________ends the body of every method.

Left brace ({, right brace })

The most popular database model is the relational database in which data is stored in simple tables. A table includes records and files (T/F)

True

The toolbar icons represent various menu commands. (T/F)

True

Although many different OOAD processes exist, a single graphical language for communicating the results of any OOAD process has come into wide use. This language, known as the _________ , is now the most widely used graphical scheme for modeling object-oriented systems.

UML

Windows 10 introduced the ________ for building Windows apps that run on desktop computers, notebook computers, tablets, phones, Xbox and even Microsoft's new HoloLens augmented reality holographic headset - all using nearly identical code

Universal Windows Platform (UWP)

Computers can directly understand only their _________ language, which is composed of only 1s and 0s

Machine

C# apps begin execution at method __________.

Main

State the order of evaluation of the operators in each of the following C# statements and show the value of x after each statement is performed: a) x = 7 + 3 * 6 / 2 - 1; b) x = 2 % 2 + 2 * 2 - 2 / 2; c) x = (3 * 9 * (3 + (9 * 3 / (3))));

a) *, /, +, -, =; Value of x is 15. b) %, *, /, +, -, =; Value of x is 3. c) x = (3 * 9 * (3 + (9 * 3 / (3)))); 6 4 5 3 1 2 Value of x is 324.

What is the value of the double variable x after each of the following statements is executed? a) x = Math.Abs(7.5); b) x = Math.Floor(7.5); c) x = Math.Abs(0.0); d) x = Math.Ceiling(0.0); e) x = Math.Abs(-6.4); f) x = Math.Ceiling(-6.4); g) x = Math.Ceiling(-Math.Abs(-8 + Math.Floor(-5.5)));

a) 7.5 b) 7.0 c) 0.0 d) 0.0 e) 6.4 f) -6.0 g) -14.0

Keyword public is a(n) ____________

access modifier

The do....while statements tests the loop-continuation condition _______ executing the loop's body; therefore, the body always executes at least once.

after

The arithmetic operations with the same precedence as multiplication are __________ and ___________

division (/) and remainder (%)

If the loop-continuation condition in a for header is initially _____, the for statement's body does not execute.

false

Typically, _________ statements are used for counter controlled repetition and _________ statements for sentinel controlled repetition.

for, while

Test whether variable count is greater than 10. If it is, print "Count is greater than 10".

if (count > 10) { Console.WriteLine(" Count is greater than 10"); }

Using __________ help immediately displays a relevant help article.

context-sensitive help

____________ displays relevant help articles, based on the current context.

context-sensitive help

The __________ statement, when executed in an iteration statement, skips the remaining statements in the loop body and proceeds with the next iteration of the loop.

continue

When parenthesis in an arithmetic expression are nested, the _____________ set of parenthesis is evaluated first.

innermost

(Write a C# statement) Sum the odd integers between 1-99, using a for statement. Assume that the integer variables sum and count have been declared.

sum=0; for (count =1; count <=99; count +=2) { sum += count; }

The ________ statement selects among multiple actions based on the possible values of an integer variable or expression.

switch

A(n) appears when the mouse pointer hovers over an icon.

tool tip

Decrement the variable x by 1, then subtract it from the variable total. Use only 1 statement.

total-= --x;

An algorithm is a procedure for solving a problem in terms of the actions to execute and the order in which these actions execute (T/F)

true

Input an integer and assign the result to int variable value

value= int.Parse(Console.ReadLine());

A location in the computer's memory that may contain different values at various times throughout the execution of a program is called a ______.

variable

The CLR is a(n) _________ machine. It is software that manages the execution of programs and hides from them the underlying operating system and hardware.

virtual

The technique of ____________ allows you to create GUIs without writing any code.

visual app development

Return type _________ indicates that a method will not return any information when it completes its task.

void.

The __________ menu contains commands for arranging and displaying windows.

window

Assuming x=2 and y=3, what does each of the following statements display? Console.WriteLine($"x={x}"); Console.WriteLine($"Value of {x}+{x} is {x+x}"); Console.Write("x="); Console.WriteLine($"{x+y}={y+x}");

x=2 Value of 2+2 is 4 x= 5=5

Read the first integer from the user and store it in the variable x.

x=int.Parse(Console.ReadLine());

Write four different C# statements that each add 1 to an int variable x.

x=x+1; x+=1; ++x; x++;

Read the second integer from the user and store it in the variable y.

y=int.Parse(Console.ReadLine());

Read the third integer from the user and store it in variable z.

z=int.Parse(Console.ReadLine());

Assign the sum of x and y to z, and increment x by 1 with ++. Use only one statement and ensure that the original value of x is used in the statement.

z=x++ + y;

By using existing controls—which are objects—you can create powerful apps much faster than if you had to write all the code yourself. This is a key benefit of software ________.

reuse

Use a building-block approach to creating your programs. Avoid reinventing the wheel—use existing pieces wherever possible. Such software ________ is a key benefit of object-oriented programming.

reuse

Most statements end with a(n) ____________

semicolon (;)

When it's not known in advance how many times a set of statements will be repeated, a(n) _______ value can be used to terminate the repetition.

sentinel, signal, flag, or dummy

The __________ structure is built into C#--by default, statements execute in the order in which they appear.

sequence

All apps can be written in terms of three types of control structures: ____________,_______________,____________.

sequence, selection, iteration

Assign the product of variables b and c to variable a.

a=b*c;

The ________ operator can be used to ensure that two conditions are both true before choosing a certain path of execution.

&& (conditional AND) or & (boolean logical AND)

Instance variables of type int are given the ____________ by default.

(0) zero

Given that y = ax3 + 7, which of the following are correct C# statements for this equation? a) y = a * x * x * x + 7; b) y = a * x * x * (x + 7); c) y = (a * x) * x * (x + 7); d) y = (a * x) * x * x + 7; e) y = a * (x * x * x) + 7; f) y = a * x * (x * x + 7);

(a), (d), (e).

What does the following code display? Console.WriteLine("*\n**\n***\n****\n*****");

* ** *** **** *****

What does the following code display? string s1 = "*"; string s2 = "***"; string s3 = "*****"; Console.WriteLine($"{s1}\n{s2}\n{s3}")

* *** *****

What does the following code display? Console.WriteLine("*"); Console.WriteLine("***"); Console.WriteLine("*****"); Console.WriteLine("****"); Console.WriteLine("**");

* *** ***** **** **

(What Does This Code Do?) What does the following code segment do? for (int i = 1; i <= 5; ++i) { for (int j = 1; j <= 3; ++j) { for (int k = 1; k <= 4; ++k) { Console.Write('*'); } Console.WriteLine(); } Console.WriteLine(); }

**** **** **** **** **** **** **** **** **** **** **** **** **** **** ****

What does the following code display? Console.Write("*"); Console.WriteLine("***"); Console.WriteLine("*****"); Console.Write("****"); Console.WriteLine("**");

**** ***** ******

(What Does This Program Do?) What does the following app display? 1 // Ex. 5.25: Mystery2.cs 2 using System; 3 4 class Mystery2 5 { 6 static void Main() 7 { 8 int count = 1; 9 10 while (count <= 10) 11 { 12 Console.WriteLine(count % 2 == 1 ? "****" : "++++++++"); 13 ++count; 14 } 15 } 16 }

**** ++++++++ **** ++++++++ **** ++++++++ **** ++++++++ **** ++++++++

What does the following code display? Console.Write("*"); Console.Write("***"); Console.Write("*****"); Console.Write("****"); Console.WriteLine("**");

***************

(What's Wrong with This Code?) What is wrong with the following statement? Provide the correct statement to add 1 to the sum of x and y. Console.WriteLine(++(x + y));

++ can only be applied to a variable—not an expression with multiple terms. The correct statement is Console.WriteLine( x + y + 1 );

Using the statements you wrote in Exercise 3.5 write an app that calculates and displays the product of three integers.

//Exercise 3.6: Product.cs // Calculating the product of three integers. using System; class Product { static void main() { int x; int y; int z; int result; Console.Write("Enter first integer:"); x=int.Parse(Console.ReadLine()); Console.Write("Enter second integer:"); y=int.Parse(Console.ReadLine()); Console.WriteLine("Enter third integer:"); z=int.Parse(Console.Readline()); result = x*y*Z; Console.WriteLine($"Product is {result}); } }

(What Does This Program Do?) What does the following app display? 1 // Ex. 5.16: Mystery.cs 2 using System; 3 4 class Mystery 5 { 6 static void Main() 7 { 8 int x = 1; 9 int total = 0; 10 11 while (x <= 10) 12 { 13 int y = x * x; 14 Console.WriteLine(y); 15 total += y; 16 ++x; 17 } 18 19 Console.WriteLine($"Total is {total}"); 20 } 21 }

1 4 9 16 25 36 49 64 81 100 Total is 385

Write a complete C# app to prompt the user for the double radius of a sphere, and call method SphereVolume to calculate and display the volume of the sphere. Write an expression-bodied method containing the following expression to calculate the volume: (4.0 / 3.0) * Math.PI * Math.Pow(radius, 3)

1 // Exercise 7.6 Solution: Sphere.cs 2 // Calculate the volume of a sphere. 3 using System; 4 5 class Sphere 6 { 7 // obtain radius from user and display volume of sphere 8 static void Main() 9 { 10 Console.Write("Enter radius of sphere: "); 11 double radius = double.Parse(Console.ReadLine()); 12 Console.WriteLine("Volume is {SphereVolume(radius):F3}"); 13 } 14 15 // calculate and return sphere volume 16 static double SphereVolume(double radius) => (4.0 / 3.0) * Math.PI * Math.Pow(radius, 3); }

.NET programs can run on any platform. (T/F)

: False. .NET prorgrams run on the Common Language Runtime, which is a virtual machine

(What does this program do?) 1 // Ex. 5.26: Mystery3.cs 2 using System; 3 4 class Mystery3 5 { 6 static void Main() 7 { 8 int row = 10; 9 int column; 10 11 while (row >= 1) 12 { 13 column = 1; 14 15 while (column <= 10) 16 { 17 Console.Write(row % 2 == 1 ? "<" : ">"); 18 ++column; 19 } 20 21 --row; 22 Console.WriteLine(); 23 } 24 } 25 }

>>>>>>>>>> <<<<<<<<<< >>>>>>>>>> <<<<<<<<<< >>>>>>>>>> <<<<<<<<<< >>>>>>>>>> <<<<<<<<<< >>>>>>>>>> <<<<<<<<<<

Describe Form

A Form represents the Windows Forms application that you are creating. The Form and controls collectively represent the program's GUI.

Explain the purpose of an instance variable.

A class provides an instance variable (or several instance variables) when each object of the class must maintain information separately from all other objects of the class. For example, a class called Account that represents a bank account provides an instance variable to represent the balance of the account. Each Account object maintains its own balance and does not know the balances of the bank's other accounts.

Describe control

A control is a component, such as a PictureBox or Label. Controls are added to a Form

What is a default constructor? How are an object's instance variables initialized if a class has only a default constructor?

A default constructor is a constructor provided by the compiler when you do not specify any constructors in the class. When a class has only the default constructor, its instance variables are initialized to their default values. Variables that contain numbers are initialized to 0, variables of type bool are initialized to false, and reference-type variables are initialized to null.

What is a key advantage of interpreters over compilers? What is a key disadvantage?

A key advantage is that interpreters can execute high-level language programs directly (without the need for compilation). A key disadvantage is that interpreted programs exexute more slowly than compiled programs.

What is the difference between a local variable and an instance variable?

A local variable is declared in the body of a method and can be used only in the method in which its declared. An instance variable is declared in a class, but not in the body of any of the class's members. Every object (instance) of a class has a separate copy of the class's instance variables. Also, instance variables are accessible to all members of the class.

(Structured Equivalent of continue Statement) Describe in general how you would remove any continue statement from a loop in an app and replace it with some structured equivalent. Use the technique you develop here to remove the continue statement from the app in Fig. 6.14

A loop can be rewritten without a continue statement by moving all the code that appears in the body of the loop after the continue statement into an if statement that tests for the opposite of the continue condition. Thus, the code that was originally after the continue statement executes only when the if statement's conditional expression is true (i.e., the "continue" condition is false). When the "continue" condition is true, the body of the if does not execute and the application "continues" to the next iteration of the loop by not executing the remaining code in the loop's body. The answer shown here removes the continue statement from the if statement.

A criticism of the break statement and the continue statement (in a loop) is that each is unstructured. Actually, break and continue statements can always be replaced by structured statements, although doing so can be awkward. Describe in general how you would remove any break statement from a loop in an app and replace it with a structured equivalent. [Hint: The break statement exits a loop from the body of the loop. The other way to exit is by failing the loop-continuation test. Consider using in the loop-continuation test a second test that indicates "early exit because of a 'break' condition."] Use the technique you develop here to remove the break statement from the app in Fig. 6.13

A loop can be written without a break by placing in the loop-continuation test a second test that indicates "early exit because of a 'break' condition." Alternatively, the break can be replaced by a statement that makes the original loop-continuation test immediately false, so that the loop terminates.

Describe Menu Bar

A menu bar contains menus, which are groups of related commands.

Describe solution

A solution is a group of projects.

Describe toolbar:

A toolbar contains icons that, when clicked, execute a command.

The properties in the properties window can be sorted ______________ or ___________.

Alphabetically, categorically

Explain why a class might provide a property for an instance variable.

An instance variable is typically declared private in a class so that only the methods (and properties) of the class in which the instance variable is declared can manipulate the variable. In some cases, it may be necessary for an application to modify the private data. A class's designer can provide a public property that enables an application to specify the value for, or retrieve the value of, a private instance variable. The property's set accessor can ensure that the instance variable is set only to valid values. Using properties to access private fields allows the modification of the internal representation of the object without affecting the clients of the class.

The three types of computer programming languages discussed in the chapter are machine languages _______ , _______ and ________

Assembly Languages, High-Level Languages

Microsoft's Windows _________ is a cloud-computing platform that allows you to develop, manage and distribute your apps in the cloud.

Azure. (Instructor Note: "Microsoft's Windows" should be simply "Microsoft" in this exercise.)

___________,__________, and __________ are called whitespace. Newline characters are also considered whitespace.

Blank lines, space characters, tab characters

Describe the two-step translation process for preparing your C# code to execute on your particular computer

C# code is first compiled into MSIL and placed in an executable file. When the app executes, another complier called the JIT (just-in-time) complier in the CLR translates the MSIL in the executable file into machine-language code (for particular platform)

The format specifier _________ is used to display values in a monetary format

C.

You send messages to an object. Each message is implemented as a method ________ that tells a method of the object to perform its task

Call

Objects, or more precisely the _______ that objects come from, are essentially reusable software components

Classes

Why is using cloud-computing resources sometimes preferable to purchasing all the hardware you need for your own computer?

Cloud computing gives you the flexibility to increase or decrease computing resources to meet your resource needs at any given time, making it more cost effective than purchasing expensive hardware to ensure that you have enough storage and processing power at their occasional peak levels.

The _________ executes .NET programs

Common Language Runtime (CLR) of the .NET Framework

What did the chief benefit of the early Internet prove to be?

Communication by e-mail. Today, that communication is also facilitated by applications such as instant messaging and file transfer.

The programs that translate high-level language programs into machine language are called ________

Compliers

Computers process data under the control of sequences of instructions called _________

Computer Programs

Display the message "Enter an integer: " leaving the cursor on the same line.

Console.Write ("Enter an integer: ");

Prompt the user to enter an integer.

Console.Write("Enter an Integer");

Prompt the user to enter the first integer.

Console.Write("Enter first integer");

Prompt the user to enter the second integer.

Console.Write("Enter second integer");

Prompt the user to enter the third integer.

Console.Write("Enter third integer");

Methods ______________ and ___________display information in the console window.

Console.WriteLine and Console.Write.

Display "This is a C# app" on one line in the console window

Console.WriteLine("This is a C# app");

Display the message "Product is", followed by the value of the variable result - use string interpolation.

Console.WriteLine($"Product is {result});

Write a statement that uses string interpolation to display the sum of the variables x and y. Assume variable x and y of type int exist and already have values.

Console.WriteLine($"The sum of {x} and {y} is {x+y}");

Display "This is a C# app" on two lines in the console window. The first line should end with C#. Use method console.writeLine.

Console.WriteLine(This is a C#\napp");

(Combining Control Statements) Describe the two ways in which control statements can be combined.

Control statements can be "attached" (that is, stacked) to one another by connecting the exit point of one to the entry point of the next. Control statements also can be nested by placing one control statement inside another control statement.

Repeating a set of instructions a specific number of times is called __________ repetition.

Counter-Controlled (or definite)

(Choosing Iteration Statements) What type of iteration would be appropriate for calculating the sum of the first 100 positive integers? What type of iteration would be appropriate for calculating the sum of an arbitrary number of positive integers? Briefly describe how each of these tasks could be performed.

Counter-controlled iteration would be appropriate for calculating the sum of the first 100 positive integers, because the number of iterations is known in advance. The application that performs this task could use a while iteration statement with a counter variable that takes on the values 1 to 100. The application could then add the current counter value to the total variable in each iteration of the loop. Sentinel-controlled iteration would be appropriate for calculating the sum of an arbitrary number of positive integers. The application that performs this task could use a sentinel value of -1 to mark the end of data entry. The application could use a while iteration statement that totals positive integers from the user until the user enters the sentinel value.

Describe the four basic elements of counter-controlled iteration.

Counter-controlled repetition requires a control variable (or loop counter), an initial value of the control variable, an increment (or decrement) by which the control variable is modified each time through the loop, and a loop-continuation condition that determines whether looping should continue.

Data items processed by computers form a __________ that becomes larger and more complex in structure as we progress from bits to characters to fields, and so on.

Data Hierarchy

Find the error(s) in each of the following code segments. Explain how to correct the error. a) void G() { Console.WriteLine("Inside method G"); void H() { Console.WriteLine("Inside method H"); } }

Error: Method H is declared within method G. Correction: Move the declaration of H outside the declaration of G.

When an ellipsis button is clicked, a(n) __________ is displayed.

Dialog box

(Integer Division) Explain what happens when a C# app attempts to divide one integer by another. What happens to the fractional part of the calculation? How can you avoid that outcome?

Dividing two integers results in integer division—any fractional part of the calculation is lost (i.e., truncated). For example, 7 ÷ 4, which yields 1.75 in conventional arithmetic, truncates to 1 in integer arithmetic, rather than rounding to 2. To obtain a floating-point result from dividing integer values, you must temporarily treat these values as floating-point numbers in the calculation by using the unary cast operator (double). As long as the (double) cast operator is applied to any variable in the calculation, the calculation will yield a double result which can be assigned to a double variable.

Find the error: int Sum(int x, int y) { int result; result = x + y; }

Error: The method is supposed to return an integer, but does not. Correction: Delete the method's body statements and place the statement return x + y; in the method, or add the following statement at the end of the method body: return result;

Find the errors: The following code should display whether integer value is odd or even: switch (value % 2) { case 0: Console.WriteLine("Even integer"); case 1: Console.WriteLine("Odd integer"); }

Each case should include a break statement.

Find the error: void Product() { int a = 6, b = 5, c = 4, result; result = a * b * c; Console.WriteLine("Result is " + result); return result; }

Error: The method returns a value when it's not supposed to. Correction: Change the return type from void to int.

Find the error: void F(float a); { float a; Console.WriteLine(a); }

Error: The semicolon after the right parenthesis of the parameter list is incorrect, and the parameter a should not be redeclared in the method. Correction: Delete the semicolon after the right parenthesis of the parameter list, and delete the declaration float a;.

Find the errors: a.) i=1;

Error: The semicolon after the while header causes an infinite loop, and there's a missing left brace for the body of the while statement. Correction: Remove the semicolon and add a { before the loop's body

n = 1; while (n < 10) { Console.WriteLine(n++); }

Error: The wrong operator is used in the while iteration-continuation condition. Correction: Use <= rather than <, or change 10 to 11.

Find the errors: for (k = 0.1; k = != 1.0; k += 0.1) { Console.WriteLine(k); }

Error: Using a floating-point number to control a for statement may not work, because floating-point numbers are represented only approximately by most computers. Correction: Use an integer, and perform the proper calculation in order to get the values you desire: for(k = 1; k <10; ++k) { Console.WriteLine(double) k / 10); }

Find the errors: switch (n) { case 1: Console.WriteLine("The number is 1"); case 2: Console.WriteLine("The number is 2"); break; default: Console.WriteLine("The number is not 1 or 2"); break; }

Error: case 1 cannot fall through into case 2. Correction: Terminate the case in some way, such as adding a break statement at the end of the statements for the first case.

Visual C# is __________ driven. You'll write programs that respond to mouse clicks, key strokes, timer expirations and touches and finger swipes

Event

To test for a range of values in a switch statement, use a hyphen (-) between the start and end values of the range in the case label (T/F)

False, the switch statement does not provide a mechanism for testing ranges of values, so you must list every value to test in a separate case label.

The break statement is required in every case of a switch statement (T/F)

False, you could terminate the case with other statements, such as a return.

A property declaration must contain both a get accessor and a set accessor. (T/F)

False. A property declaration can contain a get accessor, a set accessor or both.

A property's get accessor enables a client to modify the value of the instance variable associated with the property (T/F)

False. A property's get accessor enables a client to retrieve the value of the instance variable associated with the property. A property's set accessor enables a client to modify the value of the instance variable associated with the property.

A set of statements contained within a pair of parentheses is called a block (T/F)

False. A set of statements contained within a pair of braces ( {and} ) is called a block.

The Unicode character set is a popular subset of ASCII that represents uppercase and lowercase letters, digits and some common special characters. (T/F)

False. ASCII is a subset of Unicode.

A selection statement specifies that an action is to be repeated while some condition remains true. (T/F)

False. An iteration statement specifies that an action is to be repeated while some condition remains true. A selection statement determines whether an action is performed based on the truth or falsity of a condition.

By convention, method names begin with a lowercase first letter and all subsequent words in the name begin with a capital first letter (T/F)

False. By convention, method names begin with an uppercase first letter and all subsequent words in the name begin with an uppercase first letter.

C# considers the variables number and Number to be identical. (T/F)

False. C# is case sensitive, so these variables are distinct.

Visual Studio C# app developers usually create complex apps without writing any code.

False. C# programming usually involves a combination of writing a portion of the program code and having Visual Studio generate the remaining code.

Comments cause the computer to display the text after the // on the screen when the app executes. (T/F)

False. Comments do not cause any action to be performed when the app executes. They're used to document apps and improve their readability.

Control properties can be modified only by writing code. (T/F)

False. Control properties can be modified using the Properties window.

The form, label, and PictureBox, have identical properties.

False. Each type of control has a different set of properties, although controls can have common properties.

Both forms and labels have a title bar. (T/F)

False. Forms have a title bar but Labels do not (although they do have a Label text)

Local variables are initialized by default. (T/F)

False. Instance variables are initialized by default.

Instance variables of type bool are given the value true by default. (T/F)

False. Instance variables of type bool are given the value false by default.

All instance variables are initialized by default to null. (T/F)

False. Numeric simple-type instance variables are initialized to 0, bool simple-type instance variables are initialized to false and instance variables of all other types are initialized to null.

Sizing handles are visible during execution.

False. Sizing handles are present only in Design view when a Form or control is selected.

Secondary storage data takes much longer to access than data in primary memory, but the cost per unit of secondary storage is much higher than that of primary memory (T/F)

False: The cost per unit of secondary storage is much lower than that of primary memory

Java has become the key programming language for the MAC OS X Desktop operating system an all iOS-based devices, such as iPods, iPhones and iPads (T/F)

False: The language is Swift, not Java

The Transmission Control Protocol (TCP) ensures that messages, consisting of sequentially numbered pieces called bytes, were properly routed from sender to receiver, arrived intact and were assembled in the correct order (T/F)

False: The pieces are called packets, not bytes

The following are all invalid variable names: 3g, 87, 67h2, h22, 2h

False; A variable name can be a combination of alphabets, number and underscores starting with an underscore or an alphabet. h22 is valid.

C# operators are evaluated from left to right (T/F)

False; Generally C# applies the evaluation of operators from left to right. But this order can change according to the precedence of operation of associativity of operations

How does the .NET Framework Class Library facilitate the development of .NET apps?

First, the Framework Class Library is a large library of reusable classes that reduces development time. Programmers can build software quickly by reusing framework's classes, rather than building new classes "from scratch." Second, the Framework Class Library is shared by all of the .NET languages, which means that programmers who work in multiple languages have to learn only one class library

Find the errors: For (i = 100, i >= 1, ++i) { Console.WriteLine(i); }

For should be for. Also, the commas in the for header should be semicolons.

GUI is an acronym for

Graphical User Interface

(Enhanced Guess-the-Number Game) Modify the app of Exercise 7.30 to count the number of guesses the player makes. If the number is 10 or fewer, display Either you know the secret or you got lucky! If the player guesses the number in 10 tries, display Aha! You know the secret! If the player makes more than 10 guesses, display You should be able to do better! Why should it take no more than 10 guesses? Well, with each "good guess," the player should be able to eliminate half of the numbers. Now show why any number from 1 to 1000 can be guessed in 10 or fewer tries.

Guessing the middle number in the range of remaining numbers will always eliminate at least half the numbers (because the number guessed is eliminated as well). Repeatedly halving 1000 yields the values 500, 250, 125, 62, 31, 15, 7, 3, and 1. Because at most one element remains after halving 9 times, the user will always be able to guess by the 10th try.

A computer consists of various devices referred to as _________ , such as the keyboard, screen, mouse, hard disks, memory, DVD drives and processing units.

Harware

Visual studio is a(n) _________ in which C# programs are developed

IDE

Discuss a situation in which it would be more appropriate to use a do...while statement than a while statement. Explain why.

If you want a statement or set of statements to execute at least once, then repeat based on a condition, a do...while is more appropriate than a while (or a for). A do...while statement tests the loop-continuation condition after executing the loop's body; therefore, the body always executes at least once. A while tests the loop-continuation condition before executing the loop's body, so the application would need to include the statement(s) required to execute at least once both before the loop and in the body of the loop. Using a do...while avoids this duplication of code. Suppose an application needs to obtain an integer value from the user, and the integer value entered must be positive for the application to continue. In this case, a do...while's body could contain the statements required to obtain the user input, and the loop-continuation condition could determine whether the value entered is less than 0. If so, the loop would repeat and prompt the user for input again. This would continue until the user entered a value greater than or equal to zero. Once this criterion was met, the loop-continuation condition would become false, and the loop would terminate, allowing the application to continue past the loop. This process is often called validating input.

(Prefix vs. Postfix Increment Operators) What is the difference between the prefix increment operator and the postfix increment operator?

Incrementing a variable with the prefix increment operator causes the variable to be incremented by 1; then the new value of the variable is used in the expression in which it appears. Incrementing a variable with the postfix increment operator causes the current value of the variable to be used in the expression in which it appears; then the variable's value is incremented by 1. The prefix increment and the postfix increment have the same effect when the incrementing operation appears in a statement by itself.

The ability of a program to run without modification across multiple platforms is known as platform _________

Independence

A new class of objects can be created quickly and conveniently by ______—the new class absorbs the characteristics of an existing class, possibly customizing them and adding unique characteristics of its own.

Inheritance

What is the key capability of the web?

It allows computer users to locate and view multimedia-based documents on almost any subject over the Internet.

What is the key accomplishment of the UML?

It replaced the many different graphical modeling languages with a single (unified) language for modeling that can be used by developers regardless of the different OOAD processes they may use.

________________are reserved for use by C#.

Keywords

Arrange these byte measurements in order from smallest to largest: Terabyte, megabyte, petabyte, gigabyte, and kilobyte

Kilobyte, megabyte, gigabyte, terabyte, petabyte

The CLR provides various services to _________ code, such as integrating software components written in different .NET languages, error handling between such components, enhanced security and more

Managed

Write an app that tests whether the examples of the Math class method calls shown in Fig. 7.2 actually produce the indicated results. ANS: Figure 7.1 demonstrates the Math class methods in Fig. 7.2: 1 // Exercise 7.3 Solution: MathTest.cs 2 // Testing the Math class methods. 3 using System; 4 5 class MathTest 6 { 7 static void Main() 8 { 9 Console.WriteLine($"Math.Abs(23.7) = {Math.Abs(23.7)}"); 10 Console.WriteLine($"Math.Abs(0.0) = {Math.Abs(0.0)}"); 11 Console.WriteLine($"Math.Abs(-23.7) = {Math.Abs(-23.7)}"); 12 Console.WriteLine($"Math.Ceiling(9.2) = {Math.Ceiling(9.2)}"); 13 Console.WriteLine($"Math.Ceiling(-9.8) = {Math.Ceiling(-9.8)}"); 14 Console.WriteLine($"Math.Cos(0.0) = {Math.Cos(0.0)}"); 15 Console.WriteLine($"Math.Exp(1.0) = {Math.Exp(1.0)}"); 16 Console.WriteLine($"Math.Exp(2.0) = {Math.Exp(2.0)}"); 17 Console.WriteLine($"Math.Floor(9.2) = {Math.Floor(9.2)}"); 18 Console.WriteLine($"Math.Floor(-9.8) = {Math.Floor(-9.8)}"); 19 Console.WriteLine($"Math.Log(Math.E) = {Math.Log(Math.E)}"); 20 Console.WriteLine($"Math.Log(Math.E * Math.E) = {Math.Log(Math.E * Math.E)}"); 21 Console.WriteLine($"Math.Max(2.3, 12.7) = {Math.Max(2.3, 12.7)}"); 22 Console.WriteLine($"Math.Max(-2.3, -12.7) = {Math.Max(-2.3, -12.7)}"); 23 Console.WriteLine($"Math.Min(2.3, 12.7) = {Math.Min(2.3, 12.7)}"); 24 Console.WriteLine($"Math.Min(-2.3, -12.7) = {Math.Min(-2.3, -12.7)}"); 25 Console.WriteLine($"Math.Pow(2.0, 7.0) = {Math.Pow(2.0, 7.0)}"); 26 Console.WriteLine($"Math.Pow(9.0, 0.5) = {Math.Pow(9.0, 0.5)}"); 27 Console.WriteLine($"Math.Sin(0.0) = {Math.Sin(0.0)}"); 28 Console.WriteLine($"Math.Sqrt(900.0) = {Math.Sqrt(900.0)}"); 29 Console.WriteLine($"Math.Tan(0.0) = {Math.Tan(0.0)}"); 30 } 31 }

Math.Abs(23.7) = 23.7 Math.Abs(0.0) = 0 Math.Abs(-23.7) = 23.7 Math.Ceiling(9.2) = 10 Math.Ceiling(-9.8) = -9 Math.Cos(0.0) = 1 Math.Exp(1.0) = 2.71828182845905 Math.Exp(2.0) = 7.38905609893065 Math.Floor(9.2) = 9 Math.Floor(-9.8) = -10 Math.Log(Math.E) = 1 Math.Log(Math.E * Math.E) = 2 Math.Max(2.3, 12.7) = 12.7 Math.Max(-2.3, -12.7) = -2.3 Math.Min(2.3, 12.7) = 2.3 Math.Min(-2.3, -12.7) = -12.7 Math.Pow(2.0, 7.0) = 128 Math.Pow(9.0, 0.5) = 3 Math.Sin(0.0) = 0 Math.Sqrt(900.0) = 30 Math.Tan(0.0) = 0

A(n) ________ processor implements several processors on a single "microchip" ---a dual-core processor has two CPUs and a quad core processor has four CPUs

Multicore

What are operating systems?

Operating systems are software systems that make using computers more convenient for users, app developers and system administrators. They provide services that allow each app to execute safely, efficiently and concurrently (i.e., in parallel) with other apps.

decimal method ________________ converts a string to a decimal value.

Parse.

What are the advantages to using object-oriented techniques?

Programs that use object-oriented programming techniques are easier to understand, correct and modify. The key advantage with using object-oriented programming is that it tends to produce software that is more understandable, because it is better organized and has fewer maintenance requirements than software produced with earlier methodologies. OOP helps the programmer build applications faster by reusing existing software components that model items in the real world. OOP also helps programmers create new software components that can be reused on future software development projects. Building software quickly, correctly, and economically has been an elusive goal in the software industry. The modular, object-oriented design and implementation approach has been found to increase productivity while reducing development time, errors, and cost.

To create the best solutions, you should follow a detailed analysis process for determining your project's ___________ (i.e, deciding how the system should do it.)

Requirements

The _________ window allows you to browse solution files

Solution Explorer

Find the error: while (y > 0) { Console.WriteLine(y); ++y;

The ++ operator should be changed to --; otherwise the loop will be an infinite loop if y is greater than 0 when the while statement is encountered. The closing curly brace for the while loop is missing.

Describe toolbox

The Toolbox contains controls used to customize forms.

Compare and contrast the break and continue statements.

The break and continue statements alter the flow of control through a control statement. The break statement, when executed in one of the repetition statements, causes immediate exit from that statement. Execution typically continues with the first statement after the control statement. In contrast, the continue statement, when executed in a repetition statement, skips the remaining statements in the loop body and proceeds with the next iteration of the loop. In while and do...while statements, the application evaluates the loop-continuation test immediately after the continue statement executes. In a for statement, the increment expression executes, then the application evaluates the loop-continuation test.

You are probably wearing on your wrist one of the world's most common types of objects— a watch. Discuss how each of the following terms and concepts applies to the notion of a watch: object, attributes and behaviors

The entire watch is an object that is composed of many other objects (the moving parts, the band, the face, etc.) Watch attributes are time, color, band style, technology (digital or analog), and the like. The behaviors of the watch include setting the time and getting the time. A watch can be considered a specific type of clock (as can an alarm clock).

Compare and contrast the if single-selection statement and the while iteration statement. How are these two statements similar? How are they different?

The if single-selection statement and the while repetition statement both perform an action (or set of actions) based on whether a condition is true or false. However, if the condition is true, the if single-selection statement performs the action(s) once, whereas the while repetition statement repeatedly performs the action(s) until the condition becomes false.

Find the errors: The following code should output the odd integers from 19 to 1: for (int i = 19; i >= 1; i += 2) { Console.WriteLine(i); }

The increment i += 2 should be a decrement i -= 2.

What are the key benefits of the .NET Framework and the CLR? What are the drawbacks?

The key benefits are portability between operating systems and interoperability between languages. As long as a CLR exists for a platform, it can run any .NET program. Programmers can concentrate on program logic instead of platform-specific details. Thus, the double compilation (code-to-MSIL, and MSIL-to-machine code) allows for platform independence: Programs can be written once and executed on any platform supporting the CLR—this is known as platform independence. Code written once could easily be used on another machine without modification, saving time and money. A second benefit of the .NET framework is language interoperability— software components written in different languages can interact (language independence). A drawback associated with these features is that .NET programs cannot be run until the .NET Framework is developed for a platform. Another is the overhead of the double compilation that is needed before a .NET-language program can be executed

(Find the Error) Find the error(s) in the following recursive method, and explain how to correct it: static int Sum(int n) { if (n == 0) { return 0; } else { return n + Sum(n); } }

The method never reaches the base case. The recursion step should be: return n + Sum(n - 1);

(What Does This Code Do?) What does the following method do? // Parameter b must be positive to prevent infinite recursion static int Mystery(int a, int b) { if (b == 1) { return a; } else { return a + Mystery(a, b - 1); } }

The method returns the equivalent value of a times b where b is greater than 0

What is the key advantage of using the new async feature in preference to using old-style multithreading?

The new features simplify asynchronous programming, because the compiler hides much of the associated complexity from the developer.

What is the purpose of operator new? Explain what happens when this keyword is used in an app

The purpose of operator new is to create an object of a class. When operator new is used in an application, first a new object of the class to the right of new is created, then the class's constructor is called to ensure that the object is initialized properly.

(Find the Error) Identify and correct the errors in each of the following pieces of code. [Note: There may be more than one error in each piece of code.] a) if (age >= 65); { Console.WriteLine("Age greater than or equal to 65"); } else { Console.WriteLine("Age is less than 65)"; }

The semicolon at the end of the if condition should be removed. The closing double quote of the second Console.WriteLine should be inside the closing parenthesis.

What is wrong with the following while statement? while (z>=0) { sum +=z; }

The value of variable z is never changed in the while statement. Therefore, an infinite loop occurs if the loop-continuation condition (z>=0) is initially true. To prevent an infinite loop, z must be decremented so that it eventually becomes less than 0

Find the error: int x = 1, total; while (x <= 10) { total += x; ++x; }

The variable total should be initialized to zero

Find the error: while (x <= 100) total += x; ++x;

The variable total should be initialized to zero.

Compare and contrast the while and for iteration statements

The while and for repetition statements repeatedly execute a statement or set of statements as long as a loop-continuation condition remains true. Both statements execute their bodies zero or more times. The for repetition statement specifies the counter-controlled-repetition details in its header, whereas the control variable in a while statement normally is initialized before the loop and incremented in the loop's body. Typically, for statements are used for counter-controlled repetition, and while statements for sentinel-controlled repetition. However, while and for can each be used for either repetition type.

What is the key vision of Microsoft's .NET initiative?

To embrace the Internet and the web in the development and use of software.

The ___________ contains the controls that you can add to a form.

Toolbox

A database is a collection of data that's organized for easy access and manipulation (T/F)

True

A nested control statement appears in the body of another control statement. (T/F)

True

An expression containing the || operator is true if either or both of its operands are true (T/F)

True

An interpolated string must begin with a $ before the string literal. (T/F)

True

An object has attributes that it carries along as it's used in a program (T/F)

True

C# provides the arithmetic compound assignment operators +=,-=,*=,and %= for abbreviating assignment expressions. (T/F)

True

High-Level languages allow you to write instructions that look almost like everyday English and contain commonly used mathematical expressions (T/F)

True

If your machine is connected to the Internet, you can browse websites from the Visual Studio IDE.

True

Listing cases consecutively with no statements between them enables the cases to perform the same set of statements. (T/F)

True

Microsoft's Windows operating system is the most widely used desktop operating system worldwide (T/F)

True

One of the W3C's primary goals is to make the web universally accessible to everyone regardless of disabilities, language or culture. (T/F)

True

Pseudocode helps you think out an app before attempting to write it in programming language. (T/F)

True

Reuse helps you build more reliable and effective systems, because existing classes and components often have gone through extensive testing, debugging and performance tuning. (T/F)

True

Software objects model both abstract and real-world things (T/F)

True

Specifying the order in which statements (actions) execute in an app is called program control. (T/F)

True

The Universal Windows Platform (UWP) is designed to provide a common platform (the underlying system on which apps run) and user experience across all of your devices including personal computers, smartphones, tablets and Xbox Live. (T/F)

True

The following are all valid variable names: _under_bar, m928134, t5, j7, her-sales, his_account_total, a, b, c, z, z2

True

The integer after the comma (,) in a format item (e.g., {0,4}) indicates the field width of the displayed string. (T/F)

True

You can add a control to a form by double clicking its control icon in the ToolBox.

True

You can build web-based apps with C# and Microsoft's ASP.NET technology (T/F)

True

A Form's background color is set using the Backcolor property. (T/F)

True.

Each of the following is a form of computer output: data displayed on screens, printed on paper, played as audio or video on PCs and media players, used to control other devices, such as robots, 3D printers and "intelligent" appliances. (T/F)

True.

Empty parentheses following a method name in a method declaration indicate that the method does not require any parameters to perform its task. (T/F)

True.

Pictureboxes typically display images. (T/F)

True.

The body of any method or property is delimited by left and right braces. (T/F)

True.

The number of arguments in the method call must match the number of required parameters in the method declaration's parameter list. (T/F)

True.

Variables or methods declared with access modifier private are accessible only to members of the class in which they're declared. (T/F)

True.

Find the errors: The following code should output the even integers from 2 to 100: counter = 2; do { Console.WriteLine(counter); counter += 2; } While (counter < 100);

While should be while and the loop-continuation condition should use <= rather than <. 6.10

You can sell your own Windows Phone Apps in the __________

Windows Store

A key goal of Java is to be able to write programs that will run on a great variety of computer systems and computer-control devices. This is sometimes called ___________

Write once, run anywhere

For each of the following sets of integers, write a single statement that will display a number at random from the set. Assume Random randomNumbers = new Random() has been defined and use the one-parameter version of method Random.Next. a) 2, 4, 6, 8, 10. b) 3, 5, 7, 9, 11. c) 6, 10, 14, 18, 22.

a) Console.WriteLine(2 + randomNumbers.Next(5) * 2); b) Console.WriteLine(3 + randomNumbers.Next(5) * 2); c) Console.WriteLine(6 + randomNumbers.Next(5) * 4);

a) What does it mean to choose numbers "at random"? b) Why is the Random class useful for simulating games of chance? c) Why is it often necessary to scale or shift the values produced by a Random object? d) Why is computerized simulation of real-world situations a useful technique?

a) Every number has an equal chance of being chosen at any time. b) Because it produces a series of pseudorandom numbers c) To produce random numbers in a specific range. d) It enables more accurate predictions of random events, such as cars arriving at toll booths and people arriving in lines at a supermarket. The results of a simulation can help determine how many toll booths to have open or how many cashiers to have open at specified times.

Categorize each of the following items as either hardware or software: a) CPU b) Compiler c) Input unit d) A word-processor program e) A C# program

a) Hardware. b) Software. c) Hardware. d) Software. e) Software.

Translator programs, such as assemblers and compilers, convert programs from one language (referred to as the source language) to another language (referred to as the target language). Determine which of the following statements are true and which are false: a) An assembler translates source-language programs into machine-language programs. b) High-level languages are generally machine dependent. c) A machine-language program requires translation before it can be run on a computer d) The C# compiler translates high-level-language programs into SMIL.

a) True. b) False. A high-level language must be compiled into machine-dependent language before it can be executed. This allows high-level languages to be used on all computers with appropriate compilers. c) False. A machine-language program is native to a specific machine. d) False. It translates C# into MSIL.

Expand each of the following acronyms: a) W3C b) OOP c) CLR d) MSIL e) UML f) IDE

a) World Wide Web Consortium b) Object-Oriented Programming c) Common Language Runtime d) Microsoft Intermediate Language e) Unified Modeling Language f) Integrated Development Environment

For the class Craps in Fig. 7.8, state the scope of each of the following entities: a) the variable randomNumbers. b) the variable die1. c) the method RollDice. d) the method Main e) the variable sumOfDice

a) class body. b) block that defines method RollDice's body c) class body. d) class body. e) block that defines method Main's body.

Give the method header for each of the following methods: a) Method Hypotenuse, which takes two double-precision, floating-point arguments side1 and side2 and returns a double-precision, floating-point result. b) Method Smallest, which takes three integers x, y and z and returns an integer. c) Method Instructions, which does not take any arguments and does not return a value. [Note: Such methods are commonly used to display instructions to a user.] d) Method IntToDouble, which takes integer argument number and returns a double value.

a) double Hypotenuse(double side1, double side2) b) int Smallest(int x, int y, int z) c) void Instructions() d) double IntToDouble(int number)

Write statements that assign random integers to the variable n in the following ranges. Assume Random randomNumbers = new Random() has been defined and use the two-parameter version of the method Random.Next. a) 1 ≤ n ≤ 2 b) 1 ≤ n ≤ 100 c) 0 ≤ n ≤ 9 d) 1000 ≤ n ≤ 1112 e) -1 ≤ n ≤ 1 f) -3 ≤ n ≤ 11

a) n = randomNumbers.Next(1, 3); b) n = randomNumbers.Next(1, 101); c) n = randomNumbers.Next(0, 10); d) n = randomNumbers.Next(1000, 1113); e) n = randomNumbers.Next(-1, 2); f) n = randomNumbers.Next(-3, 12);

Assume that i = 1, j = 2, k = 3 and m = 2. What does each of the following statements display? a. Console.WriteLine(i == 1); b. Console.WriteLine(j == 3); c. Console.WriteLine((i >= 1) && (j < 4)); d. Console.WriteLine((m <= 99) & (k < m)); e. Console.WriteLine((j >= i) || (k == m)); f. Console.WriteLine((k + m < j) | (3 - j >= k)); g. Console.WriteLine(!(k > m));

a. true. b. false. c. true. d. false. e. true. f. false. g. false.

Identify and correct the errors in each of the following sets of code: a. while (c<=5) { product *=c; ++c; b. if (gender==1) { Console.WriteLine("Woman"); else; { Console.WriteLine("Man");

a. Error: The closing right brace of the while statement's body is missing. Correction: Add a closing right brace after the statement ++c; b. Error: The semicolon after else results in a logic error. The second output statement will always execute. Correction: Remove the semicolon after else.

Which of the following C# statements contain variables whose values are modified? a. p=i+j+k+7; b. Console.WriteLine("variables whose value are modified"); c. Console.WriteLine("a=5"); d. value=int.Parse(Console.ReadLine());

a. The statement contains a variable whose value can be modified. (P is being modified) b. In the statement there is no variable whose value cannot be modified c. In the statement there is no variable whose value cannot be modified d. The statement contains a variable whose value can be modified

Identify and correct the errors in each of the following statements. a. if (C<7); { Console.WriteLine("c is less than 7"); } b. if (c=>7) { Console.WriteLine("c is equal to or greater than 7"); }

a. error: Semicolon after the right parenthesis of the condition (c<7) in the if statement. correction: Remove the semicolon after the right parenthesis. b. Error: The relational operator => is incorrect correction: Change => to >=

Calculations are normally performed by _______ statements.

assignment

The _________ feature hides a window in the IDE.

auto-hide

For a(n) ____________, the complier automatically generates a private instance variable and set and get accessors.

auto-implemented property.

Every class declaration contains keyword ___ followed immediately by the class's name.

class

In object-oriented programming languages, we create a program unit called a(n) ________ to house the set of methods that perform its tasks.

class

_________ are used to document an app and improve its readability.

comments

Translator programs called ____________ convert high-level language code into machine language code.

compilers

Variables of type __________ are typically used to represent monetary amounts.

decimal.

(Write a C# statement) Calculate the value of 2.5 raised to the power of 3, using the Pow method.

double result = Math.Pow(2.5,3);

Systems such as smartphones, appliances, game controllers, cable set-top boxes and automobiles that contain small computers are called ___________

embedded systems

Just as characters are composed of bits, __________ are composed of characters or bytes.

fields

(Write a C# statement) Display the integers from 1 to 20 using a for loop and the counter variable i. Assume that the variable i has been declared, but not initialized. Display only 5 integers per line. [Hint: Use the calculation i%5. When the value of this expression is 0, display a newline character; otherwise, display a tab character. Use the Console.WriteLine() method to output the newline character, and use the Console.Write('\t') method to output the tab character.]

for (i=1; i <=20; ++i) { Console.Write(i); if(i%5==0) { Console.WriteLine(); } else { Console.Write('\t'); } }

(Write a C# statement) Display the integers from 1 to 20 using a while loop and the counter variable i. Assume that the variable i has been declared, but not initialized. Display only 5 integers per line. [Hint: Use the calculation i%5. When the value of this expression is 0, display a newline character; otherwise, display a tab character. Use the Console.WriteLine() method to output the newline character, and use the Console.Write('\t') method to output the tab character.]

i=1; while (i <= 20) { Console.Write(i); if (i%5==0) { Console.WriteLine(); } else { Console.Write('\t'); } ++i; }

The ______________ statement is used to make decisions.

if

If the variable number is not equal to 7, display "The variable number is not equal to 7".

if (number !=7) { Console.WriteLine("The variable number is not equal to 7"); }

A decision can be made in a C# app with a(n) ___________

if-statement

The ______________ statement is used to execute one action when a condition is true and another when that condition is false.

if....else

The _________ property specifies which image a PictureBox displays.

image

When each object of a class maintains its own copy of an attribute, the field that represents the attribute is also known as ____________.

instance variable.

Declare variables c, thisIsAVariable, q76354 and number to be of type int.

int c; int thisIsAVariable; int q76354; int number;

a. declare the int variable b. declare the int variable x and initialize it to 1 c. add variable x to the variable sum, and assign the result to variable sum d. display "the sum is: ", followed by the value of variables sum.

int sum = 0; int x = 1; sum += x; or sum = sum +x; Console.WriteLine($"The sum is: {sum}");

Declare the variables x,y,z, and result to be of type int.

int x; int y; int z; int result;

Operator _____ creates an object of the class specified to the right of the keyword.

new.

Information on secondary storage devices is __________; it's preserved even when the computer's power is turned off.

persistent

Converting a program to run on a different platform from which it was originally intended is called __________

porting

If the increment operator is _______ to a variable, first the variable is incremented by 1, then its new value is used in the expression.

prefixed

Determine the values of the variables in the the following statement after it executes. Assume that when the statement begins executing, all variables are type in and have the value 5. product *= x++

product = 25, x = 6

Calculate the remainder after q is divided by divisor, and assign the result to q. Write this statement in two different ways.

q %= divisor; q = q % divisor;

Compute the product of the three integers contained in variables x, y and z, and assign the result to the variable result.

result =x*y*z;

The programs that run on a computer are referred to as______

software

A(n) ___________ is a group of one or more projects that collective form a Visual studio C# app.

solution

Methods that perform common tasks and cannot be called on objects are called ________ methods.

static

__________enables you to insert values directly into a strong literal.

string interpolation

C# requires all variables to have a(n) __________

type

Each parameter must specify both a(n) _____ and a(n) ______.

type, name.


Set pelajaran terkait

French: Chapter 1 (Une Amie et Un Ami)

View Set

6.19.M - Lesson: Using Electricity

View Set

CompTIA A+ Certification Exam 220-1101 Practice Test 1

View Set

Physics Study Guide (Forces and the Laws of the Motion)

View Set

Inflammation practice questions

View Set

Econ Midterm two Review Questions Set 6

View Set

2018 Business Past Paper, 2017 Business Past Paper, 2016 Business Past Paper, SAM 2015 Business Past Paper

View Set