wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

แบบทดสอบเรื่อง if การเขียนโปรแกรม C++

Total questions: 20

Worksheet time: 1hrs 26mins

Name
Class
Date
1.

นามสกุล ของไฟล์ source code คือ

a)

.c / .cpp

b)

.obj

c)

.exe

d)

.h

2.
ชื่อใดไม่ผิดกฏการตั้งชื่อ
a)
int
b)
tea_001
c)
#tea001
d)
tea  001
3.
ในภาษาซี หากตั้งชื่อตัวแปรดังนี้
1. ant
2. Ant
3. aNt
4. anT
ข้อใดถูกต้อง
a)
ทั้ง 4 ตัว เป็นตัวแปรตัวเดียวกัน
b)
ทั้ง 4 ตัว เป็นตัวแปรคนละตัว
c)
ข้อ 1, 2 เป็นตัวแปรตัวเดียวกัน
d)
ไม่มีข้อถูก
4.

main() เป็น อะไร

a)

process

b)

library

c)

function

d)

data

5.

ตัวเชื่อมเงื่อนไข "หรือ" คือข้อใด

a)

||

b)

&&

c)

""

d)

#

6.

a+=2 มีค่าเท่ากับข้อใด

a)

a=a+2

b)

a=a+a

c)

a=a*a

d)

a=2

7.

100 % 2 = ?

a)

50

b)

2

c)

1

d)

0

8.

ข้อใดเป็นจริง ถ้า A = 5, B = 0

a)

A == B || A <= B

b)

A != B && A < B

c)

A != B || A <= B

d)

A < B && A == B

9.

ฟังก์ชันที่ใช้ในการรับค่าจากผู้ใช้ในภาษา C++ คืออะไร?

a)

scanf

b)

cin

c)

cout

d)

get

10.
จากรูปแบบที่กำหนดให้ คำสั่ง statement จะถูกเรียกทำงานเมื่อใด if (condition) statement;
a)
ก็ต่อเมื่อนิพจน์ทางตรรกศาสตร์ที่กำหนดเป็น condition มีค่าเป็นจริง
b)
ก็ต่อเมื่อนิพจน์ทางตรรกศาสตร์ที่กำหนดเป็น condition มีค่าเป็นเท็จ
c)
ก็ต่อเมื่อนิพจน์ทางตรรกศาสตร์ที่กำหนดเป็น condition มีค่าเป็นเท็จหรือจริง
d)
ก็ต่อเมื่อนิพจน์ทางตรรกศาสตร์ที่กำหนดเป็น condition มีค่าเป็นเท็จและจริง
11.
จากรูปแบบคำสั่งที่กำหนดให้ คำสั่ง statement2 จะถูกเรียกทำงานเมื่อใด if (condition) statement1; else statement2;
a)
เมื่อนิพจน์ในตำแหน่ง condition statement1 มีค่าเป็นเท็จ
b)
เมื่อนิพจน์ในตำแหน่ง condition statement1 มีค่าเป็นอนันต์
c)
เมื่อนิพจน์ในตำแหน่ง condition statement1 มีค่าเป็นศูนย์
d)
เมื่อนิพจน์ในตำแหน่ง condition statement1 มีค่าเป็นจริง
12.
if (total < 500) discount = total * 0; else if (total < 1001) discount = total * 0.03; else if (total < 2001) discount = total * 0.05; else if (total < 3001) discount = total * 0.07; else discount = total * 0.10; จากโปรแกรมที่กำหนด ถ้า total = 50 จะได้ discount เท่าไร
a)
0
b)
3
c)
5
d)
7
13.
if (total < 500) discount = total * 0; else if (total < 1001) discount = total * 0.03; else if (total < 2001) discount = total * 0.05; else if (total < 3001) discount = total * 0.07; else discount = total * 0.10; จากโปรแกรมที่กำหนด total ต้องเป็นเท่าไรจึงจะได้ discount 7%
a)
2500
b)
500
c)
1500
d)
2000
14.
if (total < 500) discount = total * 0; else if (total < 1001) discount = total * 0.03; else if (total < 2001) discount = total * 0.05; else if (total < 3001) discount = total * 0.07; else discount = total * 0.10; จากโปรแกรมที่กำหนด หาก total มีค่าเท่ากับ 3580 จะคำนวณ discount กี่ %
a)
10 %
b)
7 %
c)
5 %
d)
3 %
15.
if (total < 500) discount = total * 0; else if (total < 1001) discount = total * 0.03; else if (total < 2001) discount = total * 0.05; else if (total < 3001) discount = total * 0.07; else discount = total * 0.10; จากโปรแกรมที่กำหนด หากต้องการส่วนลด 3 % จะต้องมีค่า total เท่าไร
a)
500 - 1000
b)
501 - 1001
c)
1000 - 2001
d)
1001 - 2001
16.
รูปแบบคำสั่ง if มีกี่รูปแบบ
a)
3 รูปแบบ
b)
2 รูปแบบ
c)
4 รูปแบบ
d)
5 รูปแบบ
17.
คำสั่ง if แบบใด ใช้ในกรณีหลายทางเลือก
a)
if...else if...else
b)
if
c)
if...else
d)
if...else if
18.
กรณี 2 ทางเลือกใช้คำสั่ง if ข้อใด
a)
if...else if...else
b)
if
c)
if...else
d)
if...else if
19.

กรณี 1 ทางเลือกใช้คำสั่ง if ข้อใด

a)
if...else if...else
b)
if
c)
if...else
d)
if...else if
20.

ข้อใด ประกาศตัวแปรแบบชุด จำนวน 2 ตัวแปร ชนิดตัวอักขระ ได้ถูกต้อง

a)

int name[30]:nickname[10];

b)

char name[30]:nickname[10];

c)

char name[30],nickname[10];

d)

int name[30],nickname[10];