----- is a combination of operators
and operands that ----- |
An expression is; that
expresses a value. |
----- is a group of (zero or more)
statements delimited by a set of braces, { }. |
A compound statement (= a block). |
----- is a sequence of data that
comes from a particular source and is available and waiting
to be moved to a particular destination. |
A stream. For the cin stream, it waits in
the buffer |
"Using functions as parameters"
means ----- |
you replace an argument with a function call
that returns a value of the same data type. |
(Arguments/Parameters) appear
in the function call whereas (arguments/parameters) are
the position-matched variables in the function and appear
in the function's declaration and function header. A function's
value parameters are used to receive data supplied by ----- |
Arguments; parameters;
the calling statement. |
* indicates a ----- |
pointer. |
A ----- is a program statement
or expression that transfers control to a function so that
it will perform its subtask. |
function call. |
A ----- is a variable that contains
the address of a memory location as its value. |
pointer. |
A caret looks like ---- |
(
|
address-of operator looks like
----- |
& |
Alphabetise:
How to sort 3 variables into order? |
void main () {
string w1, w2, w3;
… // user inputs 3 words
if (w1>w2) swap(w1, w2); // see Swap, below
if (w1>w3) swap(w1, w3);
if (w2>w3) swap(w2, w3); then cout… } |
An absolute number is ----- |
The numerical value of a real number without
regard to its sign. Eg, the absolute value of -4 is 4. |
Arguments that are used for both
input and output are passed by ----- |
reference. |
Array memory cells can called
which 3 names? |
Components, elements, cells. |
Array_name[3] is read out (ie,
spoken) as ------ |
array name sub (or subscript) 3. |
Arrays can be depicted (horizontally
/ vertically). |
Both. |
Arrays cannot be passed by value.
Right/wrong? |
Right. They're either passed by reference
or by const reference. |
Arrays: Write code to add 2 arrays
element by element, and store the result in a corresponding
element in array3. |
void add_arrays (int size, const float a[],
const float b[], float c[]) … {
int i; for
(i=0; i < size; i++)
{ c[i] = a[i] + b[i]; } return;
} |
Assigning a float to an integer
causes ----- |
the output to be truncated. |
Associativity: Which is processed
first? |
Left before right. |
C++ defines string type in which
header file? |
string (now that wasn’t hard, was it?) |
cin >> removes the trailing newline
character from its stream. Right? |
Wrong. |
Columns: In what column will the
E of AGE be output? name is a string, age is an int. cout<<"NAME"< cout< |
E will be in column 16 because NAME uses
4 spaces, then setw(12) creates a zone of width 12. The
right edge of this zone is in column 16 because 4 + 12 =
16. |
Comparing arrays: Impress us with
your skill. Write a code fragment to show us how it's done.
|
int compare_arrays (int size, const float
a{}, const float b[]) {
int i = 0; // loop control variable and array subscript while
( (i
i++; // why?? return
(a[i] == b[i] ); }
{ int i = 0; // loop control variable and array subscript while(i < size) { i++; if (a[i] != b[i] ) return 0; //comparison failed, The arrays are different } return 1; //comparison passed, The arrays are the same. } |
cout is (an object / a function). |
object. |
Declare the datatype for the value
returned by a function at the place where ----- |
you name the function to be defined. (Later
you copy this up into the prototypes section.) |
Declare the datatype of each parameter
in each function at the place where ----- |
you introduce the parameter. |
do {statement;} % while (expression)
% What replaces the % signs? |
Nothing, then a semicolon. |
Does the scope of a variable called
in main include the bodies of functions called by main? |
No. A variable declared inside main has its
scope limited to the body of main. |
Expressions take {} and statements
take (). True? |
Nope. (Hint: It's the other way around.) |
Fill an array of 4 numbers interactively,
using a for loop, then output it all showing which element
each number was found in. |
cout<< "Enter 4 values: "; for (i=0; i < 4; i++) cin>> my_array[i]; for (i=0; i < 4; i++) cout<< "my_array[" <<<"] = " < |
for (initiation_exp; stop_condn;
update_exp) & statement & What replaces the & signs? |
Nothing, then a semicolon. |
Fractions: How to divide 1 fraction into
another? |
Invert one fraction and multiply.
|
Fractions: How to return the next whole number
up? |
Use ceil (in the math.h library).
|
Functional programming languages
rely heavily on recursion where procedural languages use
---- |
iteration. |
Home |