CTC Test
CTC Test
PROGRAMMING TEST
NUMERIC CONSTANTS
Question #1
Numeric constants are integers. I repeat, integers. They range in
magnitude from 0 to 999999999999999 and may be signed or unsigned.
Examples of numeric constants are:
0
-13
1300
14567
STRING CONSTANTS
Question #2
A string constant is a sequence of 0 to 255 characters chosen from the
standard ASCII 64 character set.
Any legal character (alpha or numeric) may be used as a string and is
designated as such when included in quotation marks (i.e. ABC).
A string constant can also consist of zero characters, that is,
quotation marks around no characters. This is referred to as the nill
or null string.
Some examples are:
ABCDEF
123456
!!!$$
When string constants are read in or written out, the quotation marks
are omitted.
Question:
String
B.
Numeric
C.
I cant tell.
numeric.
VARIABLE NAMES
Question #3
A constant retains its value, by definition. The value of a variable
may be changed in the course of a program. A variable may take on any
value that is allowable for either a string or numeric constant.
Unlike some other programming languages (e.g. FORTRAN), the type of
variable is not determined by the name or any kind of declaration.
Variable names are in the format of 1 alphabetic character, followed
by any number of other alphanumeric characters.
Here are some examples of acceptable variable names:
A
ABC
A12
A0
ARRAYS
Question #4
In addition to scalar variables, there are also single dimension
arrays, among others.
The rules for naming arrays are the same as the rules for naming
variables.
Unlike almost all other programming languages, there is no need (and
no capability) for declaring array dimension. An element of an array
is undefined until you put something into it. The only space used in
the system is for those array elements which are defined.
There is also no restriction on the data types of different array
elements. Thus you can have string and numeric values within the same
array.
Question:
The
=
=
=
=
-X!X
Question:
Remainder of X/10
X if X is less than 10, otherwise 10
X if X is greater than 10, otherwise 10
X if X is between 1 and 10,
1 if X is less than 1, and
10 if X is greater than 10
Positive value of X
Now for an example.
What is 1+1*3/2+7#12?
A. 9
B. 7
C. 10
D. 0
E. 131071
F. None of the above
Less than
Greater than
Equals
BOOLEAN AND
Question #7
Simple in concept, though sometimes complicated in practice, are the
Boolean operators, & (AND), ! (OR), and ' (NOT).
The symbol & is the Boolean operator for ANDing.
If applied against logical true and false statements, both statements
must be true in order for the AND statement to be true. That is, if
the variables A and B are both true, the statement A&B is true, while
if either A or B (or both A and B) are false, the statement A&B is
false.
Question:
BOOLEAN OR
Question #8
The ! is used as the Boolean OR operator.
The logical OR appears between two values or expressions. If either
expression is true, the entire statement is evaluated as true. For
example, in the expression A!B if either variable is true (or if both
variables are true), the expression is evaluated as true.
Question:
Assume that the variable A is true, the variable B is
true, and the variable C is false. Which of the following is false?
A.
A!C
B.
A&C!B
C.
C!C!B
D.
C&A!C
BOOLEAN NOT
Question #9
The operator ' (apostrophe) is used to represent the Boolean NOT. If
it is applied to an integer or a non-nill (true) variable it
reevaluates that integer or variable to a nill (note, not a zero).
When applied to a variable where value is nill (false) it reevaluates
that variable to the rubout character (true).
Question:
17
B.
14
C.
10001
D.
True
E.
F.
NOT AGAIN
Question #10
The NOT can also be used to modify comparison operators, e.g. 1'>2
(one not greater than 2), 2'<1, 1'=2, and A#B'>B are true.
Question:
'A'=A
B.
A'=('A)
C.
A'<A
D.
'(A=A)
UNARY OPERATORS
Question #11
The (minus) and the ' (not) are also referred to as Unary
operators and may be used in arithmetic expressions. When used in
this way, they apply to the value immediately to their right, BEFORE
it is evaluated in the expression.
In arithmetic expressions, the nill string is evaluated as a zero,
while in logical expressions it is evaluated as a false. For example,
the expression '1 is evaluated as a nill; when it is used in the
arithmetic expression 1+'1 the value of the expression would be 1, but
when used logically in the expression 0='1, the expression is false.
Other examples:
-3=-3
Question:
'1=
'10+0=0
2+3+'3*-3=-15
1!2!4!8&'15+0=0
B.
5-5=2+'8*-5
C.
1+'(-3)'>4
D.
'('5)=5
E.
4+'4='4+4
STRING CONCATENATION
Question #12
Concatentation means linking together in a series or chain.
period (.) is the concatenation operator.
The
For example:
HI .THERE is the same as HI THERE
HI. THERE is the same as HI THERE
Question:
If GOD has the value HOLY and HOH has the value
WATER, how do you make HOLY WATER?
A.
GOD.WATER
B.
HOLY.WATER
C.
HOLY. .WATER
D.
GODHOH
E.
.GOD.HOLY
F.
GOD.HOH
G.
GOD..HOH
H.
GOD. .HOH
INTEGER CONCATENATION
Question #13
You can also concatenate integers.
For example:
5.5 = 55
678.910 = 678910
Question:
4.6
B.
46
C.
D.
1234
E.
154
F.
DATA CONVERSION
Question #14
You can mix integers and non-integers in a single expression.
example:
123.A = 123A
4A+123 = 127
For
5.5 + 5 = 10
44
B.
4.6
C.
154
D.
4.4
E.
46.2
F.
0JOHNJANEDOES
B.
C.
JOHNJANE3DOES
D.
E.
A and D
F.
B and C
G.
H.
If I say: R Z S X=Z,Y=X
What type of variables are X, Y and Z?
A.
All numeric
B.
All string
C.
X, Y numeric; Z string
D.
X numeric; Y, Z string
E.
X numeric; Y, Z undefined
F.
MORE ON SET
Question #17
Question:
B.
C.
D.
MORE ON KILL
Question #18
There is a KILL command which removes a variable and its value from
the symbol table, thus undefining it.
The syntax for the KILL is:
K
A KILL command followed by 2 spaces kills all
variables
K VAR
The variable VAR is killed, if it exists
K (VAR,VAS) All variables except VAR and VAS are killed
The most common use of KILL is to free storage space. Another use is
to flag conditions if a particular value is defined, that means one
thing; and if it is undefined, that means something else.
Question:
K S S=4,T=S+2,Z=T>6 K K,J,S
What variables are defined and what are their values?
A.
S=4,T=S+2,Z=T>6
B.
S=4,T=6,Z=FALSE
C.
S=4,T=6,X=0
D.
S=4,T=6,Z=0
E.
T=6,Z=0
F.
T=6,Z=
G.
A=1,B=1,,T=1
B.
B=1,T=1
C.
A=0
D.
A=131071
E.
A=3
F.
A=1
$PIECE
Question #20
The $PIECE function is a useful string-valued function. It returns a
sub-string of a base string as defined by a delimiter and one or more
positional indicators. For example:
$P(ONE,TWO,THREE,FOUR,,2)=TWO
This is because the base string (inside the quotes) is
ONE,TWO,THREE,FOUR,. The delimiter is the comma and the 2 is the
positional indicator. This statement says, take the second piece out
of the variable with the piece defined as the portion of the variable
placed between the defined delimiter (comma in this case).
There is an optional argument that allows for the definition of the
positional indicator to multiple places (i.e. take the second through
the fourth pieces would be indicated by replacing the positional
indicator with 2,4).
Further examples:
S X= JOHN DOE;1234 MAIN;ANYTOWN
$P(X;1)=JOHN DOE
$P(X;2)=1234 MAIN
$P(X;2,3)=1234 MAIN;ANYTOWN
Question:
WRITE $P(X;1,3)
A.
JOHN DOE
B.
JOHN DOE;ANYTOWN
C.
An error
D.
Nothing
E.
JOHN DOE1234MAINANYTOWN
F.
JOHN
G.