CH 2 Using Data

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

String interpolation

(also called variable substitution) The process of replacing string place holders with values. -C# also includes a ________ ____________ feature that allows you to use a dollar sign in place of the String.Format() method call

Implicit conversion

(or implicit cast) The conversion that occurs when a type is automatically changed to another upon assignment.

Implicit cast

(or implicit conversion) The automatic transformation that occurs when a value is assigned to a type with higher precedence.

Scientific

*Format Specifier* (exponential) E or e

Currency

*Format Specifier* C or c

Decimal

*Format Specifier* D or d

Fixed point

*Format Specifier* F or f

General

*Format Specifier* G or g

Number

*Format Specifier* N or n

Percent

*Format Specifier* P or p

Round trip

*Format Specifier* R or r

Hexadecimal

*Format Specifier* X or x

sbyte

*Integral data types* An integral data type that can hold a signed numeric value from −128 through 127.

long

*Integral data types* An integral data type that can hold a signed numeric value in eight bytes.

short

*Integral data types* An integral data type that can hold a signed numeric value in two bytes.

ulong

*Integral data types* An integral data type that can hold an unsigned numeric value in eight bytes.

uint

*Integral data types* An integral data type that can hold an unsigned numeric value in four bytes.

ushort

*Integral data types* An integral data type that can hold an unsigned numeric value in two bytes.

double

A data type that can hold a floating-point number with 15 or 16 significant digits of accuracy. -For example, a _________ given the value 123456789.987654321 will appear as 123456789.987654 because it is accurate to only the fifteenth digit (the sixth digit to the right of the decimal point).

float

A data type that can hold a floating-point number with as many as seven significant digits of accuracy. -For example, a ________ assigned the value 1234.56789 will appear as 1234.568 because it is accurate only to the seventh digit (the third digit to the right of the decimal point).

string

A data type that can hold a series of characters. -expressed within double quotation marks -example: string firstName = "Jane";

bool

A data type that holds a Boolean value. -has no true maximum or minimum, but you can think of true as the highest and false as the lowest

Data type

A description of the format and size of a data item as well as the operations that can be performed on it.

decimal

A floating-point data type that has a greater precision and a smaller range than a float or double, which makes it suitable for financial and monetary calculations. -a __________ is significant to 28 or 29 digits -cannot hold as large a value as a double can, but the __________ will be more accurate to more decimal places

Type precedence

A hierarchy of data types used to determine the unifying type in arithmetic expressions containing dissimilar data types.

Enumeration

A list of values in which names are substituted for numeric values. -a set of constants represented by identifiers -you create an _____________ using the keyword enum and an identifier, followed by a comma-separated list of constants between curly braces -by convention, the identifier begins with an uppercase letter

Screaming caps

A naming style that uses all uppercase letters and underscores; often used for named constants.

Placeholder

A number within curly braces that holds a position for a variable value within a string. -the first position is always position 0

Scientific notation

A numeric expression format that includes an E (for exponent) and that specifies a number of implied decimal places. -if you store a value that is too large (or too small) in a floating-point variable, you will see output expressed in ____________ _____________

Interactive program

A program that allows user input. -you can use the ReadLine() method to create an ____________ ______________ that accepts user input from the keyboard -the characters can be assigned to a string -for example, the following statement accepts a user's input and stores it in the variable myString: myString = ReadLine();

Culture

A set of rules that determines how culturally dependent values such as money and dates are formatted.

Escape sequence

A single character composed of two symbols beginning with a backslash that represents a nonprinting character such as a tab. -examples: char aBackspaceChar = '\b'; char aTabChar = '\t';

Precision specifier

A specifier that controls the number of significant digits or zeros to the right of the decimal point in a format string.

Assignment

A statement that provides a variable with a value.

Format string

A string of characters that controls the appearance of output. -it optionally contains fixed text and contains one or more format items or placeholders for variable values

Literal constant

A value that is taken literally at each use.

Boolean variable

A variable that can hold only one of two values: true or false. -you declare a ___________ ___________ by using the data type bool -examples: bool isItMonday = false; bool areYouTired = true;

