Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jahfar

macrumors newbie
Original poster
Apr 27, 2016
2
0
london
Logics Test

can someone help me with these questions .

Code:
QUESTION #1: Numeric Constants

Numeric constants are integers which range in magnitude from 0 to 999999999999999 and may be signed or unsigned. Examples of numeric constants are:

0 -13 1300 1 14567 Some invalid numeric constants are:

1.2 not an integer $1 not numeric 1000000000000000 too large

Question: Which of the following is not a legal numeric constant?

[LIST=1]
[*]10.2


[*]-0


[*]00000007


[*]89
[/LIST]






QUESTION #2: String Constants

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), which 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:

A . B. C.



What kind of a constant is this: "4"

Numeric
String
I can't tell - it could be either string or numeric







QUESTION #3: Variable Names

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 ABCA12A0
If a variable is set equal to a string value, such as "##$", it will be a string variable. The very





same variable Question:

A. B. C. D. E. F. G. H.



may be converted to a numeric variable by setting it to a numeric constant. Which of the following variable names can have a string value?

STG
S3
I
A and B (above)
A and C (above)
B and C (above)
A, B and C (above) None of the above.







QUESTION #4: Arrays

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.

Suppose the only variables defined are:

A=0 A(0) =1

= 32767
= "NINETY-NINE"

= "THIS IS A STRING" Question: What is the value of A(A(A+1))?

[LIST=1]
[*]0


[*]32767


[*]1


[*]“THIS IS A STRING”


[*]Undefined
[/LIST]




A(1) A(100) A(32767)







QUESTION #5: Numeric Arithmetic Operators

Operators connect constants and variables to form expressions. The arithmetic operators include:





+ Addition
- Subtraction
* Multiplication / Division
& Minimum
! Maximum
# Modulo



1+2=3
3-2=1
2*3=6
3/2=1 (Integer division only) 2&3=2

2!3=3
13#5=3 (Remainder after division)





An important feature of these, and all operators, is that evaluation in an expression takes place STRICTLY FROM LEFT TO RIGHT. Parentheses may be used to group parts as in algebra.

The & (minimum), ! (maximum), and # (modulo) operators are probably less familiar than the other four operators. Below are some examples of how they can be used:





X#10 =
X&10 =
X!10 =
X!1&10 = X if X is between 1 and 10, 1 is X is less than 1,





Remainder of X/10
X if X is less than 10, otherwise 10
X if X is greater than 10, otherwise 10





and 10 if X is greater than 10 Positive value of X





-X!X =
Question: Now for an example. What is 1+1*3/2+7#12?





[LIST=1]
[*]9


[*]7


[*]0


[*]10


[*]-131071


[*]None of the above
[/LIST]






QUESTION #6: Numeric Comparison Operators

There are three operators for comparing numbers:

< Less than
> Greater than = Equals

You can combine arithmetic and comparison operators in an expression. True evaluates to the "rubout" character (binary, all ones), and False evaluates to "" (nill). Thus, 1+2=3 evaluates to "rubout" and 1+3<2 evaluates to "" (nill).

Question: Suppose A is a variable with a non-zero numeric value. Which of the following is false?

[LIST=1]
[*]A + A=A*2


