Study your flashcards anywhere!

Download the official Cram app for free >

  • 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

How to study your flashcards.

Right/Left arrow keys: Navigate between flashcards.right arrow keyleft arrow key

Up/Down arrow keys: Flip the card between the front and back.down keyup key

H key: Show hint (3rd side).h key

A key: Read text to speech.a key

image

Play button

image

Play button

image

Progress

1/93

Click to flip

93 Cards in this Set

  • Front
  • Back

3.1: concept: The cin object can be used to read data typed at the keyboard.

THE cin OBJECT CAN BE USED TO READ DATA TYPED AT THE KEYBOARD.

Just as cout is C++'s standard output object, cin is the standard ________ object.

input object. It reads input from the console (or keyboard).

The cout object is used to display a question. This is called a ________.

Prompt. It tells the user what data he or she should enter.

Your program should display a prompt before it uses cin to read input. Yes or No.

Yes. This way, the user will know that he or she must type a value at the keyboard.

What is the symbol used in the stream extraction operator?

>> cin >>

When gathering input from the user, normally two steps must occur:

1. Use the cout object to display a prompt on the screen.


2. Use th cin object to read a value from the keyboard.

The stream insertion operator points ________ cout, while the stream extraction operator points toward the ___________.

toward, variable

The cin object causes a program to wait until data is typed at the keyboard and the [Enter] key is pressed. True or False?

True. No other lines in the program will be executed until cin gets its input.

cin does not automatically convert the data read from the keyboard to the data type of the variable used to store it. True/False?

False. cin DOES automatically convert the data read from the keyboard to the data type of the variable used to store it. cin is smart enough to know if a character must be converted to it's corresponding data type before it is stored in it's assigned variable.

What file must you include in any program that uses cin?

The iostream file must be included in any program that uses cin.

Can the cin object be used to gather multiple values at once?

Yes. Ex: cin >> height >> weight;

Will cin read multiple values of different data types?

Yes. Ex:




cin >> while >> fraction >> letter >> name;

When the user types values at the keyboard, what area of memory are those values first stored?

the keyboard buffer




Ex:


| 5 | . | 7 | | 4 | | b |[Enter]|

3.2 concept: C++ allows you to construct complex mathematical expressions using multiple operators and grouping symbols.

C++ ALLOWS YOU TO CONSTRUCT COMPLEX MATHEMATICAL EXPRESSIONS USING MULTIPLE OPERATORS AND GROUPING SYMBOLS.

In programming, what is an expression?

a An expression is a programming statement that has a value. Ex: sum = 21 + 3;


grow = 32 * 8; tux = 67 - 7;

What is precedence?

priority in importance, order, or rank.

Which operator has the higher precedence?


+ or /

(/) division has higher precedence than (+) addition.

What is an operator's associativity?

it is either left to right, or right to left.

Does C++ have an exponent operator?

No.

Raising the number to a power requires the use of a _________ __________.

library function.

What is a library in C++?

a library in C++ is a collection of specialized functions.

pow is the library function for power, and it's purpose is to...

raise a number to a power.


Ex. area = pow(4.0, 2.0);

Consider this example:


area = pow(4.0, 2.0);




This statement contains a ____ to the pow function.




The numbers inside the parentheses are ___________.

call,




arguments

What are arguments?

data being sent to the function.

The pow function always raises the first argument to the power of the __________ argument.

second.

The result is __________ from the function and used in the statement where the functions call appears.

returned

The header file must be added when using the pow function. Yes or No?

Yes. without it errors will occur when your program is compiled. The header must be included in order to use the pow function.

What are some guidelines that should be followed when the pow function is used?

1. the program must include the header file.


2. the arguments that you pass to the pow function should be doubles.


3. The variable used to store pow's return value should be defined as a double.

3.3: concept: When an operator's operands are of different data types, C++ will automatically convert them to the same data type. This can affect the results of mathematical expressions.

