1. Trang chủ
  2. » Giáo án - Bài giảng

nguyên lý ngôn ngữ lập trình nguyễn hứa phùng sequence control sinhvienzone com

6 59 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 6
Dung lượng 207,73 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Rewrite the following infix expression using the Polish prefix format?. Assume that every operator has only 2 operands.. 7 In some language like ADA, there are two kinds of AND/OR operat

Trang 1

Sequence Control

Return to Assessment List

Rewrite the following infix expression using Cambridge Polish prefix format?

a + b * c + d + e * f

A (+ a (* b c) d (* e f))

B + + + a * b c d * e f

C (+ (+ (+ a (* b c)) d) (* e f))

D (((a + (b * c)) + d) + (e * f))

E + a * b c d * e f

Rewrite the following infix expression using the Polish postfix format?Assume that all operators have 2 operands

a + b * c + d + e * f

A a + b c * d + e f * +

B a b c * d e f * + + +

C a b c * d e f * +

D a b + c * d + e f * +

E a b c * + d + e f * +

SinhVienZone.Com

Trang 2

Rewrite the following infix expression using the Polish prefix format? Assume that every

operator has only 2 operands

a + b * c + d + e * f

A + a * b c + + d * e f

B + a * b c d * e f

C + + a * b c + d * e f

D + + + a * b c d * e f

E + a * b c + d * e f

Select all possible result of the following C expression:

a + (a = 2) * a

Assume that variable a contains value 3 before the above expression is evaluated

A 10

B 6

C 9

D 8

E 7

In some language like ADA, there are two kinds of AND/OR operator: short-circuit (AND THEN) and non-short circuit(AND).Select logical expressions that are required short-circuit evaluation?

A (a == 0) || ((b / a) > 5)

B (a > 0) && (b > 0)

C (a != b) && (a * b > 0)

D (a > 0) && (sqrt(a) > 2) //sqrt is the function to calculate the square root of its

parameter

SinhVienZone.Com

Trang 3

E (i < a.length) && (a[i] > 0)

Given the grammar of if statement, select the language that there is NO dangling else problem

A <stmt> → if <expr> then <stmt> else <stmt>

B <stmt> → if <expr> then <stmt> else <stmt> endif

| if <expr> then <stmt> endif

C <stmt> → if <expr> \n (<indentation><stmt> \n)+ else \n (<indentation><stmt> \n)+ | if <expr> \n (<indentation><stmt> \n)+

D <stmt> → if (<expr>) <stmt> else <stmt>

| if (<expr>) <stmt>

E <stmt> → if <expr> then <stmt> else <stmt>

| if <expr> then <stmt>

which switch statement can be implemented using jump table?

A switch (x) {

1 20: command1;break;

21 : command2;break;

22 100: command3;break;

}

B switch (x) {

1: command1;break;

20: command2;break;

37: command3;break;

}

C switch (x) {

1: command1;break;

2: command2;break;

3: command3;break;

}

D switch (x) {

1 2: command1;break;

4 : command2;break;

5 6: command3;break;

}

SinhVienZone.Com

Trang 4

Given the semantics of the for statement:

for i = <first> to <last> by <step> do <stmt>

as follows,

i = <first>

loop:

if i ><last> goto out

<stmt>

i = i + <step>

goto loop

out:

How many times does the following for statement iterate?

n := 10;

j = 1;

for i:= 1 to n by j do j++;

A 4

B infinite

C 10

D 15

Given the following control flow,

SinhVienZone.Com

Trang 5

Select the code that implements the above control flow?

A do {

action 1

if (condition) break

action 2

} while (true);

B while (true){

action 1

if (! condition) break;

action 2

}

C for (action 1;condition;action 1) action 2

D action 1

while (condition) {

action 2

action 1

}

E while (condition) {

action 1

action 2

}

Given the following C code,

while (i > n) { // line 1

while (j > m) { //line 2

while (k > p) { // line 3

s += k;

if (s > 1000) break; // line 5

k ;

}

j ; //line8

}

i ; //line 10

}

//line 12

Where does the control come when the break at line 5 is executed?

A line 8

B line 10

C line 2

SinhVienZone.Com

Trang 6

D line 3

E line 12

SinhVienZone.Com

Ngày đăng: 30/01/2020, 22:17

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

🧩 Sản phẩm bạn có thể quan tâm