Dòng Ni dung đ c sa

Một phần của tài liệu FUNDAMENTAL IT ENGINEER EXAMINATION (NETWORK)(AFTERNOON) docx (Trang 65 - 80)

1 CNT1 START 2 LAD GR2,0 3 LD GR1,GR1 4 JZE FIN 5 PUSH 0,GR1 6 LP JPL NCNT 7 LAD GR2,1,GR2 8 NCNT SLL GR1,1 9 JNZ LP 10 POP GR1 11 FIN RET 12 END Câu h i con 1

N u #BCA0đ c l u gi trong GR1 và ch ng trình con CNT1đ c g i, thì ch ng trình con

r nhánh bao nhiêu l n t i NCNT khi dòng s 6 đ c th c hi n? Hãy ch n t các s d i đây. Nhóm câu tr l i:

a) 4 b) 5 c) 7 d) 8 e) 9

Câu h i con 2

s a đ i ch ng trình g c sao cho nó tính s các bit “0” trong GR1 và l u gi s đó vào trong GR2, dòng s 2 ban đ u đ c đ i thành “LAD GR2,16”. Nh ng dòng nào khác còn c n ph i đ i và đ i nh th nào? Ch n câu tr l i đúng trong nhóm d i đây.

Nhóm câu tr l i:

S dòng N i dung đ c s a

a) 4 JMI NCNT

Sub-Question 3

To test another algorithm, a program for counting the number of "1" bits was rewritten as follows. Which of the following instructions could be used in blanks a and

b below so that the program can obtain the same results before the change? Select the correct answers from the answer groups below.

(Line number) 1 CNT1 START 2 LAD GR2,0 3 LD GR1,GR1 4 a 5 PUSH 0,GR1 6 LP SLL GR1,1 7 b 8 JUMP NCNT 9 CNT LAD GR2,1,GR2 10 NCNT JNZ LP 11 POP GR1 12 FIN RET 13 END

Answer group for “a”:

a) JNZ CNT b) JNZ NCNT c) JNZ FIN

d) JZE CNT e) JZE NCNT f) JZE FIN

Answer group for “b”:

a) JPL CNT b) JMI CNT c) JOV CNT

Câu h i con 3

ki m tra thu t toán khác, m t ch ng trình đ m s các bit "1" đã đ c vi t l i nh sau. L nh nào trong nh ng l nh sau có th đ c dùng trong các ch tr ng a và

b d i đây sao cho ch ng trình có th thu đ c cùng k t qu nh tr c khi thay

đ i? Ch n câu tr l i đúng t nhóm d i đây. (S dòng) 1 CNT1 START 2 LAD GR2,0 3 LD GR1,GR1 4 a 5 PUSH 0,GR1 6 LP SLL GR1,1 7 b 8 JUMP NCNT 9 CNT LAD GR2,1,GR2 10 NCNT JNZ LP 11 POP GR1 12 FIN RET 13 END

Nhóm câu tr l i cho “a”:

a) JNZ CNT b) JNZ NCNT c) JNZ FIN

d) JZE CNT e) JZE NCNT f) JZE FIN

Nhóm câu tr l i cho “b”:

a) JPL CNT b) JMI CNT c) JOV CNT

Select one of the following four questions (Q10, Q11, Q12, or Q13). Be sure to mark on your answer sheet the “Select” circle corresponding to the question you have selected. If you select more than one question, only the first answer will be graded.

Q10. Read the following description of a C program and the program itself, then answer the sub- question.

[Program Description]

A program written in a programming language with macro facility is stored in the

source_file. The macro names in this source_file are replaced by the token

strings in the definitions to create dest_file.

(1) The program code that uses the macro definitions and macro names is stored in the

source_file.

(2) The program code containing the replacements of macro names is stored in the

dest_file. However, the macro definitions of the source-file are not written into

it.

(3) The macro definition has the following form.

$STRDEFmacro name token string

$STRDEF starts at the first character position and there is one space separating

$STRDEF and the macro name, and one space separating the macro name and the

token string.

(4) The macro definition for one macro name can be done only once.

(5) Macro names (separated by delimiter characters) which appear after macro

definitions in the source_file are replaced by the token strings. However, the line of a macro definition is not replaced.

(6) The following delimiters | to ¡ are used. They are stored in the character type array

delmchar.

| Space

~ Graphic characters !"#%&'()*+,-./:;<=>?[\]^_{|}~

