Starting Out in C# - Chapter 3 Questions

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

order of operations

PEMDAS

summarize the mathematical order of operations

PEMDAS

panel control

Panel control is like a group box but does not have a tile, text property and the border style can be changed.

In code, how do you retrieve data that has been typed into the TextBoxControl?

Retrieving the contents of the control's Text property.

What kind of code does the try block of a try-catch statement contain?

Statements that could potentially throw an exception

What type of data does a control's Text property always contain?

String

What control can be used to gather text input from the user?

TextBox Control

What access modifier should you use when declaring a field? why?

private field because in prevents code from outside the class from changing the values of a class's field preventing bugs

Will the following cause an error, why or why not? string luckyNumber = 7;

yes because it defines the data type of string but does not include the number 7 in double quotes to make it a string.

exception object

a variable created in memory when an exception is thrown that stores data about the exception

field

a variable declared in a class instead of an individual method

try-catch statement

A type of exception handler which has the program "try" a group of arguments, and if they fail, ''catch" the failure.

what value with the wholePieces variable contain after the following code executes? double totalPieces = 6.5; int wholePieces = (int)totalPieces;

6

assume the result is an int variable. When the following statement executes, what value will be stored in result? result = (2 + 5) * 10;

70

Assume the result is a double variable. When the following statement executes what value will be stored in result? result = 4 + 10 / 2;

9

parse

A family of methods in the .NET Framework which means to analyze a string of character for some purpose.

what value will be displayed in the message box when the following code segment is executed? double apples = 12.0; MessageBox.Show (apples.ToString("N0"));

12

assume result is a double variable. When the following statement executes what value will be stored in result? result = 5/2;

2.5

access key

Also known as a mneumonic; a key that is pressed in combination with the Alt key to access quickly a control such as a button

Assuming the variable greeting has not been assigned a value, what will be the result of the following statement MessageBox.Show(greeting);

An error

exception

An unexpected error that occurs while a program is running, causing the program to halt.

How can you display the default error message when an exception is thrown?

Assign name to the exception object when writing the catch clause of a try-catch statement and then use the Message property of the exception object in the catch block to display the default error message in a message box

How do you get out of break mode when an exception is thrown?

Click Stop debugging button or pressing Shift + F5

primitive data types

Data types which hold fundamental types of data such as strings, integers and real numbers

What is the lifetime of a variable that is declared inside of a click event handler

From the click to when the code concludes

List the operands for the following math expression. length * width

Length, Width

what method of the math class can be used to determine larger of two values?

Math.Max

what method of the Math class can be used to determine the smaller of two values?

Math.Min

Write a programming statement that displays the string value of a variable named salary in a message box using currency format.

Messagebox.Show(salary.ToString("c"));

math operators

The item that defines what to do with values in a math expression (+, -, =, etc)

What are two advantages of using named constants?

They make the program more self-explanatory and allow for widespread changes to easily be made to the program.

What is the purpose of a variable?

To store a value in memory

cancel button

a button on a form that is automatically clicked when the user presses the escape key

constant field

a field that cannot be changed by any statement in the class. exception will occur if a statement attempts to change a constant field.

How is the lifetime of a field different from the lifetime of a local variable?

a local variable exists only while the method in which it is declared is executing but a field exists as long as the form exists.

numeric literal

a number written into the programs code.

argument

a piece of data passed into a method

TextBox control

a rectangular area on a form that when the application is running, the user can type text into it. The program can then retrieve the text that the user entered and use it in any necessary operations.

break mode

a special window which appears when an exception occurs and displays which line of code caused the error.

variable

a storage location in memory that is represented by a name.

Write a statement that displays each of the following numeric variables in a message box a. grandTotal b. highScore c. sum d. width

a. Messagebox.Show(grandtotal.ToString( )); b. Messagebox.Show(highScore.ToString( )); c. Messagebox.Show(sum.ToString( )); d. Messagebox.Show(width.ToString( ));

Rewrite the following statements using combined assignment operators: a. count = count + 1; b. amount = amount - 5; c. radius = radius * 10; d. length = length / 2;

a. count =+ 1; b. amount =- 5; c. radius =* 10; d. length =/ 2;

specify the appropriate primitive numeric data type for each of the following values. a. 24 dollars b. 12 bananas c. 14.5 inches d. 83 cents e. 2 concert tickets

a. decimal b. int c. double d. decimal e. int

write a statement that converts each of the following string values to the decimal data type using the decimal.parse method. a. "9.05" b. grandTotal c. "50" d. priceTextBox.Tex

a. decimal.parse("9.05"); b. decimal.parse(grandTotal); c. decimal.parse("50"); d. decimal.parse(priceTextbox.Text);

for each of the following items, determine whether the data type should be an integer, string, or real number. a. Pet name b. Sales Tax c. Mailing Address d. Video Game Score

a. string b. real number c. string d. integer

