Pseudocode is a mixture of C++ and ordinary English. It allows us to make our algorithm precise without worrying about the details of a C++ statement.
What is an algorithm?
An algorithm is a sequence of precise instructions which lead to a solution.
What is the input and output(s) of the compiler?
Input: source program or source code.
Output: object program or object code.
What are the 3 catagories of errors that can be made by a programmer?
Syntax, run-time, and logic errors.
What type of errors can a compiler detect?
How are run-time errors usually discovered?
When the program is run.
What errors must the programmer detect and correct during testing?
What is meant by "echoing the input"?
Input that appears on the screen as it is typed. A program should always write out the input values some time before it ends.
What C++ commands are associated with each of the 4 control structures?
Sequence Control, Selection Control (branching or If, If-Else), Repition Control, and Case Control (switch).
How are comments symbols // and /* */ different?
// covers only one line for comments.
/* */ spans several lines for comments.
What is the purpose of including comments in a program?
To make the program more understandable and for explanatory notes at key places.
What are some of the things a debugger allows a programmer to see?
Mistakes, syntax errors, error and warning messages, and run-time errors.
What are the different data types?
Integer (int), floating-point types (double, long double, long float), characters (char).
Why do we use meaningful naming conventions for variables?
To make a program easy to understand.
Are variable names case sensitive?
What is variable initialization, and how can it be done in C++?
Variable initialization is assigning a variable at the time that you declare the variable.
It is done by adding an equal sign and a value.
What are constant variables used for, and what is the preferred naming convention?
Constant variables are used to mark a variable declaration so that the value of the variable cannot be changed.
The preferred naming convention is to use const before the declaration.
What special character is used to define an escape sequence?
What do the escape sequences \n and \t do?
\n is a new line.
\t is a horizontal tab.
What is endl used for?
Its used to output a blank line.
What does the "magic formula" for formatting output do?
It causes numbers that contain a decimal point to be output in everyday notation with the exact number of digits after the decimal point that you specify.
What are the precedence rules?
They are rules that determine the order in which operators are performed.
How do the parentheses affect the precedence rules?
It makes the expression easier to read and less prone to programmer error.
What can be lost from the result of integer division?
Decimal number are lost during integer division.
What does the modulus operator % return?
It gives the remainder in division.
What is the syntax to increment a variable by 1 using assignment statements, short hand notation, and incrementors?
n = n +
n += 1
What is the syntax to decrement a variable by 1 using assignment statements, short hand notation, and decrementors?
n = n -1
n -= 1
What would the following statement do to the variable num?
num += -1;
num = num + num -1
no increment or decrement.
What values are Boolean expressions evaluated to?
True or False.
What is the difference between the = and == symbols?
= is part of an assignment statement.
== is a Boolean expression "equal to".
What is the difference between AND and OR operators?
All expressions must be true in AND.
Only 1 expression need be true in OR.
What are the symbols for the AND and OR operators?
AND is &&
OR is ||
What is the NOT operator and how does it effect the Boolean expression?
! is the operator symbol and it negates a Boolean expression.
What is the difference between if and if-else statements?
The if statement allows for 1 or 2 alternatives to do an action.
The if-else statement chooses between 2 alternative actions.
How does the compiler match an else with an if statement?
The compiler always pairs an else with the nearest previous if that is not already paired with some else.
Does the compiler take indenting you use into consideration to match else and if statements?
The compiler does not care about indenting.
What is the purpose of indenting if-else statements?
It makes the program easier to read and shows the level of nested substatements.
How can braces be used to prevent the dangling-else problem?
Braces tell the compiler how to group things rather than leaving them to be grouped according to default conventions.
What are the differences between the while and do-while loops?
In a while statement, the Boolean expression is checked.
In a do-while statement, the loop body is always executed at least once.
What causes an infinite loop?
A Boolean expression that is always true.
What is involved in top-down design?
Break down the task to be accomplished into subtasks, decompose subtasks into smaller subtasks and so forth.
What is the purpose of structure charts?
To show the overall structure of a program but omits specific logic. It is used for initial planning of a program.
What is depicted in a structure chart?
It shows what tasks need to be completed, not how they will be completed.
Why is the black box analogy used to describe how functions should be written?
It tells all the programmer needs to know if they put appropiate arguments into the black box and have an appropiate return value that will come out of the black box.
Why are functions considered small programs?
It uses formal parameters for input. Arguments to the function are the input and they are plugged in for the formal parameters. The function sends output back to the program using a return statement.
What is the purpose of precondition and postconditions?
Preconditions states what is assumed to be true when the function is called.
Postconditions describe the effect of a function call which tells what will be true after the function is executed in which the precondition holds.
Does the compiler require preconditions and postconditions?
No, they are comments that describe the function declaration.
What is the difference between formal parameters and arguments?
A formal parameter is used as a blank or place holder to stand in for the argument.
An argument is a constant or variable or complicated expression.
When do we use formal parameters?
When writing a function declaration which arguments are not known, formal parameters are used in place of arguments and they are used with function definitions.
When do we use arguments?
They are used with function calls.
What is the purpose of the function declaration?
The function declaration or prototype describes how the function is called. It tells you all you need to know to write a call to the function. It is required to appear in your code prior to a call to a function whose definition has not yet appeared and placed before the main part of the program.
Why must the data types of parameters and arguments match?
When an argument is plugged in for a formal parameter, the argument is plugged in for all instances of the formal parameter that occur in the function body.
Why is it that the function declaration provides all of the information needed to write the function call?
The function declaration tells you the name of the function, how many arguments the function needs, and what type the arguments should be.
What is considered the function call?
The expression on the right-hand side of the equal sign.
What is included in the header of the a function definition?
It describes how the function computes the value it returns. It acts like a small program and calling the function is the same thing as running this "small program".
What is included in the body of a function definition?
It consists of declarations and executable statements enclosed within a pair of braces.
What does the return statement do in the function?
It sends output or a value to the function.
How many return statements can be in a body of a function?
What is the main difference between void and other return types?
The keyword void is used in place of the return type and second is the return statement does not contain an expression for the value to be returned since no value is returned.
Why would you want a function that doesn't return a value?
To output results of a calculation.
What is the syntax for the return statement in void functions?
which is optional before the closing brace of the function body.
Can functions call functions that call other functions?
What is passed to the function through a call-by-reference parameter?
The addresses of the arguments are passed through the function's parameters instead of the values stored in the arguments.
In a call-by-reference mechanism, how many values can be "returned" through the parameters?
Many values can be returned.
Can call-by-value and call-by-reference parameters be mixed?
How are function names overloaded?
Using the same function name but different parameter types or number of parameters.
When function manes are overloaded, how are they uniquely identified?
With their function signature.
What is a function's signature consist of?
Its function name and parameters.
Where are global variables defined?
They are defined before main and they can be referenced by all the functions in the program.
Where are local variables for main defined?
Within the main part of the program.
Where are local variables for other functions defined?
Within the body of a function definition.
Are the variables listed in the function header declared as local variables of the function?
When various functions declare variables of the same type with the same name, are they considered global variables?
No, they are local to the function unless they are declared before main.
How is a block of code defined?
With an open and closed brace.
Can local variables be declared in a block of code?
What is a variable's scope?
It determines in which function or block of code a particular variable exists in.
What are pointer variables?
They are a special type of variable that can store a memory address instead of a regular value.
How is a pointer variable declared?
Using an asterisk * as in int *pointerInt;
What value does the & in front of a regular variable provide?