¡ Newline character

char delmchar[]=" !\"#%&'()*+,-./:;<=>?[\\]^_{|}~\n";

Ch n m t trong b n câu h i sau (Q10, Q11, Q12, hay Q13). Hãy ch c ch n đánh d u vào t tr l i c a b n vòng tròn “Select” ng v i câu h i b n đã ch n.

N u b n ch n nhi u câu h i, ch câu tr l i đ u tiên đ c ch m.

Q10. Hãy đ c mô t d i đây v ch ng trình C và b n thân ch ng trình, r i tr l i câu h i con. [Mô t ch ng trình]

M t ch ng trình vi t b ng ngôn ng l p trình có tính n ng macro đ c l u gi trong

source_file. Các tên macro trong source_file này đ c thay th b ng xâu hi u

bài (token) trong các đnh ngh a đ t o ra dest_file.

(1) Mã ch ng trình dùng các đnh ngh a macro và các tên macro đ c l u gi trong source_file.

C

(2) Mã ch ng trình ch a nh ng thay th tên macro đ c l u gi trong

dest_file. Tuy nhiên, các đnh ngh a macro c a t p ngu n này không đ c ghi

vào đó.

(3) Các đnh ngh a macro có d ng sau.

$STRDEFtên macro xâu hi u bài

$STRDEF b t đ u t i v trí kí t th nh t và có m t d u cách tách $STRDEF

v i tên macro, và m t d u cách tách tên macro và xâu hi u bài.

(4) nh ngh a macro cho m t tên macro ch có th đ c th c hi n m t l n.

(5) Các tên macro (phân tách b i các kí t đnh biên) xu t hi n sau các đnh ngh a macro trong source_fileđ c thay th b i xâu hi u bài. Tuy nhiên, dòng đnh ngh a macro l i không đ c thay th .

(6) Các ký t đnh biên | t i ¡ sau đ c dùng. Chúng đ c l u gi trong m ng ki u kí

t delmchar.

| D u cách

~ Các kí t đ ho !"#%&'()*+,-./:;<=>?[\]^_{|}~

¡ Kí t xu ng dòng

char delmchar[]=" !\"#%&'()*+,-./:;<=>?[\\]^_{|}~\n";

(7) The macro name and token string do not contain delimiters. (8) Up to 20 macro definitions appear in the source_file.

(9) The macro name and token ring can be up to 31 characters in length.

(10) Each line before and after the replacement ends with a newline character and can contain up to 255 characters.

(11) Specifications for the strchr function used in the program are as follows.

char *strchr(const char *s, int c)

Process: Searches for the first appearance of c (converted to char

type) in the character string specified by s. The null marking the end of the character string is treated as part of the

character string.

Returned value: The pointer to the found character is returned. If the character does not exist in the string, a null pointer (NULL) is returned. (12) An example of program execution is given below.

source_file dest_file $STRDEF $$TITLE HELLO

$STRDEF $$SIGN BILLY $STRDEF $$LENG 8 MSG START OUT $$TITLE,6 IN BUF,$$LEN G OUT BUF,$$LEN G OUT $$SIGN,6 EXIT $$TITLE DC 'Hello!' $$SIGN DC 'Billy' BUF DS $$LENG END MSG START OUT HELLO,6 IN BUF,8 OUT BUF,8 OUT BILLY,6 EXIT HELLO DC 'Hello!' BILLY DC 'Billy' BUF DS 8 END

Example of Program Execution

[Program]

#include <stdio.h> #include <string.h> #define MCRDEF 20

(7) Tên macro và xâu hi u bài không ch a các ký t đnh biên.

(8) T i đa là 20 đnh ngh a macro đ c xu t hi n trong source_file. (9) Tên macro và xâu hi u bài có th dài t i đa t i 31 kí t .

(10) M i dòng tr c và sau ch thay th k t thúc b ng m t kí t xu ng dòng và có th ch a t i đa t i 255 kí t .

(11) c t cho hàm strchrđ c dùng trong ch ng trình này nh sau.

char *strchr(const char *s, int c)

X lí: Tìm l n xu t hi n đ u tiên c a c (đ c chuy n thành ki u

char) trong xâu kí t đ c xác đnh b i s. Ký t null đánh d u cu i c a xâu kí t đ c coi là m t ph n c a xâu kí t . Giá tr cho l i: Cho l i con tr t i kí t tìm đ c. N u không t n t i kí t này trong xâu, thì cho l i con tr null (NULL).

