• 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/97

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;

97 Cards in this Set

  • Front
  • Back

2.5: concept: Choose variable names that indicate what the variables are used for.

CHOOSE VARIABLE NAMES THAT INDICATE WHAT THE VARIABLES ARE USED FOR.

What is an identifier?

a programmer-defined name that represents some element of a program. Variable names are examples of identifiers.

What are examples of identifiers?

Variables.

In C++ can you use your own variables names?

Yes.

What are key words?

Key words make up the "core" of the language and have specific purposes.

Are all the key words in the C++ language lowercase or uppercase?

lowercase

Identify Legal Identifiers:

1). first character must be one of the letters a - z, A - Z, or an underscore character(_)


2). After the first character you may use the letters a - z or A - Z, the digits 0 - 9, or underscores.


3). Uppercase and lowercase characters are distinct. This means ItemsOrdered is not the same as itemsordered.

Is Freedom the same as freedom?

No.

2.6: concept: There are many different types of data. Variables are classified according to their data type, which determines the kind of information that may be scored in them. Integer variables can only hold whole numbers.

THERE ARE MANY DIFFERENT TYPES OF DATA. VARIABLES ARE CLASSIFIED ACCORDING TO THEIR DATA TYPE, WHICH DETERMINES THE KIND OF INFORMATION THAT MAY BE STORED IN THEM. INTEGER VARIABLES CAN ONLY HOLD WHOLE NUMBERS.

In the broadest sense , there are only two data types:

Numeric and character.

Numeric data types are broken into two additional categories:

integer and floating point.

What type of data are integers?

whole numbers

What type of data are floating point numbers?

decimal numbers

You can define several variables of the same type, simply by separating their names with commas. True or False?

True

What is a integer literal?



If a numeric literal is an integer and it fits within the range of an int, then the numeric literal is treated as an int. a numeric literal that is treated as an int. (ex: floors = 15; rooms = 300; suites = 40;)

What is a long integer literal treated as?

a long integer literal is treated as a long. (Ex:


long amount;


amount = 32L;


)

What is a long long integer literal treated as?

The long long literal is treated as a long long int. (ex:


long long amount;


amount = 32LL;)

2.7

The char data type

What is the char data type used for?

the char data type is used to store individual characters.

What type of quotation marks are always used with char data type? double or single?

single quotation marks. ex. 'Q'

How many characters can a char variable hold?

only 1

Are char variables compatible with strings?

No. Hence the single quotes used for char and double used for strings.

In C++ an extra byte is appended to the end of a string literal. True or False?

True. The null terminator.

What is the last byte of a string called?

the null terminator or null character.

What number is stored in the null terminator?

Zero

"Sebastian" is stored how?

S | e | b | a | s | t | i | a | n | \0




...in ten locations...

The null terminator sits quietly in the background. Yes or No?

Yes. Stays in the background.

Does C++ automatically place the null terminator at the end of string literals?

Yes. So a string with 5 letters occupies 6 bytes of memory.

How is the literal 'A' stored?




How is the string "A" stored?

A ...one byte




A | \0 ...two bytes

Because char variables are only large enough to hold one character, you cannot assign__________ literals to them.

string literals to them.

How many bytes of memory does a newline character (\n) have?

only One, internally. Also, it is stored as one character.

2.8: concept: Standard C++ provides a special data type for storing and working with strings.

STANDARD C++ PROVIDES A SPECIAL DATA TYPE FOR STORING AND WORKING WITH STRINGS.

What is the first step in using the string class ?

The first step is to #include the header file.

Is #include a preprocessor directive?

Yes. It must be included before using the string class in C++.

2.9: concept: Floating- point data types are used to define variables that can hold real numbers.

FLOATING-POINT DATA TYPES ARE USED TO DEFINE VARIABLES THAT CAN HOLD REAL NUMBERS.

In programming terms, what are floating-point numbers?

fractional values.

Floating-point numbers are stored in a similar manner to ___________ notation.

Scientific notation.