Integer

A whole number without a fractional part.

Enumeration

After you have created an ______________, you can declare variables of the ______________ type, and you can assign _____________ values to them. -For example, you can use the following statements to declare payrollDay as data type DayOfWeek, and assign a value to it: DayOfWeek payrollDay; payrollDay = DayOfWeek.TUESDAY;

Lexically

Alphabetically.

Alias

An alternative name or pseudonym. -each C# intrinsic type in an _______, or other name, for a class in the System namespace

Initialization

An assignment made when a variable is declared. -an assignment made later is simply an assignment

Named constant

An identifier for a memory location whose contents cannot change. -example: const double TAX_RATE = 0.06; (programmers use all caps, and underscores for readability, so that a reader is less likely to confuse them with variable names)

Prompt

An instruction to the user to enter data.

int

An integral data type that can hold a signed numeric value in four bytes. -represents an integer

char

An integral data type that can store any single character such as 'A', '4', or '$'. -________ values are written between single quotation marks. -examples: char initial = 'D'; char aCharValue = '9';

Add and assign operator

An operator that adds the operand on the right to the operand on the left and assigns the results to the operand on the left in one step. -example: balanceDue -= payment subtracts a payment from balanceDue and assigns the result to balanceDue

Comparison operator

An operator that compares two values; an expression containing a ____________ _____________ has a Boolean value. -6 of them: >Less than (<) >Greater than (>) >Equal to (==) >Less than or equal to (<=) >Greater than or equal to (>=) >Not equal to (!=) -example: bool isBigger = 6 > 5; bool isHighTaxBracket = annualIncome > 100000;

Decrement operator

An operator that consists of two minus signs and that reduces a variable's value by 1; there is a prefix and a postfix version. -For example, if s and t are both assigned the value 34, then the expression --s has the value 33 and the expression t-- has the value 34, but t then becomes 33.

Postfix increment operator

An operator that evaluates a variable and then adds 1 to it. -This operator is represented by two plus signs (++) after a variable. -can only use with variables, not constants -example: int anotherValue = 56; anotherValue++; >these statements result in anotherValue holding 57.

Prefix increment operator

An operator that increases the variable's value by 1 and then evaluates it. -This operator is represented by two plus signs (++) before a variable. -can only use with variables, not constants -example: int someValue = 6; ++someValue; >these statements result in someValue holding 7.

Implicitly

Automatically. -Contrast with explicitly.

Intrinsic types

Basic, built-in data types -C# provides 15 intrinsic types. -most common built-in data types: >int >double >decimal >char >string >bool

Hexadecimal

Because 16-bit numbers are difficult to read, programmers often use a shorthand notation called ____________, or base 16. -example: the letter A is stored in computer memory as a set of 16 zeros and ones -- 0000 0000 0100 0001 >in this shorthand notation, 0000 becomes 0, 0100 becomes 4, and 0001 becomes 1 >thus, the letter A is represented as 0041 >you tell the compiler to treat the four-digit ______________ 0041 as a single character by preceding it with the \u escape sequence >thus, there are two ways to store the character A: char letter = 'A'; char letter = '\u0041';

Integral data types

Data types that store whole numbers; the nine types are byte, sbyte, short, ushort, int, uint, long, ulong, and char. -the first 8 always represent whole numbers, and the ninth type, char, is used for characters such as A or a

Constant

Describes a data item when it cannot be changed after a program is compiled; in other words, when it cannot vary.

Type-safe

Describes a data type for which only appropriate behaviors are allowed.

Floating-point

Describes a number that contains decimal positions. -described as having varying numbers of significant digits -three data types: >float >double >decimal

Self-documenting

Describes a program element that is self-explanatory.

Simple types

Describes one of the following in C#: byte, sbyte, short, ushort, int, uint, long, ulong, float, double, decimal, char, and bool. -all of the built-in types except object and string are called *this*

Integer by integer

Even though you define a result variable as a floating-point type, integer division still results in an integer. -The statement double d = 7 / 2; results in d holding 3, not 3.5, because the expression on the right is evaluated as _____________-_____-_____________ division before the assignment takes place. If you want the result to hold 3.5, at least one of the operands in the calculation must be a floating-point number