(12) Ví d th c hi n ch ng trình đ c cho d i đây.

C

source_file dest_file $STRDEF $$TITLE HELLO

$STRDEF $$SIGN BILLY $STRDEF $$LENG 8 MSG START OUT $$TITLE,6 IN BUF,$$LEN G OUT BUF,$$LEN G OUT $$SIGN,6 EXIT $$TITLE DC 'Hello!' $$SIGN DC 'Billy' BUF DS $$LENG END MSG START OUT HELLO,6 IN BUF,8 OUT BUF,8 OUT BILLY,6 EXIT HELLO DC 'Hello!' BILLY DC 'Billy' BUF DS 8 END Ví d th c hi n ch ng trình [Ch ng trình] #include <stdio.h> #include <string.h> #define MCRDEF 20 #define STRLNG 32

char linbuf[LINLNG], token[LINLNG][LINLNG], delm[LINLNG]; char label[] = "$STRDEF";

char delmchar[] = " !\"#%&'()*+,-./:;<=>?[\\]^_{|}~\n"; main() {

FILE *sfp, *dfp;

int mcrcnt = 0, tokcnt, flg, idx1, idx2;

char orig[MCRDEF][STRLNG], expand[MCRDEF][STRLNG]; sfp = fopen("source_file", "r");

dfp = fopen("dest_file", "w");

while(fgets(linbuf, LINLNG, sfp) != NULL) { tokcnt = divide_line(); if(strcmp(token[0], label) == 0) { strcpy(orig[mcrcnt], token[1]); strcpy(expand[mcrcnt], token[2]); a ; } else {

for(idx1 = 0; idx1 < b ; idx1++) { flg = 0;

for(idx2 = 0; idx2 < mcrcnt; idx2++)

if(strcmp(token[idx1], orig[idx2]) == 0) { flg = 1;

break; }

if( c )

fprintf(dfp, "%s%c", token[idx1], delm[idx1]); else

fprintf(dfp, "%s%c", expand[idx2], delm[idx1]); } } } fclose(sfp); fclose(dfp); } int divide_line() {

int tokcnt = 0, lidx = 0, tidx; do {

for(tidx = 0; strchr(delmchar, linbuf[lidx]) == NULL; lidx++, tidx++) token[tokcnt][tidx] = linbuf[lidx]; token[tokcnt][tidx] = d ; delm[tokcnt] = e ; f ; tokcnt++; } while(linbuf[lidx - 1] != '\n'); return tokcnt; }

C

char linbuf[LINLNG], token[LINLNG][LINLNG], delm[LINLNG]; char label[] = "$STRDEF";

char delmchar[] = " !\"#%&'()*+,-./:;<=>?[\\]^_{|}~\n"; main() {

FILE *sfp, *dfp;

int mcrcnt = 0, tokcnt, flg, idx1, idx2;

char orig[MCRDEF][STRLNG], expand[MCRDEF][STRLNG]; sfp = fopen("source_file", "r");

dfp = fopen("dest_file", "w");

while(fgets(linbuf, LINLNG, sfp) != NULL) { tokcnt = divide_line(); if(strcmp(token[0], label) == 0) { strcpy(orig[mcrcnt], token[1]); strcpy(expand[mcrcnt], token[2]); a ; } else {

for(idx1 = 0; idx1 < b ; idx1++) { flg = 0;

for(idx2 = 0; idx2 < mcrcnt; idx2++) if(strcmp(token[idx1], orig[idx2]) == 0) { flg = 1;

break; }

if( c )

fprintf(dfp, "%s%c", token[idx1], delm[idx1]); else

fprintf(dfp, "%s%c", expand[idx2], delm[idx1]); } } } fclose(sfp); fclose(dfp); } int divide_line() {

int tokcnt = 0, lidx = 0, tidx; do {

for(tidx = 0; strchr(delmchar, linbuf[lidx]) == NULL; lidx++, tidx++) token[tokcnt][tidx] = linbuf[lidx]; token[tokcnt][tidx] = d ; delm[tokcnt] = e ; f ; tokcnt++; } while(linbuf[lidx - 1] != '\n'); return tokcnt; }

Sub-Question

From the answer groups below, select the correct answers to insert in blanks

a through f in the above program.

Answer group for “a”:

a) idx1 = 0 b) idx1++ c) idx2 = 0

d) idx2++ e) mcrcnt = 0 f) mcrcnt++