What is the mantissa multiplyed by??

by the power of ten.

Computers typically use E notation to represent floating-point values. True or False?

True.

In E notation, the number 47,281.97 would be

4.728197E4

EX. 4.728197E4


the part of the number before the E is the __________, and the part after the E is the __________ of ten.

mantissa, power

The floating-point number is stored in memory as:

the mantissa and the power of ten.

Decimal Notation:


247.91




Scientific Notation:


2.4791 x 10^2

E notation:


2.4791E2

Decimal Notation:


0.00072




Scientific Notation:


7.2 x 10^-4

E Notation:


7.2E-4

Decimal Notation:


2,900,000

Scientific Notation:


2.9 x 10^6




E Notation:


2.9E6

In C++ there are three data types that can represent floating-point numbers. What are they?

float, double, and long double.

The following are all equivalent to one another:




1.4959E11


1.4959e11


1.4959E+11


1.4959e+11


1.49590000000.00

Yes. the + sign is optional. Though it is more convenient for lengthy numbers, however 4.739E1 is preferably written: 47.39

What precision is the float data type considered?

Single precision.

What precision is the double data type?

double precision

What precision is the long double data type?

Long double precision.

If you needed to force a literal to be stored as a float, what letter do you append to the end of it?

F or f. (Ex..... 1.2F or 45.907f)



If you want to force a value to be stored as a long double, what letter do you append to it?

L or l. (Ex.. 1034.56L and 89.2l)

You should always use an uppercase L when forcing a value to be stored as a long double, because?

a lowercase L can often be mistaken for a 1.

What does truncated mean?

It means that part of value is discarded.

When a value is truncated, is the floating-point rounded?

No. It's just truncated.

Floating-point variables can hold a much larger range of values than integer variables can. True or False?

True.

If a floating-point value is being stored in an integer variable, the whole part of the value is ____ ________ for the integer variable, an ___________ value will be stored in the integer variable.

too large, invalid.

2.10: concept: Boolean variables are set to either true or false.

Boolean variables are set to either ________ or ________.

Expressions that have a true or false value are called:

Boolean expressions.

the bool data type allows you to create small integer variables that are suitable for holding _______ or ________ values.

True, False

the number __ equals true and the number __ equals false.

true = 1 .....while..... false = 0

2.11: concept: the sizeof operator may be used to determine the size of a data type on any system.

Which operator may be used to determine the size of a data type on any system?

C++ provides a way to find out what the sizes of data types are on any computer. True / False?

True.

What is the purpose of the sizeof operator?

The sizeof operator reports the number of bytes of memory used by any data type variable.

2.12: concept: an assignment operation assigns, or copies, a value into a variable. When a value is assigned to a variable as part of the variable's definition, it is called an initialization.

an assignment operations _________, or ________, a value into a variable. WHen a value is assigned to a ________ variable as part of the variable's definition, it is called an ____________.

A ___________ is stored in a variable with an assignment statement.

value.

The = symbol is called the __________ ____________.

assignment operator.

What are operands?

Operands are the data that operators work with.

What is the lvalue?

The lvalue is the operand the appears on the left side of an assignment operator.

What is rvalue?

The operand that appears on the right side of an assignment operator.

What is initialization?

The assignment of values to variables as part of the definition.


Ex:


double interestRate = 12.9;


char stockCode = 'D';


long customerNum = 459L;


(Notice that the variables are assign a definition right away, instead of wait to define the a few lines after. )

What does initialization do for the programmer?

It simplifies the program and reduces the number of statements that must be typed by the programmer. (efficient = achieving maximum productivity with minimum wasted effort or expense.)

With C++ you can define several variables and only initialize some of them. True/False?

True. Ex: int flightNum = 89, travelTime, departure = 10, distance;


Notice*: flightNum and departure are initialized, while travelTime and distance are not.

C++ 11 allows an alternative way to define variables, using the ____ key word and an initialization value.

auto

What does the auto key word allow in C++11?