Indicate whether each of the following is a legal variable name. if not, why? a. pay_Rate b. speed of sound c. totalcost d. 2ndPlaceName

a. yes b. no spaces are not allowed c. yes d. no, a number cannot start a variable name

ForeColor

allows you to change the color of the text.

BackColor property

allows you to change the objects background color

ToString Method

allows you to convert variables to string values

What can cause an application to throw an exception?

an unexpected error while the program is running, such as user input that is not in the correct format

where should you place field declarations in a program?

at the top of a class declaration, before any methods

Which of the following will cause an error, why? a. decimal payRate = 24m; b. int player score = 1240.5; c. double box width 205.25; d. string lastName = "Holm";

b. because variables of the int data type can be assigned only whole-number values.

local variable

belongs to the method in which it is declared and only statements inside that method can access the variable.

accept button

button on a form that is automatically clicked when a user presses the enter key

How do you clear the contents of a Textbox Control?

by assigning the string " " to the TextBox

catch block

catch followed by a group of one or more statements enclosed by brackets

exception handler

code that responds to exceptions when they're thrown and prevents the program from crashing

focus method

code to move the focus from one object to another

concatenation

common operation performed on string adding one string to the end of another using the + operator.

Write a programming statement that declares a named constant for a 10 percent discount.

const double DISCOUNT = 0.1;

TabIndex property

contains a numeric value which indicates a control's position in the tab order

decimal.parse method

converts a string into a decimal

double.parse method

converts a string into a double

int.Parse method

converts string into an integer

Rewrite the following code segment so that it does not cause an error. decimal pricePerFoot = 2.99m; double boardLength = 10.5; decimal total cost = boardLength * pricePerFoot

decimal pricePerFoot = 2.99m; double boardLength = 10.5; decimal total cost = (decimal)boardLength * pricePerFoot;

tab order

defines in which order controls receive focus

combined assignment operators

designed specifically for common operations used in programing.

write a programming statement that uses the math.Pow method to square the number 12 and store the result in a double variable named product.

double product = Math.Pow(12.0, 2.0);

initialize

give variable a string

What will be stored in the message variable after the following statement is executed ? string message = "he" + "ll" + "o!";

hello

variable name

identifies the variable in the code.

What causes the program to jump to the catch clause and execute the catch block of a try-catch statement?

if a statement in the try block throws an exception

formatting string

indicates how you want a number to appear, formatted in a specific way. (using N & C for example)

write a programming statement that will convert the following decimal variable to an int and store the result in an int variable named dollars: decimal deposit = 976.54m;

int dollars = (int)deposit;

What method converts the string literal "40" to a value of the int data type?

int.Parse

Write a programming statement that uses the ToString Method of a variable named millimeters so that it displays a precision of four digits after the decimal point in fixed-point scientific format.

millimeters.ToString("f4");

tab order selection mode

mode to change and define the tab order of a form.

Write a programming statement that gives the focus to a TextBox control named numberTextBox

numberTextBox.Focus( );

decimal literal

numeric literal treated as a decimal.

double literal

numeric literal treated as a double

integer literal

numeric literal treated as an integer

catch clause

one or more statements enclosed in brackets defining what happens when an exception occurs

How do you display a form in tab order selection mode? How do you exit tab order selection mode?

open the tab order selection mode

math expression

performs a calculation and gives a value

Write a programming statement that declares a constant field for a 5.9 percent interest rate

private const decimal INTEREST_RATE = 0.059m;

GroupBox Control

rectangular control that appears with a thin border and optional title as a container to hold other controls.

write a statement that will store the value of an int variable named result in the Text property of a label control named resultLabel.

resultLabel.Text = result.ToString( );

access modifier

specifies how a class member can be accessed by code outside of the class

variable declaration

specifies the variables name and data type

Give an example of a variable declaration that will store the value of your favorite food.

string favoritefood = "Pizza";

Write a single declaration statement for the variables name, city and state

string name, city, State

What happens if you press the Enter key while a Button control has the focus?

the button's click event handler will execute

focus

the item that receives the user's keyboard input

scope

the part of a program in which a variable can be accessed.

truncation

the process of dropping a numbers fractional part

Suppose an application has a decimal variable named total and a label control named totalLabel what would be the result when the following assignment statement is executed? totalLabel.Text = total;

the result will be an error because numeric values cannot be assigned to strings.

lifetime

the time period during which the variable exists in memory while the program is executing. based on the scope of the variable.

data type

the type of data a variable will hold

operands

the values on the left and right of the operator (*, /, +, etc)

cast opperator

used to explicitly convert a value from one numeric data type to another, with the understanding that changing data types may result in a loss of data


संबंधित स्टडी सेट्स

Digital Email Marketing Strategies

View Set

Intermediate Accounting - Chapter 5

View Set

ACT study guide Math: Equation of a Line

View Set