• Shuffle
    Toggle On
    Toggle Off
  • Alphabetize
    Toggle On
    Toggle Off
  • Front First
    Toggle On
    Toggle Off
  • Both Sides
    Toggle On
    Toggle Off
  • Read
    Toggle On
    Toggle Off
Reading...
Front

Card Range To Study

through

image

Play button

image

Play button

image

Progress

1/59

Click to flip

Use LEFT and RIGHT arrow keys to navigate between flashcards;

Use UP and DOWN arrow keys to flip the card;

H to show hint;

A reads text to speech;

59 Cards in this Set

  • Front
  • Back

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

A TextBox control

In code, how do you retrieve data that has been typed into a TextBox control?

Retrieve the contents of the control’s Text property

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

A string

How do you clear the contents of a TextBox control?

Assign an empty string ( "" ) to the Text property.

What is the purpose of a variable?

To store a value in memory

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

string myFavoriteFood = "pizza";

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 it is not, explain
why.
a. pay_Rate
b. speed of sound
c. totalCost
d. 2ndPlaceName

a. Legal
b. Illegal; spaces are not allowed in variable names.
c. Legal
d. Illegal; first character of the variable name cannot be a number.

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

The string "Hello!"

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

While the event is executing; then it is deleted.

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

The statement will result in an error.

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

Yes, string variables can be assigned only string values.

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

string name, city, state;

Specify the appropriate primitive numeric data type to use 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

Which of the following variable declarations will cause an error? Why?
a. decimal payRate = 24m;
b. int playerScore = 1340.5;
c. double boxWidth = 205.25;
d. string lastName = "Holm";

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

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 value will the wholePieces variable contain after the following code
executes?
double totalPieces = 6.5;
int wholePieces = (int)totalPieces;

6

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

length and width

Summarize the mathematical order of operations.

1. Perform any operations that are enclosed in parentheses.
2. Perform any multiplications, divisions, or modulus operations as they appear
from left to right
3. Perform any additions or subtractions as they appear from left to right.

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

decimal pricePerFoot = 2.99m;
decimal boardLength = 10.5;
decimal totalCost = boardLength * pricePerFoot;
or
decimal pricePerFoot = 2.99m;
double boardLength = 10.5;
decimal totalCost = (decimal)boardLength * pricePerFoot;

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

9

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

70

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

2.5

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;

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

int.Parse

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.Text

a. decimal.Parse("90.5");
b. decimal.Parse(grandTotal);
c. decimal.Parse("50");
d. decimal.Parse(priceTextBox.Text);

Suppose an application has a decimal variable named total and a Label control
named totalLabel . What will 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.

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());

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();

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"));

The following variable names give an indication of the data each stores. For each
variable, specify the format string that you think is most appropriate.
a. discountPercentage
b. atomicWeight
c. retailPrice
d. quantityPurchased
e. degreesKelvin

a. "P" or "p" for percent format
b. "E" or "e" for exponential scientific format
c. "C" or "c" for currency format
d. "N" or "n" for number format
e. "F" or "f" for fixed-point scientific format

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

Examine the following integer variables and specify the number of leading zeros to
use with the d or D format strings so that all the numbers are equal in width.
int valueA = 234, valueB = 56, valueC = 7, valueD = 89123;

"d5"

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");

What can cause an application to throw an exception?

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

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

Click the Stop Debugging button or by pressing shift+F5

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

Statements that can potentially throw an exception

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

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

Assign a 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.

Write a try - catch statement for an application that calculates the sum of two
whole numbers and displays the result. The application uses two TextBox controls
named value1TextBox and value2TextBox to gather the input and a Label
control named sumLabel to display the result.

try
{
int value1; // To hold value 1.
int value2; // To hold value 2.
int sum; // To hold the sum.
// Get the values as input from the user.
value1 = int.Parse(value1TextBox.Text);
value2 = int.Parse(value2TextBox.Text);
// Calculate the sum of value 1 and value 2.
sum = value1 + value2;
// Display the result in the Label control.
sumLabel.Text = sum.ToString();
}
catch (Exception ex)
{
// Display the default error message.
MessageBox.Show(ex.Message);
}

What are two advantages of using named constants?

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

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

const double DISCOUNT = 0.9;

Where should you place field declarations in a program?

At the top of a class declaration, before any methods

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

It’s a good programming practice to make fields private because private fields
are hidden from code outside the class. That prevents code outside the class from
changing the values of a class’s fields and helps prevent bugs from creeping into
your program.

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.

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

private const decimal INTEREST_RATE = 0.059m;

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);

What method of the Math class can be used to determine the larger of two
values?

Math.Max

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

Math.Min

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

The button’s Click event handler will execute.

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

Click View on the Visual Studio menu bar and then click Tab Order . Exit tab
order selection mode by pressing the Esc key.

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

numberTextBox.Focus();

How do you assign an access key to a Button control?

In the Text property, place an ampersand (&) before the character you wish to
use as the access key.

How do you display an ampersand (&) character on a Button control?

In the Text property, place two ampersand (&&) characters where you would
like the single ampersand to appear on the Button control.

Write the code that will change the BackColor property of a Label control named
resultLabel to the color white and the ForeColor property to the color red.

resultLabel.BackColor = Color.White;
resultLabel.ForeColor = Color.Red;

List the different values of a form’s BackgroundImageLayout property.

None, Tile, Center, Stretch, and Zoom

When a GroupBox control is deleted, what happens to the controls that are inside?

The controls inside the GroupBox control are also deleted.

How are the TabIndex properties of the controls inside the group box organized?

The TabIndex values of controls inside a group box are organized relative to the
GroupBox control’s TabIndex property.

How is a Panel control different from a GroupBox control?

A Panel cannot display a title and does not have a Text property. A Panel’s
border can be specified by its BorderStyle property.