False

If answer if a double with a value of 10.0, then the following is valid: int deptNum = answer; *hint: a double cannot be implicitly converted to an int*

True

If deptNum is an int with a value of 10, then the following is valid: double answer = deptNum;

True

If value is a double with a value of 12.2, then the following is valid: double answer = (int)value;

Immutable

In C#, a string is _____________ (unchangeable). -That is, a string's value is not actually modified when you assign a new value to it. For example, when you write name = "Amy"; followed by name = "Donald";, the first literal string of characters, Amy, still exists in computer memory, but the name variable no longer refers to that string's memory address. Instead, name refers to a new address where the characters in Donald are stored.

double

Just as an integer constant is an int by default, a floating-point number constant is a __________ by default -to explicitly store a constant as a float, you place an F (either lowercase or uppercase) after the number: float pocketChange = 4.78F; -to explicitly store a value as a decimal, use an M (or m) after the number (M stands for monetary)

static

Methods like Compare() that are not preceded with an object and a dot when they are called are ____________ methods

instance

Methods like CompareTo() that are preceded with an object and a dot are nonstatic and are ___________ methods

Format specifier

One of nine built-in format characters in a format string that defines the most commonly used numeric format types.

Binary operators

Operators that use two operands: one value to the left of the operator and another value to the right of it.

Unary operators

Operators used with one operand. -the prefix and postfix increment operators are __________ __________ because you use them with one operand

Explicit cast

Purposefully assigns a value to a different data type; it involves placing the desired result type in parentheses followed by the variable or constant to be cast.

Explicitly

Purposefully. -Contrast with implicitly.

Operator precedence

Rules that determine the order in which parts of a mathematical expression are evaluated. Also called order of operation. 1. Parentheses 2. Multiplication 3. Division 4. Remainder 5. Addition 6. Subtraction

Associativity

Specifies the order in which a sequence of operations with the same precedence are evaluated.

Significant digit

Specify the mathematical accuracy of a value. -for example: in the statement "The population of New York City is 8,000,000," there is just one ____________ ___________-- the 8. The zeros serve as placeholders and are meant to approximate the actual value

Standard numeric format strings

Strings of characters expressed within double quotation marks that indicate a format for output. -they take the form X0, where X is the format specifier and 0 is the precision specifier

Digit separators

Symbols used to separate the digits in a long number for readability; in C# the underscore ( _ ) is *this*.

Substring

The _____________() method can be used to extract a portion of a string from a starting point for a specific length.

Assignment operator

The equal sign ( = ); any value to the right of the assignment operator is assigned to, or taken on by, the variable or constant to the left.

Formatted string

The following statements create a ____________ ____________ and then displays it. -the curly braces that contain a digit create a placeholder {0} into which the value of someMoney is inserted because it is the first variable -You can also use WriteLine() or Write() in place of String.Format()

Variable declaration

The statement that names a variable; it includes a data type, an identifier, an optional assignment operator and assigned value, and an ending semicolon. -you must declare all variables you want to use in a program -examples: >with an initialization value: int myAge = 25; >assigns a new value to the variable: myAge = 42; >without an initialization value: int myAge; >multiple variables with the same type: int myAge = 25, yourAge = 19;

Unifying type

The type chosen for an arithmetic result when operands are of dissimilar types. -C# chooses a __________ ________ for the result and implicitly converts nonconforming operands to the ___________ ____________, which is the type with the higher type precedence

Operands

The values that operators use in expressions.

Parse

To break an item into component parts. -example: string itemPriceAsString; double itemPrice; itemPrice = double.Parse(itemPriceAsString);

Concatenate

To join strings together in a chain with a plus sign. -example: WriteLine("The money is $" + someMoney);

Explicit

Two __________ casts are performed in the following code. The value of bankBalance / 4 is implicitly a double because a double divided by an int produces a double. The ______________ cast then converts the double result to a float before it is stored in weeklyBudget. Similarly, the float value weeklyBudget is cast to an int before it is stored in dollars (and the decimal-place values are lost).