g) tokcnt = 0 h) tokcnt++

Answer group for “b”:

a) idx2 b) idx2++ c) mcrcnt

d) mcrcnt++ e) tokcnt f) tokcnt++

Answer group for “c”:

a) flg = 0 b) flg == 0 c) flg = 1

d) flg == 1 e) idx2 = 0 f) idx2 > 0

g) idx2 < mcrcnt h) idx2 = mcrcnt

Answer group for “d” and “e”:

a) '\0' b) '\n' c) delm[lidx]

d) delm[tidx] e) linbuf[lidx] f) linbuf[tidx]

g) token[lidx] h) token[tidx]

Answer group for “f”:

a) lidx = 0 b) lidx++ c) tidx = 0

Câu h i con

T nhóm câu tr l i d i đây, hãy ch n các câu tr l i đúng đ đi n vào ch tr ng

a t i f trong ch ng trình trên.

Nhóm câu tr l i cho “a”:

a) idx1 = 0 b) idx1++ c) idx2 = 0

d) idx2++ e) mcrcnt = 0 f) mcrcnt++ g) tokcnt = 0 h) tokcnt++ Nhóm câu tr l i cho “b”: a) idx2 b) idx2++ c) mcrcnt d) mcrcnt++ e) tokcnt f) tokcnt++ C Nhóm câu tr l i cho “c”: a) flg = 0 b) flg == 0 c) flg = 1 d) flg == 1 e) idx2 = 0 f) idx2 > 0 g) idx2 < mcrcnt h) idx2 = mcrcnt

Nhóm câu tr l i cho “d” và “e”:

a) '\0' b) '\n' c) delm[lidx]

d) delm[tidx] e) linbuf[lidx] f) linbuf[tidx]

g) token[lidx] h) token[tidx]

Nhóm câu tr l i cho “f”:

a) lidx = 0 b) lidx++ c) tidx = 0

Q11. Read the following description of a COBOL program and the program itself, then answer the sub-question.

[Program Description]

The program reads a file containing character string data, decomposes it into paragraphs to be put together in sequence, and outputs the results as a file. The character string data is partitioned into records of a fixed length and stored sequentially in the file. This file is read one record at a time and a single paragraph is reconstructed as a single record and

outputted to the file. Each character in the character string data is stored in just one character position of an input/output record.

(1) The character string data is configured as follows.

| The character string data is a set of one or more paragraphs.

~ A paragraph is configured with alphabetical characters, numerical characters, spaces, commas, periods and semicolons.

¡ The semicolon appears as the last character in each paragraph and does not appear anywhere else.

¢ The length of a single paragraph varies. Excluding the semicolon, the length can be from 0 to 1,000 characters or less.

COBOL∆is∆an∆industry∆language.;An∆implementation∆may∆flag∆violations∆ of∆rules.;;This∆statement∆provides∆the∆ability∆to∆tally∆or∆replace∆ occurrences∆of∆single∆characters∆or∆sequences∆of∆characters∆in∆a∆ data∆item.;

Fig. 1 Example of Character String Data (A spaces indicated by ∆)

(2) The input file format is as follows.

| The file contains sequential records of a fixed length of 100 characters per record.

~ When the length of the character string data is not a multiple of 100, spaces are added after the semicolon at the end of the paragraph to make it 100 characters. (3) The output file format is as follows.

| The file contains sequential records of a fixed length of 1,000 digits per record.

~ One record stores one paragraph.

Q11. Hãy đ c gi i thích d i đây v ch ng trình COBOL và b n thân ch ng trình, r i tr l i câu h i con.

[Mô t ch ng trình]

Ch ng trình đ c m t t p ch a d li u xâu kí t , phân tách nó thành các đo n đ c đ t tu n t cùng nhau, r i đ a k t qu ra nh m t t p. D li u xâu kí t đ c phân chia thành các b n ghi đ dài c đnh và đ c l u gi m t cách tu n t trong t p. T p này đ c đ c vào theo t ng b n ghi m i l n và m t đo n đ n đ c c u trúc l i nh m t b n ghi đ n và

đ c đ a ra t p. M i kí t trong d li u xâu kí t đ c l u gi ch m t v trí kí t c a b n ghi vào/ra.

(1) D li u xâu kí t có c u t o nh sau.

| D li u xâu kí t là m t t p g m m t hay nhi u đo n.

