COSC-1337 Chapter 3 Flashcards

1
Q

“Prompt”

A

Lets the user know that input is expected and prompts them as to what they must enter.

A cin object must always be preceded by a “prompt”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What symbol is this? - “»”

A

Stream-extraction Operator

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Gathering input from a users requires what process?

A
  1. “Prompting” the user to enter input

2. Using cin object to read input from the keyboard

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

“Input Buffer” or “Keyboard Buffer”

A

This is an area of memory where input from the keyboard is temporarily placed before it is converted to the correct value and stored in its variable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is an “Expression”?

A

Is something that can be evaluated to produce a single value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

“Associativity”

A

is the order in which an operator works with its operands. It is either left-to-right or right-to-left.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is this for?: algebra = pow(4.0, 2);

A

It is the variable algebra that has an expression of 4 being raised to the second power.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What header file must be included in order to use the pow function?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is “type coercion”?

A

When C++ automatically converts two values to the same type when used with an operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

char, short, and unsigned short are automatically converted to which type?

A

int data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

An operator working with a lower value data type and a higher value data type will be promoted to what data type?

A

The higher value variable data type

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

When the final value of an expression (with an operator) is assigned to a variable what happens?

A

It is converted to the data type assigned to the variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What happens when a floating point number is converted to an int?

A

It is “truncated” and the decimal gets left out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

A ________ lets you manually promote or demote a value

A

“type cast expression”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does this do?: static_cast(Value)

A

This is type conversion. It can be used to convert the data type of a variable to another.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What type cast is this?: pennies = (double)dollar;

A

Prefix Notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What type conversion is this?: pennies = float(dollar);

A

Functional notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

High-order Bit

A

It is the leftmost bit. If it is 1 the number stored is negative. If it is 0 the number stored is positive.

19
Q

What is a named constant/variable constant and how is it declared?

A

It is a variable who has a “read-only” value stored in its memory. You declare it by using “const” before declaring your variable.

20
Q

How would you assign a value to multiple variables at once?

A

a = b = c = d = e = 12;

21
Q

What direction are assignment operations carried out in?

A

Right to left

22
Q

How do we write a stream manipulator?

A

setw(number)

23
Q

What is the setprecision manipulator and how do we use it?

A

It is used to specify how many decimals we would like to be included in our cout display. It can be used as such - cout &laquo_space;setprecision(number) &laquo_space;variable;

24
Q

How would we a float number display only 4 digits after the decimal?

A

cout &laquo_space;fixed &laquo_space;setprecision(4) &laquo_space;variable;

25
Q

How would we display the digits after a decimal even if they are zeros?

A

cout &laquo_space;fixed &laquo_space;showpoint &laquo_space;setprecision(number) &laquo_space;variable;

We would use the showpoint manipulator

26
Q

What header file is needed for setw and setprecision?

A

The header file iomanip

27
Q

What manipulators remain in effect till the programmer changes them?

A

setprecision, fixed, showpoint

28
Q

When is showpoint not needed in your source code?

A

When fixed and setprecision are already being used.

29
Q

How would you make text be left or right justified?

A

You would use the “left” or “right” manipulator

30
Q

How do we input a string?

A

getline(cin, variable);

31
Q

What is a member function of cin?

A

“get” is a member function of cin

32
Q

What does cin.get(variable); do?

A

It will receive any character as input EVEN A WHITESPACE OR THE ENTER KEY!

33
Q

How do we skip or “ignore” characters?

A

cin.ignore(n, c);

This will make the program skip “n” number of characters OR to include everything until character “c” is encountered

34
Q

How do we find out the length of a string literal?

A

variable.length();

35
Q

How do we assign 22 spaces to the variable named x?

A

x.assign(22, ‘ ‘);

36
Q

What is a C-string and how can we write one?

A

It is essentially an array. It was the way that C used to store string literals.

char example[10] = “Timmy”;

37
Q

How would we assign a string to a c-string?

A

We would need to use “strcpy”.

char example[32];

strcpy(example, “This is our c-string text”);

38
Q

How do we give a c-string memory bytes?

A

With the “size declarator”

39
Q

What are two ways that we can prevent buffer overrun?

A
  1. setw();

2. cin.width();

40
Q

What header file must we include to be able to use the rand() function?

A

cstdlib

41
Q

How would we generate a random number based on the input from the user?

A

By creating a variable that would store the input “seed” value and then using the “stand(variable);” function to start the algorithm with the input “seed”.

42
Q

How would you randomly generate a seed without user input?

A

You would use the “time” function AND you would pass a “0” to its argument

43
Q

What header file must be included to use the time function?

A

ctime

44
Q

How would we get a random number generated between 10-25?

A

int x;

x = srand(seed) % (MAX - MIN + 1) + MIN;