WHEN AN OPERATOR'S OPERANDS ARE OF DIFFERENT DATA TYPES, C++ WILL AUTOMATICALLY CONVERT THEM TO THE SAME DATA TYPE. THIS CAN AFFECT THE RESULTS OF MATHEMATICAL EXPRESSIONS.

C++ follows a set of rules when performing mathematical operations on variables of different types. Yes or No?

Yes.

One data type outranks another if it can hold a __________ number. Larger or Smaller?

Larger. One data type outranks another if it can hold a larger number.

Here is a list of data types in order of their rank, from highest to lowest.

1. long double


2. double


3. float


4. unsigned long


5. long


6. unsigned int


7. int

One exception to the data type ranking is when an int and a long are the same size. What happens then?

In that case, when an int and a long are the same size, an unsigned int out ranks long because it can hold a higher value.

When C++ is working with an operator, it doesn't strive to convert the operands to the same type. True/False?

False. C++, when working with an operator, STRIVES to convert the operands to the same type.

When C++ strives to convert the operands to the to the same type, what is it known as?

type coercion.

When a value is converted to a higher data type, it is said to be, what?

promoted.

When a value is converted to a lower data type it is called?

being demoted.

Rule 1:chars, shorts, and unsigned shorts are automatically promoted to ___.

int.

Rule 2: When an operator works with two values of different data types, the lower-ranking value is ____________ to the type of the higher-ranking value.

promoted

Rule 3: When the final value of an expression is assigned to a variable, IT WILL be converted to the _____ _____ of that variable.

data type

When you divide an integer by another integer in C++, the result is always an ___________. If there is a remainder, it will be __________.

integer,


discarded

In order for a division operation to return a floating-point value, AT LEAST ONE of the operands must be of a _____________ data type.

floating-point

3.4: concept: When a variable is assigned a value that is too large or too small in range for that variable's data type, the variable overflows or underflows.

WHEN A VARIABLE IS ASSIGNED A VALUE THAT IS TOO LARGE OR TOO SMALL IN RANGE FOR THAT VARIABLE'S DATA TYPE, THE VARIABLE OVERFLOWS OR UNDERFLOWS.

When a variable is assigned a number that is too large for its data type, it ___________.

overflows.

Assigning a value that is too small for a variable causes it to ___________.

underflow.

Typically, when an integer overflows, its contents wrap around to that data type's ___________ possible value.

lowest.

Is a warning or error message given, when working with numbers close to the maximum or minimum range of an integer? Yes or No?

No. So pay close attention! If an overflow or underflow occurs, the program will use the incorrect number and therefore produce incorrect results.

3.5: concept: Type casting allows you to perform manual datA type conversion.

TYPE CASTING ALLOWS YOU TO PERFORM MANUAL DATA TYPE CONVERSION.

What does type cast expression allow you to do?

Type cast expression lets you manually promote or demote a value.

What is the general format of type cast expression ?

static_cast(Value)

The Value in static_cast(Value) is a _________ or __________ value that you wish to convert and DataType is the data type you wish to __________ Value to.

variable, literal, convert

C++ provides several different type cast expressions. static_cast is the most commonly used type cast expression. True || False?

True.

3:6: concept: Multiple assignment means to assign the same value to several variables with one statement.

MULTIPLE ASSIGNMENT MEANS TO ASSIGN THE SAME VALUE TO SEVERAL VARIABLES WITH ONE STATEMENT.

Does C++ allow you to assign a value to multiple variables at once?

Yes. If a program has several variables, such as a, b, c, and d, and each variable needs to be assigned a value, such as 12, the following statement may be constructed:


a = b = c = d = 12;

Compound assignment operators,


compound operators, and


arithmetic assignment operators




all mean the same thing. Yes or No?

Yes.

3.7: concept: The cout object provides ways to format data as it is being displayed. This affects the way data appears on the screen.

