Exam 2 Topics Flashcards
What are the two types of flow of control and define them.
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.
What are the two selection statements in C++
They are “if” and “switch”
What is the “if” statement syntax. (two-way selection)
if (logical expression)
statement1;
else
statement2;
Define what “logical expression” is.
an expression that evaluates to true or false
Define what a “bool” is
built-in data type for storing logical values. Can be either true or false. non-zero is true, zero is false.
Handwrite the relational operators used to compare values to each other
< > <= >=
== !=
Handwrite the logical operators that are used to change or connect logical exprfessions
! – not && - and || - or
What is short circuit evaluation
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
What is a switch statement
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)
Handwrite the syntax for a switch statement
switch (expression) { case value1: statements1; break; case value2: statements2; break; . . . case valuen: statementsn; break; default: statements; break; }
What does “mv” command do? (Linux commands)
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)
what does “rm” command do? (Linux commands)
used to permanently delete a file
rm afile will delete a file from the current directory (assuming the file exists)
What does “mkdir” command do? (Linux commands)
used to create a directory (will be subdirectory of current directory)
mkdir exercises will create a directory called exercises
what does “cd” command do? (Linux commands)
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
What does “pwd” command do? (Linux commands)
displays absolute path to current directory - use it to figure out where you are
what does “rmdir” command do? (Linux commands)
used to delete a directory - the directory must be empty
rmdir exercises will remove the exercises directory
Define “Batch processing”
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)
Define “Input failure”
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
What is the “get” function and what does it do?
a function that can be used to read character data, including white space (defined in iostream)
cin.get(ch);
What is “Linux redirection for bath processing” and what are the two operators that control it?
”” linux output redirection operator changes the default output destination to a specified file
./a.out < input > output
Define “repetition structure”
statement that allows for an action to be repeated (iteration, looping)
List the three C++ repetition statements
for, while, do while
Define “counting” and two operators that can be used for it.
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
What is a “for statement”
a statement specifically designed for implementing count-controlled loops