it allows an alternative way of defining a variable.


Ex: auto amount = 100;

The auto key word tells the ___________ to determine the variable's data type from the initialization value.

compiler. In the example, auto amount = 100, the initialization value is an int. So amount will be an int, because the auto key word tells the compiler to store it as it's data type admits.

What is the auto key word intended for?

it is intended to simplify the syntax of declarations that are more complex then the ones shown here.




auto interestRate = 12.0;


auto stockCode = 'D';


auto customerNum = 459L;

2.13: concept: A variables's scope is the part of the program that has access to the variable.

A VARIABLE'S SCOPE IS THE PART OF THE PROGRAM THAT HAS ACCESS TO THE VARIABLE.

Does every variable have a scope?

Yes.

What is the scope of a variable?

The scope of a variable is the part of the program where the variable may be used.

What is the first rule of scope?

The first rule of scope is: a variable cannot be used in any part of the program before it's definition. Think!: the variable and it's definition first, then the the statement using the variable.

The compiler reads your program from bottom to top. True/False?

False. The compiler read your program from TOP to BOTTOM. Think!: variable first, then statement.

2.14: concept: There are many operators for manipulating numeric values and performing arithmetic operations.

THERE ARE MANY OPERATORS FOR MANIPULATING NUMERIC VALUES AND PERFORMING ARITHMETIC OPERATIONS.

Generally, what are the three types of operators? Do not confuse operators with operands!

The three general types are:


1. Unary, 2. Binary, 3. Ternary.




Each term reflects the number of operands an operator requires.

How many operands do unary operators require?

One. Ex: -5 the minus sign is called the negation operator.

Binary operators work with ____ operands.

Two. Ex: amount = 4 + 8;

Ternary operators work with ____operands

Three. i ? .length ++ seven

What data type will integer division return?

int. if both operands are int data type...


double number; number = 5 /2 (result:


number = 2)




double. if the at least one of the operands is a floating-point data type...


double number; number = 5.0 / 2; (result:


number = 2.5)

2.15: concept: Comments are notes of explanations that document lines or sections of a program. Comments are part of the program, but the compiler ignores them. They are intended for people who may be reading the source code.

COMMENTS ARE NOTES OF EXPLANATION THAT DOCUMENT LINES OR SECTIONS OF A PROGRAM. COMMENTS ARE PART OF THE PROGRAM, BUT THE COMPILER IGNORES THEM. THEY ARE INTENDED FOR PEOPLE WHO MAY BE READING THE SOURCE CODE.

What two ways can comments be written?

1. Single-line:


//comment




2. Multi-line:


/*


comments


comments


*/

2.16 concept: Literals may be given names that symbolically represent them in a program.

LITERALS MAY BE GIVEN NAMES THAT SYMBOLICALLY REPRESENT THEM IN A PROGRAM.

What is a NAMED CONSTANT?

a named constant is like a variable, but its content is READ-ONLY and CANNOT BE CHANGED WHILE the PROGRAM IS RUNNING.

Here are a few definitions of a named constant:

const double INTEREST_RATE = 0.069;




const double PI = 3.14159;




const double DIAMETER = 10.0;

Named constants can also help prevent ______________ errors in a program's code.

typographical.

Constants must be used if named in a program. True or false?

True. Or you will receive an error!

2.17: concept: Programming style refers to the way a programmer uses identifiers, spaces, tabs, blank lines, and punctuation characters to visually arrange a program's source code. These are some, but not all, of the elements of programming style.

PROGRAMMING STYLE REFERS TO THE WAY A PROGRAMMER USES IDENTIFIERS, SPACES, TABS, BLANK LINES, AND PUNCTUATION CHARACTERS TO VISUALLY ARRANGE A PROGRAM'S SOURCE CODE. THESE ARE SOME, BUT NOT ALL, OF THE ELEMENTS OF PROGRAMMING STYLE.

In the C++ language, is it possible to spread a statement over several lines? Yes or No?

Yes. C++ is a free-flowing language.