THE cout OBJECT PROVIDES WAYS TO FORMAT DATA AS IT IS BEING DISPLAYED. THIS AFFECTS THE WAY DATA APPEARS ON THE SCREEN.

What is formatting?

Formatting is the way a value is printed.

cout offers a way of specifying the minimum number of spaces to use for each number. True of False?

True.

A stream manipulator, ____, can be used to establish print fields of a specified width.

setw

Here is an example the uses setw:

value = 23;


cout << "(" << stew(5) << value << ")";

The number inside the parentheses after the word setw specifies the _____ ______ for the value immediately following it.

field width.

What is field width?

The field width is the minimum number of character positions, or spaces, on the screen to print the value in.

What does it mean to be right-justified?

When a value appears on the right side of the field with blank spaces it in front. this is also known as padding!

What is precision?

the total number of digits that appear before and after the decimal point.

Floating-point values may be rounded to a number of ____________ _______, or precision.

significant digits.

You can control the number of significant digits with which floating-point values are displayed by using the what manipulator?

the setprecision manipulator

To use the setprecision manipulator what header file must be included to the program?

<iomanip>

What is the purpose of the fixed manipulator?

The fixed manipulator forces cout to print digits in fixed-point notation, or decimal.

When the fixed manipulator is used, all floating-point numbers that are ______________ printed will be displayed in _______ point notation, with the number of digits to the right of the decimal point specified by the _____________ manipulator.

subsequently, fixed, setprecision.

When the _______ and setprecision manipulators are used together, the _______ specified by the ____________ manipulator will be the number of digits to appear after the decimal point, NOT the number of significant digits.

fixed, value, setprecision

By default, floating-point numbers are not displayed with trailing _______, and floating-point numbers that do not have a __________ _____ are NOT displayed with a decimal point.

zeroes, fractional part

If we want the numbers padded with trailing zeroes, we must use what manipulator?

the showpoint manipulator.

Normally, in C++, output is ________ justified.

right

You can cause the values to be left-justified by using the ______ manipulator.

left manipulator



The left manipulator remains in effect until you use the _______ manipulator, which causes all subsequent output to be right-justified.

right manipulator

Describe what the setw(n) stream manipulator does:

Establishes a print field of n spaces.

describe what the fixed stream manipulator does:

Displays floating-point numbers in fixed point notation.

Describe what the showpoint stream manipulator does:

It causes a decimal point and trailing zeroes to be displayed, even if there is no fractional part.

Describe what the setprecision(n) stream manipulator does:

It sets the precision of floating-point numbers.

Describe what the left stream manipulator does:

It causes subsequent output to be left justified.

what does subsequent mean?

coming after something in time; following.

Describe what the right stream manipulator does:

It causes subsequent output to be right justified.

3.8: concept: Special functions exist for working with characters and string objects.

SPECIAL FUNCTIONS EXIST FOR WORKING WITH CHARACTERS AND string OBJECTS.

When cin reads input, it passes over and ignores any leading ______________ characters.


Once it comes to the first non-blank character and starts reading, it stops reading when it gets to the next whitespace character.

whitespace

What is whitespace?

(spaces, tabs, or line breaks).

What does the getline function do?

The getline function reads an entire line, including leading and embedded spaces, and stores it in a string object.

Here is what the getline function looks like:

getline(cin, inputLine);

Which member function of cin reads a single character, including any whitespace character.

cin.get( )

the cin.get member function is good for a programs that pauses it's screen until the [Enter] key is pressed.

Or it can also be useful for a program that uses "hit [Enter] key to continue" within it's program.

There is three ways to us the cin.get function:

cin.get(variable);




variable = cin.get( );




cin.get( );

What type of character does the [Enter] key store in the keyboard buffer?

the newline character ('\n')

What is the purpose of the cin.ignore( ) function?

The cin.ignore( ) function tells the cin object to skip one or more characters in the keyboard buffer.

cin.ignore( ) can have arguments within it's parentheses. True or False?

True. the arguments shown within the parentheses are optional.