[*](A#A)>(A/A)


[*]A*A>0


[*]A#A=0
[/LIST]






QUESTION #7: Boolean And

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: Assume the variable A is true, the variable B is true, and the variable C is false. Which of the following is false?

[LIST=1]
[*]A&B&C


[*]B&B


[*]A&B


[*]None of the above
[/LIST]






QUESTION #8: Boolean Or

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?

[LIST=1]
[*]A!C


[*]A&C!B


[*]C!C!B


[*]All of the above


[*]None of the above
[/LIST]






QUESTION #9: Boolean Not

The operator ' (apostrophe) is used to represent the Boolean NOT. If it is applied to an integer or variable it re-evaluates that integer or variable to a "nill" (note, not a zero).

Question: If you were asked for '17 you would answer:

[LIST=1]
[*]True


[*]““


[*]0


[*]14


[*]17


[*]10001
[/LIST]






QUESTION #10: Not Again

The NOT can also be used to modify comparison operators, e.g. 1'>2 (one not greater than two), 2'<1, 1'=2, and A#B'>B are true.

Question: Which of the following is false?

[LIST=1]
[*]‘(A=A)


[*]A’<A


[*]A’=(‘A)


[*]‘A’=A
[/LIST]






QUESTION #11: Unary Operators

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 '1="" '10+0=0 2+3+'3*-3=-15





Question:

A . B. C. D. E.



One of the expressions below is false, which one?

4+’4=’4+4 ‘(‘5)=5 1+’(-3)’>4 -5-5=2+’8*-5 1!2!4!8&’15+0=0







QUESTION #12: String Concatenation

Concatenation means linking together in a series or chain The period (.) is the concatenation operator.

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"?

[LIST=1]
[*]GOD.W A TER


[*]HOLY.WATER


[*]HOLY." ".WATER


[*]GODHOH


[*].GOD.HOL Y


[*]GOD.” “. HOH


[*]GOD.HOH


[*]GOD.. HOH
[/LIST]






QUESTION #13: Integer Concatenation

You can also concatenate integers. For example: 5.5 = 55 678.910 = 678910

Question: What is the value of 1.2+3.4?

[LIST=1]
[*]0


[*]4.6


[*]46


[*]154


[*]1234


[*]Not allowed - illegal syntax
[/LIST]






QUESTION #14: Data Conversion

You can mix integers and non-integers in a single expression. For example:

123."A"="123A" "4A"+123=127 "5.5"+5=10

Non-integers are converted to integers as required by the operators. The non-integer converts to an integer starting with the leftmost character and continuing until encountering a non- numeric character. In the second example above, "4A" converts to 4; in the third example,





"5.5" converts Question:

A. B. C. D. E. F.



to 5.

What is the value of "1.2"+3.4?

4.4
4.6
44
46.2
154
None of the above







QUESTION #15: More on Data Conversion

Question: Suppose A="JOHN", B="JANE", AND C="3DOES". What is the value of 0.A+B+C-3?

[LIST=1]
[*]"0JOHNJANEDOES"


[*]JOHNJANE3DOES


[*]0


[*]3


[*]AandD


[*]BandC


[*]All of the above


[*]None of the above
[/LIST]






QUESTION #16: Set and Kill

Variables are defined dynamically. When you log-in to a system, no variables are defined. In the course of running, a program will define variables via the READ (R) and SET (S) commands, and undefine variables via the KILL (K) command. Notice that commands can be abbreviated to one letter.

As you know, there are two kinds of variables - string and numeric. A variable may be defined via a READ command, in which case it is automatically a string. The other way a variable can be defined is by the SET command which can define it as either string or numeric.

The syntax for the SET command is: S arg1,arg2...argx





S VAR=expression

S VAR1=exp1,VAR2=exp2... S X=Y



Assigns the value of the expression
to the variable VAR. The data type
of VAR is determined by the expression.

Assigns values to multiple variables.

Assigns the value of variable Y to variable X.





Question: If I say: R Z S X=Z, Y=X
What type of variables are X, Y and Z?

[LIST=1]
[*]All string


[*]All numeric


[*]X, Y numeric; Z string


[*]X numeric; Y, Z string


[*]X numeric; Y, Z undefined


[*]Can't tell without more information
[/LIST]






QUESTION #17: More on Set

Question: What is the value of A after executing the following?

S A=1, B=1, C=1, A=1+A+(A-1)

[LIST=1]
[*]5


[*]3


[*]2


[*]1
[/LIST]






QUESTION #18: More on Kill

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?

[LIST=1]
[*]T=6,Z=” “


[*]T=”6”, Z=0


[*]S=”4”,T=6,Z=0


[*]S=”4”,T=”6”,X=”0”


[*]S=”4”,T=”6”,Z=”FALSE”


[*]S=”4”,T=”S+2”,Z=”T>6”


[*]No variables are defined
[/LIST]






QUESTION #19: Final Set and Kill

Question: As a final quiz on SET and KILL, after executing the logic below, what variables are defined and what are their values?

S T=1,B="1",A=1,B=A=T=(T=B) K (A)

[LIST=1]
[*]A=0


[*]A=1


[*]A=3


[*]A=1,B=”1”,T=1


[*]A=131071


[*]B=”1”, T=1
[/LIST]






QUESTION #20: $Piece

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 "," 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 (",")."

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: Assume X is as shown above. What would appear if we executed the statement: WRITE $P(X;1,3)

[LIST=1]
[*]JOHN


[*]JOHN DOE


[*]JOHN DOE; ANYTOWN


[*]JOHN DOE1234 MAINANYTOWN


[*]JOHN DOE; 1234 MAIN; ANYTOWN


[*]An error


[*]Nothing
 
Last edited by a moderator:

0d085d

macrumors regular
Apr 23, 2015
154
12
Many thanks for your reply , I NEED HELP from question 13 to 20 , my answers were
13 : c
14: a
15: f
16: e
17: b
18: b
19 : f
20: c

according to them they all are wrong ! could you please help me . thank you

Question 13

In question 5 it emphasises that operators are applied "STRICTLY FROM LEFT TO RIGHT", so what we're doing in this question is:

Code:
(( 1.2 ) + 3 ) . 4
= (12 + 3) . 4
= 15.4
= 154

Question 14

You've forgotten that . concatenates integers.

Question 15

Code:
0.A+B+C-3
= "0JOHN"+"JANE"+"3DOES"-3
= 0+0+"3DOES"-3
= 0+3-3
= 0

I'm assuming here that casting "JANE" to an integer will result in 0.

Question 16

Let's write what's happening out in full:

Code:
READ Z
SET X=Z
SET Y=X

According to the text in the question, Z is a string. Is that clearer?

Question 17

Note that the '+' operator doesn't change the value of A before SET is run. I suspect what you've done is (1+A)=2, then 2+(2-1)=3, whereas you should have just substituted the value of A in throughout the expression.

Question 18

I'm not actually entirely sure here... T is definitely the *integer* 6, which narrows it to A or C. I think that last kill command is removing S, so I'd go for A. I'm not sure why Z=" " though, from earlier questions I'd expect it to be "" for false.

Question 19

K (A) kills everything EXCEPT A.

Question 20

C is close. Note that 1,3 means "take the first THROUGH the third pieces", so you have to include the second piece as well.
 
Last edited:

stats-coder

macrumors newbie
Dec 26, 2023
1
0
The answers are as follows:
  1. B (-0 does not exist)
  2. B (String)
  3. G (A, B, and C)
  4. D "THIS IS A STRING"
  5. C (0)
  6. B (A#A)>(A/A)
  7. A (A&B&C)
  8. E (None of the above)
  9. B (" ")
  10. A '(A=A)
  11. D (-5-5=2+’8*-5)
  12. G (GOD.HOH)
  13. C (46)
  14. A (4.4)
  15. A ("0JOHNJANEDOES")
  16. A (All string)
  17. C (2)
  18. A (T=6,Z=” “)
  19. F (B=”1”, T=1)
  20. C (JOHN DOE; ANYTOWN)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.