Xem mẫu
- Table Generated State Values
Column
Ro w
Initial values →
Generated
state values
(2) Values indicating the state (0 or 1) are stored in the two-dimensional array s.
The state values in row 1 and the rows which follow it are generated according to
the following rules from the initial values stored in row 0, as shown in the table
above.
The state value of row i, column j is represented by s[i][j].
All of the values in column 0 are 0.
The values of s[i+1][j] (where j 1) are generated according to the
following table, based on the initial values of s[i][j-1] and s[i][j].
Generated
State values serving as
state value
base
s[i +1][j]
s[i][j-1] s[i][j]
1 1 0
1 0 1
0 1 1
0 0 0
(3) The values of column 0, row 32 in the two-dimensional array s are not output.
24
- Program
Subquestion 1
From the answer group below, select the correct answers to be inserted in the blanks
through in the above program.
Answer group:
a) s[i-1][j-1] b) s[i-1][j] c) s[i-1][j+1]
d) s[i][j-1] e) s[i][j] f) s[i][j+1]
g) s[i+1][j-1] h) s[i+1][j] i) s[i+1][j+1]
25
- Subquestion 2
A graphic such as that shown below was output when the if statement for the
function stschk was changed. From the answer group below, select the if
statement leading to this result.
Answer group:
a) if (( s1==ALIVE ) || ( s2==ALIVE )) return ALIVE;
else return DEAD;
b) if (( s1==ALIVE ) && ( s2==ALIVE )) return ALIVE;
else return DEAD;
c) if (( s1==DEAD ) || ( s2==DEAD )) return DEAD;
else return ALIVE;
d) if ((( s1==ALIVE )&&( s2==DEAD ))||
(( s1==DEAD )&&( s2==ALIVE ))) return ALIVE;
else return DEAD;
26
- Q7. Read the following description of a COBOL program and the program itself, then
answer the subquestion.
[Program Description]
This program collects record counts, itemized by fault code, from a repair status file
in which PC repair statuses are recorded. In addition, it prints the record counts,
itemized by fault code, as well as the corresponding percentages.
(1) The record format in the repair status file is as follows.
Order number Date in Fault code Other information
6 digits 8 digits 3 digits 26 digits
(2) The print format is as follows.
The record counts, itemized by fault code, are 9,999 or less.
The percentage values are obtained by dividing the record counts for each fault
code by the total record count in the repair status file. Values are truncated to
one decimal place.
A header is printed once at the beginning.
[Program]
27
- 28
- Subquestion
From the answer groups below, select the correct answers to be inserted in the blanks
through in the above program.
Answer group for a:
a) b)
c) d)
e) f)
Answer group for b and e:
a)
b)
c)
d)
e)
f)
g)
h)
i)
j)
29
- Answer group for c:
a)
b)
c)
d)
e)
f)
g)
h)
Answer group for d:
a)
b)
c)
d)
30
- Q8. Read the following description of a Java program and the program itself, then answer
the subquestion.
[Program Description]
This program calculates the area of a figure and outputs the result. The figure is a
triangle, rectangle, or square, and is defined in the program as a figure object with the
following attributes.
Triangle: Length of three sides
Rectangle: Length of two sides (vertical and horizontal)
Square: Length of one side
This program is comprised of the following five classes.
AreaTest
This class has the method main, and performs the following processes:
(1) It constructs triangles, rectangles, and square objects, and sets them in array
figures.
(2) It obtains the area of each figure and outputs the result. In this case, it is
assumed that numerical values resulting in correct figures are provided.
Figure
This class is an abstract class of figures. It declares the abstract method getArea,
which calculates the area and returns the result.
Triangle
This class is a triangle class. It defines the method toString, which returns an
attribute as a character string; and the method getArea, which calculates the area of
a triangle using Heron’s Formula and returns the result.
Rectangle
This class is a rectangle class. It defines the method toString, which returns an
attribute as a character string; and the method getArea, which calculates the area of
a rectangle and returns the result.
Square
This class is a square class. It defines the method toString, which returns an
attribute as a character string.
31
- The Program 1 execution results are shown here.
Triangle : sides = 2.0, 3.0, 3.0 : area = 2.8284271247461903
Rectangle : height = 5.0, width = 8.0 : area = 40.0
Square : width = 5.0 : area = 25.0
Fig. Execution Results
[Program 1]
[Program 2]
[Program 3]
}
32
- [Program 4]
[Program 5]
Subquestion
From the answer groups below, select the correct answers to be inserted in the blanks
through in the above programs. The same answer may be
selected more than once.
Answer group for a, b, and d:
a) abstract b) Figure c) getArea
d) Rectangle e) Square f) super
33
- Answer group for c:
a) height b) height * height
c) height * width d) width
e) width * width
Answer group for e:
a) super(height) b) super(height, height)
c) super(width) d) super(width, height)
e) super(width, width) f) this.height = height
g) this.height = width h) this.width = height
i) this.width = width
34
- Q9. Read the following description of an assembler program and the program itself, then
answer subquestions 1 and 2.
[Program Description]
Sixteen connected words are treated as a matrix consisting of four rows and four
columns. The subprogram ROTATE is a program which rotates the contents of
matrix 90° clockwise and stores it in matrix Y.
Word
Word
Word
Word
Matrix X Matrix Y
(1) The leading address of matrix X is set in GR1, and is transferred from a main
program.
(2) The leading address of matrix Y is set in GR2, and is transferred from a main program.
(3) It is assumed that the areas where matrix X and matrix Y are stored do not overlap.
(4) The original contents of the general purpose register are restored when returning
from a subprogram.
35
- [Program]
(Line number)
Move one word from matrix X
to matrix Y
Update matrix X pointer
End of processing for one row?
Go to next row
Subquestion 1
From the answer group below, select the correct answers to be inserted in the blanks
and in the above program.
Answer group:
a) LAD b)
GR2,-16,GR2 LAD GR2,-15,GR2
c) LAD d)
GR2,-14,GR2 LAD GR2,-13,GR2
e) LAD f)
GR2,1,GR2 LAD GR2,2,GR2
g) LAD h)
GR2,3,GR2 LAD GR2,4,GR2
i) LAD j)
GR2,6,GR2 LAD GR2,8,GR2
36
nguon tai.lieu . vn