Exam 2 Topics Flashcards

1
Q

What are the two types of flow of control and define them.

A

sequential is when the statements are executed in the order they are placed in a program.

selection structure allows a program to choose between alternative actions.

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

What are the two selection statements in C++

A

They are “if” and “switch”

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

What is the “if” statement syntax. (two-way selection)

A

if (logical expression)
statement1;
else
statement2;

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

Define what “logical expression” is.

A

an expression that evaluates to true or false

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

Define what a “bool” is

A

built-in data type for storing logical values. Can be either true or false. non-zero is true, zero is false.

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

Handwrite the relational operators used to compare values to each other

A

< > <= >=

== !=

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

Handwrite the logical operators that are used to change or connect logical exprfessions

A

! – not && - and || - or

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

What is short circuit evaluation

A

process in which a computer evaluates a logical expressio0n from left to right and stops as soon as the final value of the expression is known

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

What is a switch statement

A

A switch statement provides multi-way selection, can be used in place of a nested if else structure if expression being tested is discrete (integral)

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

Handwrite the syntax for a switch statement

A
switch (expression) 
{
 case value1: statements1; 
                    break;
case value2: statements2;
                   break;
 . . .
 case valuen: statementsn;
                      break;
 default: statements; 
                    break;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What does “mv” command do? (Linux commands)

A

it is used to change the name of a file.

mv oldfile newfile will change the name of oldfile to newfile in the current directory (assuming oldfile exists)

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

what does “rm” command do? (Linux commands)

A

used to permanently delete a file

rm afile will delete a file from the current directory (assuming the file exists)

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

What does “mkdir” command do? (Linux commands)

A

used to create a directory (will be subdirectory of current directory)

mkdir exercises will create a directory called exercises

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

what does “cd” command do? (Linux commands)

A

used to move from one directory to another

cd exercises will move from current directory to the exercises directory

cd will return to home directory

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

What does “pwd” command do? (Linux commands)

A

displays absolute path to current directory - use it to figure out where you are

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

what does “rmdir” command do? (Linux commands)

A

used to delete a directory - the directory must be empty

rmdir exercises will remove the exercises directory

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

Define “Batch processing”

A

all input is gathered together and palced in a file (a batch), program is deigned to read the data from the file as needed (no prompting required)

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

Define “Input failure”

A

if the data type of a variable and the value being read into it do not match, the input operation will stop working. Once input failure occurs, not further read operations will be executed. generally, the program will continue running

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

What is the “get” function and what does it do?

A

a function that can be used to read character data, including white space (defined in iostream)

cin.get(ch);

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

What is “Linux redirection for bath processing” and what are the two operators that control it?

A

”” linux output redirection operator changes the default output destination to a specified file

./a.out < input > output

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

Define “repetition structure”

A

statement that allows for an action to be repeated (iteration, looping)

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

List the three C++ repetition statements

A

for, while, do while

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

Define “counting” and two operators that can be used for it.

A

looping often involves counting things

++ increment operator- unary operator used to add 1 to a variable

– decrement operator - unary operator used to subtract 1 from a variable

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

What is a “for statement”

A

a statement specifically designed for implementing count-controlled loops

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

What is a “count controlled loop”?

A

a loop designed to execute a specific number of times, number of runs is determined before loop starts.

26
Q

Handwrite the general syntax for a “for loop”

A

for (initial statement; loop condition; update statement)

action; // loop body

27
Q

Define “Nested looping”

A

when processing one data set requires repetition, and there are several data sets, loops can be nested.

28
Q

Define “while” statement

A

a general conditional looping statement.

29
Q

What is a conditional loop?

A

they are used when the number of repetitions required is not known in advance

30
Q

Handwrite the general syntax for a “while loop”

A

while (logical expression)

statement;

31
Q

Define a “infinite loop” and how to exit one.

A

if the logical expression in a while statement remains always true, the loop will not be exited. To exit an infinite loop use ctrl-c

32
Q

Name two common conditional looping situations

A

eof-controlled and sentinel controlled

33
Q

Define “eof-controlled”

A

designed to read and process data until the end-of-file is encountered. use cin as logical expression for eof control.

34
Q

Define “sentinel-controlled”

A

can be used when the last entry in a data setis a special value (setinel) that indicates when the loop should stop

35
Q

What is the general set up for a sentinel-controlled while loop?

A

read first data value

while data is not the sentinel

perform action to be repeated

read next data value

36
Q

Define “value-returning function”

A

a function designed to compute and return exactly one value using a return statement. must include a return statement

37
Q

Define “void function”

A

a function containing a series of statements designed to perform a task. This function does not have a specific data type

38
Q

List the three things that are needed to add a function to a C++ program

A

function definition, function prototype, and function call

39
Q

Define “function definition”

A

consists of a heading and a body, placed after the main function

40
Q

Define “function prototype”

A

placed after using statement and const declarations, before heading for main func tion - provides information to compiler about the function

41
Q

Define “function call”

A

placed inside any function, used when you want the statements in the function to be executed

42
Q

Name the three typical situations when a void function is appropriate.

A

function will generate some type of output

function performs a task that does not directly result in the calculation of a single value

function performs a task that involves changing one or more values passed to it

43
Q

Define “parameter”

A

a parameter is a value that is passed (communicated) to a function and should be the only way that functions share data

44
Q

Name the two methods of parameter passage

A

pass by value and pass by reference

45
Q

Define “pass by value”

A

a copy of the value of the actual parameter (which is supplied in the function call) is transmitted to the function for its use

46
Q

Define “pass by reference”

A

the memory location of the actual parameter (which is supplied in the function call) is sent to the function. The function will change the literal value of the memory location.

47
Q

Define function documentation

A

for each function provide a brief statement with the definition of the input output and what the function does

48
Q

Define “function prototype”

A

serves as the declaration to the compiler for a function. specifies the functions type, name, and parameter list. Should be placed before the main function.

49
Q

Hand write the syntax for a function prototype

A

function_type function_name(parameter list);

50
Q

Define “function call”

A

a statement used to invoke a function (cause it to be executed)

51
Q

Hand write the syntax for calling a function.

A

function_name(actual parameter list)

52
Q

Define “local variable”

A

a variable declared inside a function or program block is said to be local to the function/block. Exists inside a function/block only.

53
Q

Define “Scope of an identifier”

A

it is the region (part) of a program where an identifier is recognized (visible) and accessible

54
Q

Define “local identifier” and how its memory is allocated

A

identifier declared within a function (or block). The memory is allocated at declaration and de-allocated at block exit (automatic allocation)

55
Q

Define “Global identifier” and how its memory is allocated

A

identifier declared outside of every function definition. The memory is allocated at declaration and de-allocated when program is finished executing (static allocation)

56
Q

What are the general scope rules for when a global identifier is accessible by a function or block?

A

the identifier is declared before the function(block).

the function name is different from the global identifier name

all parameters have names different from the global identifier name

all local identifiers have names different from the global identifier name

57
Q

What are the general scope rules for when a identifier declared within a block is accessible?

A

from the point it is declared to the end of the block in which it is declared

in any nested blocks that do not have an identifier with the same name

58
Q

Define “Side effect”

A

it is a unintended change to a variable, use of global variables can lead to side effects (don’t use global variables)

59
Q

What is the scope of a function name

A

Scope of a function name is the same as the scope of a global identifier.

60
Q

What is the scope of a formal parameter?

A

Scope of a formal parameter is the function in which it is declared.