Arithmetic operators

Used to perform arithmetic -they include: +, -, *, /, and %.

Constant

What's the answer to number 1? If you use the number 347 within a C# program, then 347 is a _____1______, and every time you execute the program, the value 347 will be used. You can refer to the number 347 as a _____2_____ _____2______, because its value is taken literally at each use. On the other hand, when you want a data item's value to be able to change, you can create a ________3________.

Literal constant

What's the answer to number 2? If you use the number 347 within a C# program, then 347 is a _____1______, and every time you execute the program, the value 347 will be used. You can refer to the number 347 as a _____2_____ _____2______, because its value is taken literally at each use. On the other hand, when you want a data item's value to be able to change, you can create a ________3________.

Variable

What's the answer to number 3? If you use the number 347 within a C# program, then 347 is a _____1______, and every time you execute the program, the value 347 will be used. You can refer to the number 347 as a _____2_____ _____2______, because its value is taken literally at each use. On the other hand, when you want a data item's value to be able to change, you can create a ________3________.

Postfix

When you use the _________ ++, the variable is used, and then the result is calculated and stored. -example: in the second line of the following code, 4 is assigned to c; then, after the assignment, b is increased and takes the value 5. This last WriteLine() statement displays 5 and 4. In other words, if b = 4, then the value of b++ is also 4, and, in the second statement above, that value is assigned to c. However, after the 4 is assigned to c, b is increased to 5. b = 4; c = b++; WriteLine("{0} and {1}", b, c);

Prefix

When you use the ___________ ++, the result is calculated and stored and then the variable is used. -example: in the following code, both b and c end up holding 5. The WriteLine() statement displays 5 and 5. In this example, 4 is assigned to b, then b becomes 5, and then 5 is assigned to c. b = 4; c = ++b; WriteLine("{0} and {1}", b, c);

strings

You can compare _________ with any of the following methods: -an Equals () method call takes the format name1.Equals(name2); >its value is true or false -a CompareTo() method call takes the format name1.CompareTo(name2); >its value is integer-- 0 when compared strings are equal, a negative number if the first string is less, and a positive number if the second string (the one in parentheses) is less -a Compare() method call takes the format Compare(name1, name2); >its values are the same as the CompareTo() method >when using this method though, you must include the following statement at the top of the using static System.String; statement

Cast

You can convert an enum value to another data type or an integral type to an enum value by using a _______. -For example, the following are valid statements: int shipDay; DayOfWeek deliverDay; shipDay = (int)DayOfWeek.THURSDAY; deliveryDay = (DayOfWeek)shipDay;

Variable

You can display __________ values by using the ________ name within a Write() or WriteLine () method call. This program uses the Write() method to display the string "The money is $" before displaying the value of someMoney. Because the program uses Write() instead of WriteLine() for the first output, the second output appears on the same line as the first.

Constant

You must assign a value to a _________ when you create it -you can use *it* just as you would use a variable of the same type-- for example, display it or use it in a mathematical equation-- but you cannot assign any new value to it

Variable

__________ names follow the same rules as class identifiers: A variable name must start with a letter, cannot include embedded spaces, and cannot be a reserved keyword -by convention, each C# __________ name starts with a lowercase letter and uses camel casing if it contains multiple words

Unicode

a 16-bit coding scheme for characters. -for any two strings, the one with the higher _________ character value in an earlier position is considered higher -for example: "AAB" is higher than "AAA" -the string type has no true minimum; however, you can think of the empty string "" as being the lowest


Kaugnay na mga set ng pag-aaral

STR581: Ch 2: Charting a company's direction

View Set

PHTLS - Thoracic Trauma (CH12), PHTLS Pretest, PHTLS pre test 8th edition, phtls 8th test

View Set

Environmental Science- Chapter 1 Test

View Set

OB-Ch. 23 Quiz NB W/ Special Needs Quiz ?s

View Set

Exam 3 Quiz Questions (ch. 13, 15, 17, 18, 19)

View Set