13-1 13-2 / 13-3 14-1 Visual Basic 14-2 14-3 15-1 15-2 15-3 287 290 307
13-1 13-1.1 272 Introduction to Computer Science
13-1.1 1. 2. 3. 4. 273
274 Introduction to Computer Science
275 13-1.2 13-1.1 /
13-1.2 10 Sum = 0 Number = 0 X Sum = Sum+ X Number = Number + 1 Number = 10 Average = Sum / 10 Average 276 Introduction to Computer Science
277
Introduction to Computer Science 278 13-1.3
13-2 / 13-2.1 279
Introduction to Computer Science 280 A(1) A(2) A(2) A(3) A(1) A(3) A(4) A(5) A(4) A(5) A(5) A(4) A(5) A(3) A(3) A(4) A(4) A(5) A(1) A(2) A(1) A(2) A(1) A(2) A(3) A(1) A(2) A(3) A(4) A(5) A(4) A(5) A(1) A(2) A(3) A(5) A(2) A(4) A(1) A(2) A(1) A(5) A(3) A(3) A(4) A(1) A(2) A(3) A(4) A(5) A(2) A(3) A(1) A(1) A(1) A(3) A(5) A(4) A(5) A(2) A(2) A(3) A(4) A(4) A(5) A(1) A(2) A(3) A(4) A(5) N(N-1 )/2
281 A(3) A(4) A(5) A(3) A(4) A(1) A(2) A(2) A(1) A(5) A(1) A(4) A(5) A(2) A(3) A(1) A(2) A(5) A(4) A(3) A(1) A(2) A(4) A(3) A(5) A(1) A(2) A(3) A(4) A(5) A(1) A(4) A(3) A(2) A(5) A(1) A(2) A(3) A(4) A(5) A(1) A(2) A(3) A(4) A(5)
A(1) A(1) A(1) A(2) A(3) A(4) A(2) A(3) A(4) A(2) A(3) A(4) A(5) A(5) A(5) A(1) A(2) A(3) A(4) A(1) A(2) A(3) A(4) A(5) A(5) 282 Introduction to Computer Science N(N-1 )/2
13-2.2 N 1 283
2 5 9 13 15 22 26 30 2 5 9 2 284 Introduction to Computer Science
13-3 13-3.1 285
Introduction to Computer Science 286 13-3.1
13-3.2 A 287 FOR TR AN C OBOL AL GOL
B 288 Introduction to Computer Science PL /1 BASIC VBPASC AL D elp hic C ++Ja va VBAAction ScriptHTMLXML
COUNT customer WHERE city EQUALS Taipei AND years EQUALS 2004 ' 2004 Tell Me the telephone number of KZ. I don't know what you mean about KZ. Kevin Zheng. 2987-6543. Ja va Scrip tvb Scrip tpe rl4glsqllispprolog 289
A 290 Introduction to Computer Science
291 B 291
14-1Visual Basic 14-1.1VB 292 Introduction to Computer Science Visua l Basic
14-1.1 Visual Basic 6.0 (.frm ).vb p 293
294 Introduction to Computer Science VB
295
1 Com m and Button 2 Command1 14-1.2 296 Introduction to Computer Science Co m m an d Bu tton
14-1.3 twip twip twip 1 twip = 1/567 cm = 1/1440 inch 14-1.4 VB tw ip 297
1 / CTRL + G 2 BASIC Print 8 + 3 ENTER 11 Print Print " "Print Print? 298 Introduction to Computer Science Prin t
299 14-1.2 VB Cls Cls End End ClsEn d
VBHello,world! 1 Caption 2 3 Caption 300 Introduction to Computer Science C ap tion
4 5 PRINT "Hello,world!" 6 7 Cls 8 9 End 301
14-1.5 VB 1 302 Introduction to Computer Science
2 frm. 3. vbp 14-1.6. frm 303
1 /. exe 2. exe 304 Introduction to Computer Science
305
Introduction to Computer Science 306 14-1.3VB OOP
14-1.7 14-1.1 p 307
p p 14-1.8 Caption 14-1.2 VB 308 Introduction to Computer Science
. = Command1.Caption = " " Command1Caption Private Sub _ ( ) End Sub Private Sub Command3_Click( ) End End Sub End VB 309
Introduction to Computer Science 310 14-1.9 Command1 Click 14-1.3 VB
. ( 1, 2, ) Image1.Move 50,50 I m a g e1 50,50 14-1.4 311
Private Sub Com mand1_click( ) Image1.move 150,150 End Sub 14-2VB 312 Introduction to Computer Science
14-2.1VB VB VB 1. A Z 2. a z 3. 0 9 4. = + - * / %!... VB 5. Let D = A + B Print D 313
Let D = A + B : Print D REM REM ' R EM ' 314 Introduction to Computer Science R EM
Const Co nst [ As ] = 1. 2. C on st const.frm X = 1 Print X X = X + 2 Print X VB 1. AZ a z 2. AZa z 09 _ 3. 255 1 3 4. VB 315 C o ns t
MyNameData_001 1999Price Data.01. CLS VB X = 1 Print X X = X + 2 Print X Mo n e y m o n e y m OnEY MonEy X 1 X 1 X + 2 = 1 + 2 = 3 X X 3 316 Introduction to Computer Science
317 14-2.2VB 14-2.1 VB D im
Dim Dim [ As ] Dim [ ], As Varia nt Dim.frm 318 Introduction to Computer Science Dim
319 14-2.3 14-2.2
VB 31.23 \ 1.7 31 \ 2 15...1 31.23 \ 1.7 = 15 31.23 Mod 1.7 31 Mod 2 15...1 31.23 Mod 1.7 = 1 14-2.3 320 Introduction to Computer Science
1 < 5 e > E m > M Ken e > Karen a 3 < t > 14-2.1.frm 14-2.2 321
14-2.4 14-2.5 X Y NOT X X X' X AND Y XY X OR Y XY X XOR Y XY X EQV Y X Y NOT AND AND AND XOR 14-2.3 322 Introduction to Computer Science
Print 6 * 6 < 5^2+10 XOR "Ken" > "Karen" 323
14-3 14-3.1 14-3.2 14-3.1 MsgBox MsgBox MsgBox m es sage [,butto ns ] [,title ] ReturnValue = MsgBox ( m essage [,buttons ] [,title ] ) 324 Introduction to Computer Science Msg Bo x
m e ssag e bu tton s + vb Ques tio n + vbyesn o title Re tu rn Va lu e.frm 325
title vbquestion message vbyesno 1 vb Qu estio n + vbye sn o36 4 324 + 3 2 = 36 0 2 326 Introduction to Computer Science
14-3.2 InputBox 14-3.3 InputBox Retu rnvalue = Inpu tbox ( m essage [,title] [,d efault] [,xpos ] [,ypo s] ) m e ssag e title d efau lt xp os X yp os Y Re turn Valu e.frm 327 Inp utbo x
1 2 3.frm 328 Introduction to Computer Science
15-1VB 329
15-1.1 If...Then...Else If...Then...Else If Th en 1 2... Else a b... End If If Then 1 2... Else a b... If The n Els e...... IF >= 6 0 Then Print " " Else Print " " 330 Introduction to Computer Science If...The n...else
IF...Then...Else Project1 MsgboxInputBox.vbp Project1Project2 14-3 331
a = 3 : b = 5 : c = 4 If a > b Then Else If b > c Then Print a ; Print b; End If Print c If ( 5 > 4 And 3 > 4 ) Then Print "A" Else Print "B" End If 15-1.2 If...Then...Else 332 Introduction to Computer Science If...The n...es le
If...Then...Else If 1 Th en 1 2... 1 Else If 2 Th en a b... 1 2 Else x y... 1 2 End If End If If 1 Else Then 1 2... If 2 Then a b... Else x y... 1 1 2... IF 2 a b... 1 2 x y... If...The n... Else 1 2... a b... x y... If...Th en...els e 333
IF...Then...Else 334 Introduction to Computer Science
IF...Then...Else 335
A = 1 B = 2C = 3 IF B > 1 THEN IF A < 1 THEN C = 2 ELSE C = 4 END IF END IF D = 300 If D <= 100 Then Tax = D * 2 Else If D <= 250 Then Tax = 150 + ( D 50 ) * 3 Else Tax = 700 + ( D 100 ) * 5 End If End If Print Tax 15-1.3 Select...Case 336 Introduction to Computer Science Se lect...ca se
Select...Case Sele ct Ca se Ca se 1 1 Ca se 2 2 Case Else n End Select 1. Select Case Cas e Case 2. C as e Ca se Els e 3. C ase C ase Else En d Se lect 4. Select Case Case 1 Case "a" Case 1 to 5 Case "a" to "k" Case is > 5 Ca se is > "a"... Select Case Case 1 Case 2 Case Else 1 2... n 337
Select...Case 338 Introduction to Computer Science
Private Sub Form_Activate( ) X = 5 \ 2 Select Case X Case 1 Print "sm all" Case 2 Print "m edium" Case Else Print "large" End Select End Sub 339
15-1.4 * ID 340 Introduction to Computer Science
1 Form1 Label1 Label2 Text1 Text2 Command1 Caption Caption Caption MaxLength Text MaxLength PasswordChar Text Caption 341
2 3 342 Introduction to Computer Science
ID = Text1.Text ' Text1 ID Password = Text2.Text ' Text1 Password Case "Kevin" If Password = "1234" Then ' ID Kevin ' 1234 MsgBox "Kevin, ", vbinformation, " " End If La bel.cap tio nla bel.ma xle ngthla bel.pa sw ord Cha rte xtbox.text 343
Click = MsgBox(" vbexclamation + vbyesno, " ") ' ", _ If Click = vbyes Then Text1.Text = "" Text2.Text = "" Form1.Show Else End End If ' ' Text1 ' Text2 ' ' ' 344 Introduction to Computer Science Fo rm.sh ow
15-2VB 15-2.1 For...Next For...N ext 345
For...Next For = To [ Step ] 1 2 Ne xt [ ] 1. 2. 1 Ste p 3. 4. = ( ) \ + 1 0 For = To Step 1 2... 346 Introduction to Computer Science For...N ext
1100 For...Next For i = 1 To 100 Total = Total + 1 Total = Total + 2... Total = Total + 100 347
1100 For...Next 2 Total = Total + 1 Total = Total + 3... Total = Total + 99 348 Introduction to Computer Science
For...Next 3 2 0.5 For...Next 349
For i = 80 To 10 Step 10 For I = 19 To 1 Step 3 Print " # " ; Next I N = 0 For I = 1 To 50 If I M od 15 = 0 Then N = N + 1 End If Next I Print " N = " ; N 350 Introduction to Computer Science Fo rm.fon t.size
15-2.2 For...Next For...Next 351 For...N ext
For I = 6 To 1 Step 2 For K = 1 To I Print " * " ; Next K Next I K= 0 For I = 1 to 5 For J = I + 2 to 4 K = K + 1 Next J K = K 1 Next I Print K C = 0 For K = 1 to 5 For J = K to 5 C = C + 1 Next J Next K PRINT C 15-2.3 Do...Loop 352 Introduction to Computer Science
Do...Loop Do While Loop 1 2... Do Until Loop 1 2... QBASIC While...Wend VB Do While...Loop While Until Do While...Lo op Do Until...Lo op Do While Do Until False True True False 1 2... 1 2... Loop Loop 353 Do While...Loo pdo Until...Loo p
1100 Do While...Loop 15-2.1 1 1 0 0 D o Until...Loop 1 100 DoWhileLoop.frm 354 Introduction to Computer Science
Do...Loop Do 1 2... Loo p While Do 1 2... Loop U ntil Do Do 1 2... 1 2... False True True False Loop While Loop Until 355 Do...L oop WhileDo...L oop Until
1100 Do...Loop While 1100 Do...Loop Until 356 Introduction to Computer Science
a = 15: b = 27 x = a : y = b Do Until a = b If a > b Then a = a b If a < b Then b = b a Loop Print ( x / a ) ; " / " ; ( y / a ) SUM = 0 A = 1 WHILE A < 10 SUM = SUM + A A = SUM WEND C = 5D =1 Do D = D * C C = C + 1 Loop Until C >= 10 Print " D = " ; D 357
15-2.4 358 Introduction to Computer Science Ra ndo m izein t( N * Rnd )
GameOver = False Do Until True GameOver =True False 1 10 Run Run <=5 True 1 500 twips False 2 500 twips False False True True 1 2 GameOver = True GameOver = True Loop 359
Introduction to Computer Science 360 1 ForeColor Caption Form1 Caption Label1 Font Label2 Caption Font ForeColor Label3 Caption Font BorderStyle Command1 Caption BorderColor Line2 Line1 BorderWidth 8080 BorderColor
2 3 Form1 Load Click 361
15-3 15-3.1 S(9) 15-3.1 Dim ( ) As 1. 2. 0 + 1 362 Introduction to Computer Science
3. A(1 1 )A(2 0 ) Dim A(1 1 To 20) As Integer A(1 1)A(12 )A(2 0)10 VB Dim A%(11 To 20).frm Option Base Option Base 0 Option Ba se 1 0 1 1. Op tio n Bas e 1 1 Dim A(1 0) As Strin g A (1 )A(2 )A(10 )1 0 2. Op tion Bas e Op tion Bas e 0 Op tion Ba se 363
.vbp 364 Introduction to Computer Science
DIM A( 5 ) A( 1 ) = 1 FOR N = 2 TO 5 A( N ) = A( N 1 ) + N NEXT N PRINT A( 5 ) DIM B(10) FOR M = 1 TO 10 B(M ) = 3 * M + 2 NEXT M FOR N = 1 TO 10 SUM = SUM + B(N) NEXT N PRINT SUM 15-3.2 365
B(2,3) 15-3.2 B(2,3) Dim ( 1, 2) As 1. 2. 0 1 + 1 2 + 1 3. Op tion Ba se.frm 366 Introduction to Computer Science
Dim A(3, 3) As Integer For I = 0 To 3 For J = 0 To 3 A( I, J ) = 2 * I * ( I + J ) Next J Next I OPTION BASE 1 DIM K( 3, 4 ) FOR I = 1 TO 3 FOR J = 1 TO 4 IF ( I > 1 AND J > 1 ) THEN K( I, J ) = K( I 1, J 1 ) + 1 ELSE K( I, J ) = 1 END IF NEXT J NEXT I 367
/ 368
2 Bytes 4 Bytes 4 Bytes 8 Bytes 2 Bytes 8 Bytes % &! # $ 369
370
371
A >C? A >B? B <C? A B C A = 10, B = 0 B = B + A A = A 1 A < 6 B 372
373
374
375
376
377 2 2 b a c + =
378
379
380 Introduction to Computer Science
381
B attribute 307 C++ 288 0 4GL 288 A ABC 5 ActionScript 288 ADSL 215 blog 239 AI 7 algorithm 273 ALU / 49 application software 14 array 362 assembler 286 assembly language 286 B bandwidth 215 barebone 59 BBS 239 binary search 283 BIOS / 13 bps / 101 bridge 194 brightness 95 browser 221 bubble sort 281 bus 50 C cable modem 216 cache 68 CAD 24 CAI 22 CAM 24 case 56 CCD 90 CD 81 chipset 60 classip 205 class 307 client 179 client/server network 179 clock 66 cluster 151 CMOS 59, 60, 90 382 Introduction to Computer Science
collision 190 compiler 290 computer 4 contrast 95 cookiecookie 32 CPU 49 CRT 91 CU 49 cylinder 78 D embedded computer 10 end users 15 ENIAC 6 EPOC 129 Ethernet 192 event 308 event-driven 308 Extranet 204 F H hacker 30 hard disk drive 76 hardware 11 HTML 221 HTTP 221 hub 195 I IC 6 Delphi 288 desktop 133 DHCP 217 FLOPS 4 digital camera 89 digital signature 37 distance learning 22 DNS server 213 firewall 37 floppy disk drive 75 flowchart 275 format 78 FSB 50 FTP 200 icon 133 IMAP 200 Internet 177, 202 interpreter( ) 290 Intranet 204 IP addressip 205 IP 198 ISP 214 DNS 200 domain name 211 G IU 49 DOS 126 DVI 95 E gamepad 86 gateway 197 GFLOPS 4 GIGO 12 J Java 288 joystick 86 EC 243 E-Mail 227 GPS 18 K GUI 124 kernel 124 383
keyboard 85 ms 79 MU 49 179 peripheral 13 L LAN 177 LCD 91 Linux 128 LISP 289 low-level language 285 M Mac OS X 127 machine cycle 65 machine language 286 mainframe 9 MAN 177 memory card 89 method 308 microcomputer 10 microphone 88 microprocessor 7,49 MIPS 4 modem 196 motherboard 57 mouse 85 MP3 20 MPEG-4 21 N NATIP 217 network 176 NOS 179 O object 307 on-line game 241 OOP 307 organic photo-conductor drum 99 OS 122 OSI model register 67 183 OU 49 P packet 180 Palm OS 129 PASCAL 288 PC 10 PCB 57 PDA 18 peer-to-peer network phishing 31 POP3 200 port 54,198 power supply 56 printed circuit 57 printer 97 program 272 programming language 285 pseudocode 277 R R/W head 77 RAM 71 repeater 194 ROM 69 router 196 S scanner 87 searching 279 sector 78 selection sort 279 sequential search 283 384 Introduction to Computer Science
Serial ATA 79 server 179 UNIX 128 UPS 36 SET 36 user 11 shell 124 SMTP 200 software 11 sorting 279 speaker 88 VLSI 6 SQL 289 VR 23 SSL 36 V virtual memory 72 virus 33 subnet mask 208 supercomputer 8 switching hub 195 system software 14 T TANet 177 taskbar 134 W wafer 62 WAN 177 WinCE 129 window 133 word 67 workgroups 179 WWW 221 TCP 198 TENET 200 terminal 9 topology 189 track 78 TRADIC 6 U UDP 199 385