~ o n đ c c u t o b i các kí t ch , kí t s , d u cách, d u ph y, d u ch m và d u ch m ph y.

¡ D u ch m ph y xu t hi n nh kí t cu i trong t ng đo n và không xu t hi n

đâu khác.

¢ Chi u dài c a m i đo n thay đ i. Không tính d u ch m ph y, chi u dài có th t 0 t i 1,000 kí t hay ít h n.

COBOL∆is∆an∆industry∆language.;An∆implementation∆may∆flag∆violations∆ of∆rules.;;This∆statement∆provides∆the∆ability∆to∆tally∆or∆replace∆ occurrences∆of∆single∆characters∆or∆sequences∆of∆characters∆in∆a∆ data∆item.;

Hình 1 Ví d d li u xâu kí t (d u cách đ c ch ra b ng ∆)

(2) nh d ng t p vào nh sau.

| T p ch a các b n ghi tu n t v i chi u dài c đnh g m 100 kí t m i b n ghi.

~ Khi chi u dài c a d li u xâu kí t không ph i là b i c a 100, các d u cách s

đ c thêm vào sau d u ch m ph y t i cu i c a đo n đ làm cho nó thành 100 kí t .

(3) nh d ng t p ra nh sau.

| T p ch a các b n ghi tu n t v i chi u dài c đnh g m 1000 ch s cho m i b n ghi.

(4) Input and output files for the character string data given in Figure 1 above are shown in Figures 2 and 3 respectively.

COBOL∆is∆an∆industry∆language.; ;This∆statement∆provi des∆the∆ability∆to∆tally∆or∆re es∆of∆characters∆in∆a

∆data∆item.; ∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆

Fig. 2 Example of Input File (A spaces indicated by ∆)

COBOL∆is∆an∆industry∆language.∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆

An∆implementation∆may∆flag∆violations∆of∆rules.∆ ∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆ ∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆

This∆statement∆provides∆the∆ability∆to∆tally∆or∆ ∆a∆data∆item. ∆∆∆

Fig. 3 Example of Output File (A spaces indicated by ∆)

(5) The syntax and operation of the INSPECT statement used in the program are as follows.

[Syntax]

1,000 digits 100 digits

INSPECT unique name 1 TALLYING unique name 2 FOR CHARACTERS BEFORE unique name 3

[Unique name restrictions]

Unique name 1: Data item the usage of which is DISPLAY explicitly or implicitly.

Unique name 2: Numeric items.

Unique name 3: Data item the usage of which is DISPLAY explicitly or implicitly and the length of which is one character. [Operation]

The content of unique name 1 is examined from the left most position and all

occurrences of a character before the first occurrence of the content of unique name 3 are added to unique name 2. If the content of unique name 3 does not occur in unique name 1, the number of characters from the left most position through the right most position of unique name 1 is added to unique name 2.

(4) Các t p vào và ra đ i v i d li u xâu kí t đ c cho trong Hình 1 trên đây đ c nêu trong Hình 2 và 3 t ng ng.

COBOL∆is∆an∆industry∆language.; ;This∆statement∆provi des∆the∆ability∆to∆tally∆or∆re es∆of∆characters∆in∆a

∆data∆item.; ∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆

Hình 2 Ví d v t p vào (d u cách đ c ch ra b ng ∆)

COBOL∆is∆an∆industry∆language.∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆

An∆implementation∆may∆flag∆violations∆of∆rules.∆ ∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆ ∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆∆∆∆∆∆∆∆∆∆ ∆∆∆

This∆statement∆provides∆the∆ability∆to∆tally∆or∆ ∆a∆data∆item. ∆∆∆

Hình 3 Ví d v t p ra (d u cách đ c ch ra b ng ∆)

(5) Cú pháp và v n hành c a câu l nh INSPECTđ c dùng trong ch ng trình này nh sau.

[Cú pháp]

INSPECT unique name 1 TALLYING unique name 2 FOR CHARACTERS BEFORE unique name 3

[Các h n ch đ i v i unique name]

Unique name 1: M c d li u có vi c s d ng là HI N TH t ng minh hay không t ng minh.

Unique name 2: Các m c s .

Unique name 3: M c d li u có vi c s d ng là HI N TH t ng minh hay

Một phần của tài liệu FUNDAMENTAL IT ENGINEER EXAMINATION (NETWORK)(AFTERNOON) docx (Trang 65 - 80)

Tải bản đầy đủ (PDF)

(113 trang)