What Does This Program Do?
What Does This Program Do?
Frequently, one must use or modify sections of another programmer’s code. Since the original author is often unavailable to explain his/her code, and documentation is, unfortunately, not always available or sufficient, it is essential to be able to read and understand an arbitrary program.
This category presents a program and asks the student to determine that the program does. The programs are written using a pseudocode that should be readily understandable by all programmers familiar with a high-level programming language, such as Python, Java, or C.
Description of the ACSL Pseudo-code
We will use the following constructs in writing this code for this topic in ACSL:
Operators
! (not)
^ or ↑(exponent)
*
/ (real division)
% (modulus)
+
-
>
<
>=
<=
!=
==
&& (and)
|| (or)Functions
abs(x) - absolute value
sqrt(x) - square root
int(x) - greatest integer <= xVariables
Start with a letter, only letters and digits
Sequential statements
INPUT variable
variable = expression (assignment)
OUTPUT variableDecision statements
IF boolean expression THEN
Statement(s)
ELSE (optional)
Statement(s)
END IFIndefinite Loop statements
WHILE Boolean expression
Statement(s)
END WHILEDefinite Loop statements
FOR variable = start TO end STEP increment
Statement(s)
NEXTArrays
1 dimensional arrays use a single subscript such as A(5).
2 dimensional arrays use (row, col) order such as A(2,3).
Arrays can start at location 0 for 1 dimensional arrays and location (0,0) for 2 dimensional arrays.
Most ACSL past problems start with either A(1) or A(1,1).
The size of the array will usually be specified in the problem statement.
Strings
Strings can contain 0 or more characters and the indexed position starts with 0 at the first character.
An empty string has a length of 0.
Errors occur if accessing a character that is in a negative position or equal to the length of the string or larger.
The len(A) function will find the length of the string which is the total number of characters.
Strings are identified with surrounding double quotes.
Use [ ] for identifying the characters in a substring of a given string as follows:
S = “ACSL WDTPD” (S has a length of 10 and D is at location 9)
S[:3] = “ACS” (take the first 3 characters starting on the left)
S[4:] = “DTPD” (take the last 4 characters starting on the right)
S[2:6] = “SL WD” (take the characters starting at location 2 and ending at location 6)
S[0] = “A” (position 0 only).