c++_Учебник_МОНУ

589

Upload: srg-rdnk

Post on 23-Oct-2014

460 views

Category:

Documents


4 download

TRANSCRIPT

. . . , .. 32.973(076) 004.43 , 1/11-2645 04.04.2011 . :. . ,...,,.. -; . . ,..., . ; . . , ...,,.. - ; . . , ..., , . . . : . ., . ., .., . ., . ., . ., . . ++. : . / [. . , . ., . . , . . .] ; . . . . 587 . ++ ANSI - - C++ Builder. , ,,. , , , -. - . - . . .. . , ++. ISBN 978-966-7598-59-4 .. , .. , .. , .. , .. , .. , .. , 2011 3 ........................................................................................................... 8 1. ................................... 11 1.1 ........................................................... 11 1.2 .............................................................................. 13 1.3 ........................................................................................... 14 1.4 ........................................................................................ 15 1.4.1 ................................................................... 15 1.4.2 ................................................................................ 16 1.4.3 .................................................. 17 1.4.4 .................... 18 1.4.5 ........................... 23 1.5 ................... 24 1.6, . ......................................................................................... 25 2. C++ Builder.......................... 29 2.1 ...................................... 29 2.1.1 C++ Builder ........................................................... 29 2.1.2 ++ Builder- ............................................................ 46 2.1.3 C++ Builder .... 48 2.1.4 ......................................... 57 2.2 ........................................................................................... 59 2.2.1 ................................. 59 2.2.2 ..... 63 3. ++ ..................................................................... 67 3.1 ++ .................................................................................................... 67 3.2 ++ ........................................................................................ 69 3.3 .................................................................................................... 70 3.4 ...................................................................................................... 75 3.5 ............................................ 76 3.5.1 .................................................................................. 76 3.5.2 ............................................................................ 77 3.5.3 .................................................................... 79 3.5.4 ....................................................................................... 80 3.5.5 ............................................................................. 82 3.6 ++ Builder ............................................................................ 83 3.7 ++ ............................................ 85 4 4. .................................. 87 4.1 ............................................................................. 87 4.2 .......................................................... 87 4.3 ................................................. 96 4.3.1 .......................................................................... 96 4.3.2 goto .................................................. 96 4.3.3 ............................................. 96 4.3.4 .............................................................. 100 4.3.5 ........................................ 100 4.3.6 if ............................................................................ 101 4.3.7 ?: .............................................................. 111 4.3.8 switch ...................................................... 113 4.4 ..................................................... 120 4.4.1 ............................................................................. 120 4.4.2 for ...................................................... 120 4.4.3 .................................................................................... 140 4.4.4 while do-while .. 145 4.4.5 ................................................... 159 5. ++.............................................................................. 163 5.1 ........................................................................................... 163 5.2 ................................................................................... 163 5.2.1 ................................................... 163 5.2.2- ..................................... 166 5.2.3 .................................................. 168 5.2.4 ............................. 176 5.3 ..................................................................................... 185 5.3.1 ....................................................... 185 5.3.2- ....................................... 188 5.3.3 .................................................... 190 5.3.4 ............................... 198 6. . .......................................... 207 6.1 ................................................................................................... 207 6.2 .......................................................... 209 6.3 ............................................................................ 210 6.4 ....................................................... 212 6.5 ..................................................................................... 215 6.6 ................................................................. 217 6.7 () .................................................. 225 5 7. ......................................................................... 231 7.1 .............................................................................. 231 7.2 ............................................................................................................ 235 7.2.1 ................................................................................... 236 7.2.2 AnsiString (String) ......................................................................... 255 7.2.3 string ............................................................................................ 261 7.3 ......................................................................... 269 7.3.1 ++wchar_t .................................................................................. 269 7.3.2 ++ Builder WideString ................................................................ 270 8. ............................................................................................ 272 8.1 ..................................................................... 272 8.2 ......................................... 278 8.3 ........................................... 285 8.4 ................................................ 286 8.5 ..................................................................................... 288 8.6 .......................................................................... 297 9. ............................................ 302 9.1 ............................................................................... 302 9.2 .......................................................................................... 305 9.3 ..................................................................................... 326 9.4 ........................................................................... 326 9.5 ........................................................................ 330 10. ........................................... 340 10.1 - ++ ................................................................................... 340 10.2 - ++ Builder ...................................................................... 342 11. .................................................................... 361 11.1 (typedef) ......................................................... 361 11.2 (struct) ..................................................................................... 362 11.3 (union) ................................................................................... 373 11.4 (enum) ............................................................................. 375 11.5 (Set) .......................................................................................... 376 6 12. ............................................................................................. 381 12.1 .................................................................. 381 12.2 .......................................................................................... 382 12.2.1 ++ Builder .......................................... 382 12.2.2 .......................................... 383 12.2.3 ++ ................ 400 12.2.4 ............... 402 12.2.5 ................... 404 12.2.6 ....... 406 12.3 ............................................................................................ 413 12.3.1 ............................................ 413 12.3.2 ++ .................. 422 12.3.3 ........ 425 12.4 ++ Builder ......................................... 431 13. ................................................. 440 13.1 ......................................................................................... 440 13.2 ............................................................................................................ 444 13.3 .......................................................................................................... 447 13.4 ............................................ 450 13.5 ..................................................................................... 462 13.6 ........................................................................................... 474 13.7 ................................................................................................... 484 13.7.1 ............................................................................... 484 13.7.2 ........................................................................... 487 13.7.3 ......................................................................... 489 13.7.4 ........................................................................ 493 14. - ............................ 496 14.1 - ............................... 496 14.2 ..................................................................................... 498 14.3 ........................................................................ 500 14.4 ...... 501 14.5 ............................................................................................ 504 14.5.1 ................................................................ 504 14.5.2 .............................................................. 505 14.5.3 ............................................... 506 14.5.4 ........................................................ 507 14.5.5 ................................................................... 507 14.6 .............................................................................................. 512 7 14.7 .......................................................................................... 515 14.8........................................................................................... 519 14.9 ........................................... 526 14.9.1 ...................... 526 14.9.2 -....................................................... 529 14.9.3 ....................................................................... 538 15. ......................................................... 542 15.1 ................................................................................ 542 15.2 ......................................................................... 556 15.3 ........................................................................................... 557 15.4 ....................................................................... 558 ................................................................................ 546 ASCII.................................................................. 565 ++ ....................................................................... 569 ++. ........................................................... 571 .................................................................................... 577 , , ++, - . ,,,,, . ++ Windows, Unix, : -,,,Borland++Builder,MicrosoftVisualC++ Visual Studio.NET. , - ++, , - . -,++,, - , . - , -, , . - , , -,,. - ., .-++- , Borland++Builder, ++. , -, . . ,.1, , - , -.,- . . 2 ++ Builder , Windows, -, . ++Builder++- . -9 ++ Builder-.-++Builder, , -, . , -, - ++. ++, ,,- , . 3. , , . . 4 -(,) . - . -, , , , ., -, . 5. .6 ,,-. C++ .,, , . , . 7 ,, -: - , - , . -. ++ ( -)., ,. . 8. , . 9. . 10 ++ ++ Builder --.- ..11, ,,. ,. 10 ,-, , . ++,, .,.12 - ++ -.,++ .- ++. , -++Builder . .13-. , , -,., . ++ - (), -.14.-. - . . 15 , - , , - . .ASCII-,++ ++. , -, , . , . .. - . , ++, . E-mail: [email protected] 1 1.1 , (- ) -. -(hardware)-. , (hardware) . ,1945 .,-, . : ; ; ; .IBM , -. , . .-, (), (. 1.1): (CPUcentralprocessorunit) ,,, , .:1)- ();2)- ; 3) --;4) -, . CPU (FPU floating point unit), -, (chip); 112 (RAM read access memory) - (cache), . , - ; -. , , -.(,HDD harddiskdriver),D,DVD,USB-(flashUSBdrive), (memory cards) ; . - . , - , , - , , , Internet; , . ,- . - , Internet. . , - , (),,.- () - . ( ) - - . 1.1. 13 (controller) . 1.2 ()(software)-,. : ; ; .()(operatingsystem) ,-. Windows,Linux,Unix.:-,-,,-;;;- ; , - . , - : ; ; , ; ; . , - . : () , . ,- ; ,, , - . - . : 1) -(),Pascal,;2)Lisp;3) Prolog; 4) - C++, C#, Java, Object Pascal . , , - , . -()-.() . .- 114 . , ++ Builder, Visual C++, Delphi, Visual Basic . . - MathCAD, Mathematika, Matlab; - Microsoft Word, (Notepad) ; MicrosoftExcel,Adobe Photoshop,Paint. , ,,-, . , . - - . , , , . ,(hardware)-(software).- . . 1.3 , . . . :,, ,. , :., , , ,, . , -txt,MicrosoftWorddocrtf, Microsoft Excel xls, Microsoft Access mdb, bmp, psd, jg, gif . . (,), (). -.- . 15 , , , : C:\Program Files\Microsoft Office\Clipart\A16.gif. ,,1- . , -1-,2- . . (. 1.2). -, :,,-, , . -. (,,). , . 1.4 1.4.1 ().-, . (). , : I 1, V 5, X 10, L 50, C 100, D 500, M 1000. , 30 : XXX. X - . : IV 4, VI 6, IX 9, XI 11, XL 40, LX 60, XC 90, CX 110, CM 900, MC 1100, MCMLXXXIX 1989., . - . . -(). . - , , - . d h m s d 24 60 60 +h 60 60 + m 60 + s . - () , . , , - Microsoft Office Clipart command.com autoexec.bat Program Files VB VB6.exe

C: . 1.2. 116 .,4444, , ,- . . 1.4.2 -(,,,,) . -, : 0 1. - , - : . : 1 0. . , (), , - . - , , . ,, (), . - ( . binary digit ). ,-'0' '1'. n 2n - . , , . . -.-28 = 256,, 0255.,1101 0011 ., .,, ,.(.nibble, nybble), - , , , 24 ., . , , -(),25 = 32.,, ,, .- 0 1, (. .7). :'9'0011 1001, 'W' 0101 0111. 17 : (1 (kB) = 210 = 1024 ); (1 (MB) = 220 = 1024 = 1 048 576 ); (1 (GB) = 230 = 1024 = 1 073 741 824 ); (1 (TB) = 240 = 1024 = 1 099 511 627 776 ); (1 (PB) = 250 = 1024 ); (1 E (EB) = 260 = 1024 ); (1 (ZB) = 270 = 1024 E); (1 (YB) = 280 = 1024 ). , 2500 -, 1 400 , 1 400 . , 2. (, . .) , - 210 = 1024 , 1000. , -., ,,- (210), (220), (230), (240), (250), (260), (270), (280). , , -()-10. 109 .,,,250- (HDD) 232 .1.4.3 N q - : Nq = an-1 qn-1+an-2 qn-2 + ... +a1 q1 + a0 q0 + a1 q1 + + ak qk = =1 nk iiiq a , q , ; ai i- ; n ; k . q = 10. , .. ,,- . . , , : 724810 = 7 103 + 2 102 + 4 101+ 8 100 = 7000 + 200 + 40 + 8 = 7248. 118 q = 2 N2 = an-1 2n-1 + an-2 2n-2 + ...+ a1 21 + a0 20 + :10101.1012 = 124 + 023 + 122 + 021 + 120 + 121 + 022 + 123 = 21.62510. q =8-, q = 16 ., ,, , (. . 1.1)., , . 1.1 q 2 8 10 16 0, 10, 1, 2, 3, 4, 5, 6, 7 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 0, 1, , 9, (10), B(11), (12), D(13), E(14), F(15) - : 194.3810 = 1102 + 9101 + 4100 + 3101 + 8102 = 194.3810; 10011.12 = 124 + 023 + 022 + 121 + 120 + 121 =19.510; 237.28 = 282 + 381 + 780 + 281 = 159.2510; A1F16 = 10162 + 1161 + 15160 = 259110. .- .1.4.4 - ., ,- . q- , . 1.4.3. q-- : , , - , . - 19 q., q.,, (). q- .,133 : 133 : 8 = 16 (5) 16 : 8 = 2 (0) : 13310 = 2058. . , , . 133 :133 : 2 = 66 (1) 66 : 2 = 33 (0) 33 : 2 = 16 (1) 16 : 2 = 8 (0) 8 : 2 = 4 (0) 4 : 2 = 2 (0) 2 : 2 = 1 (0) : 13310 = 100001012. 133 :133 : 16 = 8 (5) : 13310 = 8516. q.- . q- . 0.125, : 1) : 0.125 2 = 0.25; 0.25 2 = 0.5; 0.5 2 = 1 : 0.12510 = 0.0012; 2) : 0.125 8 = 1 : 0.12510 = 0.18; 3) : 0.125 16 = 2 : 0.12510 = 0.216. 120 - 122.6 - . 122 : 2 = 61 (0) 61 : 2 = 30 (1) 30 : 2 = 15 (0) 15 : 2 = 7 (1) 7 : 2 = 3 (1) 3 : 2 = 1 (1) 0.6 2 = 1.2 0.2 2 = 0.4 0.4 2 = 0.8 0.8 2 = 1.6 0.6 2 = 1.2 0.2 2 = 0.4 : 122.610 = 1111010.1001102. , , - , -.,,() . -,,-.. . ,- , . 1111010.100110 (. . 1.4.1). . 1111010.1001102 = = 126 +125 +124 +123 +022 +121 +020 +121 +022 +023 +124 +125 +026 = = 64+32+16+8+2+0.5+0.0625+0.03125 = 122.59375 ~ 122.6 -.122.6- : 122 : 8 = 15 (2) 15 : 8 = 1 (7) 0.6 8 = 4.8 0.8 8 = 6.4 0.4 8 = 3.2 0.2 8 = 1.6 0.6 8 = 4.8 : 122.610 = 172.4631468. - 172.4631468 :172.4631468 = 182+781+280+481+682+383+184+485 == 64+56+2+0.5+0.09375+0.0058598+0.00024414+0.00003052~ ~ 122.599884 ~ 122.6 21 122- : 122 : 16 = 7 (10=) 0.6 16 = 9.6 0.6 16 = 9.6 0.6 16 = 9.6 0.6 16 = 9.6 : 122.610 = 7 .999916. 7.999916 :7.99916 = 7161+10160+9161+9162+9163 +9164 == 112+10+0.5625+0.03515325+0.0021972656+0.000137329= =122.599987845 ~ 122.6 .1.2. , , : 2378 = 10 011 1112 5048 = 101 000 1002 145.268 = 001100101.010110 = 1100101.010112

. , -,,,. , : 110001002 = 11 000 100 = 3048 1011.111012 = 001 011.111 010 = 13.728 - : 3048 = 11 000 1002 401.048 = 100 000 001.000 12 - ( tcto, ), .- , : 1AF816 = 1 1010 1111 10002 14.2816 = 1 1010.0010 10112

11001000010112 = 1 1001 0000 1011 = 19016 1011010.010112 = 101 1010.0101 1000 = 5.5816 , , , - . - 122 2: 23 = 8, 24 = 16. -, , , - . 1.2 0.06250.00010.040.1 0.1250.001 0.10.2 0.250.010.20.4 0.50.10.40.8 1111 21022 31133 410044 510155 611066 711177 81000108 91001119 10101012 11101113B 12110014 13110115D 14111016E 15111117F 161 00002010 263: 1) : 263 : 2 = 131 (1) 131 : 2 = 65 (1) 65 : 2 = 32 (1) 32 : 2 = 16 (0) 16 : 2 = 8 (0) 8 : 2 = 4 (0) 4 : 2 = 2 (0) 2 : 2 = 1 (0): 26310 = 1000001112; 2) : 1000001112 = 128 +122 +121 +120 = 256 + 4 + 2 + 1 = 26310 : 1000001112 = 26310; 23 3) : 263 : 8 = 32 (7) 32 : 8 = 4 (0) : 26310 = 4078; 4) : 4078 = 482 +780 = 256 + 7 = 26310 : 4078 = 26310; 5) : 263 : 16 = 16 (7) 16 : 16 = 1 (0) : 26310 = 10716; 6) : 10716 = 1162 +7160 = 256 + 7 = 26310 : 10716 = 26310; 7) :: 10716 = 1 0000 01112; 8) : : 1000001112 = 0001 0000 0111 = 10716; 9) :: 4078 = 100 000 111 = 1000001112; 10) : : 1000001112 = 100 000 111 = 4078. 1.4.5 - , , . - ., - : - 2, 8, 16. ( ): . . . . + 11001012 11011102 _110100112 . . . + 2503618 25417148 30122758 . .+ F216 3BC16 12 E616 . . + 306716 2F82416 2E028B16 124 : . . _1002 12 112 . . _1008 18 778 . . _10016 116 FF16 . _F0516 D116 E3416 . . . . _11001012 1010102 1110112 . .. . _54070248 6400528 45467528 .. . _2F8D416 F06716 1BEE6D16 ... _CF0516 F0616 BFFF16 :

10010112 10012 + 10010112 10010112 10101000112

478 238 + 1658 1148 13458 + 4116 AF16 + 3CF16 28A16 2C6F16 + F216 3C16 + B5816 2D616 38B816 1.5 , . :1) (,-,,).- -; 2) - , -, , ; 3) , . - , , , - . ; 4) , ; 5) ; 6) , - ; 7) . 25 . . 1.6, . (algorithm) , - .-, - , . : -,- -. Algorithmi, - . : () - ; , ; ; ; -. : ; ; (-); . - (-). (-) , - ().,(-) (. 1.3). -., . , - - 126 . . , , -, . .- . 3 ,5 . ,,- ,- . 1.3 - - - - () ( ) , , 5, : = 20 . b = 1.5. - , - , . - . - ,, 0.6 0.5 0.5 b 0.5 b b b b 27 , , - . :(-), (). --. - . -,, . ++. ,-., , . , , , -,-.- , () . ,-. ( , ) - . ,-.,- . 1) . 2) ? 3) . 4) ? 5) . 6) . 7) ? 8) ? 9) ()? 10) ? 11) -? 12) ? 13) ? 14)? . 15) ? ? 16) ? 128 17) . ? 18) Notepad () MS Word? txt MS Word? Paint? 19)?-. 20) ? 21)-? 22)50,127,255,25.5- . 23) 1010, 11111, 1010101 - . 24) 3F, 80, F07 - . 25) : 101101 + 1100, 11001 101. 26) : 06 + FB, C6 E9. 27) . 28) , . 29) . 30) ? . 2 C++ Builder2.1 2.1.1 C++ Builder -.Windows.- , , , . ,Windows,-,.- - . : Object Pascal Borland Delphi, Basic Visual Basic, C++ Borland C++ Builder, Microsoft Visual C. RapidApplicationDevelopment(RAD), . RAD . Builder, (Visual C, Visual Basic, Delphi ), Windows(APIApplication ProgramInterface),- , (GUIGraphicUserInterface)-, .C++ Builder , - . C++ Builder -, , . ++ Builder 100 . - VCL Visual Class Library.++Builder C++ VCL (IDE Integrated Development Environment), Delphi C++. - C++ Builder Delphi, -., Delphi, C++ Builder , , , . ++ Builder drag-and-drop -,-,- 230 , - . . C++ Builder,,-,.(-),,-., ,C++, , , - .(Properties)-,,, .(-) , , - . (Ivents) , ,, . , -,- . Button,- : , ( ) ,,,,, ,(,). , : , - . -,:,, . ++ Builder : ;, . C++ Builder - (. 2.1): ; ; ; ; ; . -(.2.1), (,,,). Form.( Caption) (Name), -,1(Button1,Button2). C++ Builder31 Caption. ObjectInspector, ( - ). . 2.1. C++ Builder -, ., TForm. Unit1.cpp. 2.2. . - . - . . 2.2. 232 , Windows-. - . . 2.1.3. , ++ Builder, - . () , - . (. . 2.1). , .(File,Edit, Search). , : File () -, . : New Application ; New Form* ; Save* (unit); Save As (unit) ; Save Project As ; Save All* ; Close ; Close All . .,*, , . 2.1.Edit(), ,.- : Undo, Redo ( :+ ++); Cut, Copy (+ +); Paste (+), ; Delete ( ); Select All- ; Aline* - ; BringToFront* ; SendToBack* ; C++ Builder33 Scale* . .,*, , - . , C++ Builder - - . Search () (+) -(+), . -., .+ .,- . , . View(), (),, .Project()(+) , . Run () (), . Componet()- , . DataBase()- . Tools () - , -,- Tools.Help() . , - , , Borland . (. . 2.3). . 2.3. 234 -.- . 2.1. , - , Properties , - . 2.1 New (, , ) Open Save Savell Open project Add file to project Remove file from project Help Select unit from list , Select form from list , Toggle form/unit New form Run Pause Trace info Step over , , -, (..2.4)., , . . C++ Builder35 . 2.4. : Standard; Additional -. Component / Configure Palette, Properties . , . Standard Windows -, . 2.2. 2.2 Standard Frame( ) MainMenu( ) . Items, PopupMenu( ) , . PopupMenu, Label( ) , Caption. . AutoSize , . true WordWrap . Alignment 236 . 2.2 Edit() , ; Text. : , , , Font Memo ( ) , ; Lines Button () , ; Caption CheckBox ( ) / , : ( State) RadioButton () , . : ( ), . Checked OnClick ListBox( ) . Items, Itemlndex. , , Add, Delete, Insert Append Items. true Sorted ComboBox () ( Items) - () . Text. : ListBox Edit. true Sorted Panel () . , C++ Builder37 . 2.2 ScrollBar () , . Min . , Position RadioGroup () GroupBox RadioButton. . Items. Itemlndex , . Columns GroupBox ( ) , ActionList ( ) , Additional , - Windows, . 2.3. 2.3 Additional BitBtn ( ) () . Kind : , Cancel, Hello . Glyph bmp SpeedButton ( ) MaskEdit ( ) ( Text) ( EditMask) 238 . 2.3 StringGrid ( ) . Cells . ColCount , RowCount DrawGrid ( ) Image () :, Shape () , ( ). Shape, Brush: Color Style Bevel () . Shape , Style ScrollBox ( ) CheckListBox ( ) ListBox CheckBox Splitter () StaticText ( ) Label, . Caption ControlBar( ) ApplicationEvents ( ) Chart ( ) C++ Builder . -..2.4 C++ Builder39 , . 2.4 TabControl ( ) , . Tabs. , Win32 PageControl (- ) , . , . Caption Win32 ImageList () BMP ICO. - , Win32 RichEdit ( RTF) RTF, Win32 DateTimePicker ( ) , . Date Time . Kind , Win32 MonthCalendar ( ) . Date Win32 ProgressBar () , . Min . Step ( Position) Win32 240 . 2.4 TrackBar ( ) ( ). Min , Position . Frequency., , ( ) PageUp PageDown, PageSize. TickStyle TickMarksWin32 StatusBar Windows. . SimplePanel . true , , SimpleText. false , Panels. :StatusBar1->Panels->Items[0]->Text=""; 0 Win32 ToolBar . ToolButton New Button ( ) NewSeparator ( ). ImageList Win32 Timer () , . Interval , Timer, 1000 System OleContainer ( OLE) OLE- OLE-, System C++ Builder41 . 2.4 OpenDialog ( ) Windows . FileName , InitialDir Dialogs SaveDialog ( ) . OpenDialog Dialogs OpenPictureDialog ( ) . OpenDialog Dialogs SavePictureDialog ( ) . OpenDialog Dialogs :()-().(-, Button, Label ) , . (, OpenDialog SaveDialog, Timer, :Table,DataSource,Query,ADOConnection-) , .(,- , Windows .). - , .(ObjectInspector) .-, .:Properties()Events ().(,,)-Properties,(, ,)EventsObject Inspector(. 2.5). , , - , . Properties(.2.5,) ., . 242 . 2.5. : Properties; Events ., , Caption, - Form1 , . - Color , , . clRed, - . -, . . . - , .,Font : , , . .,LabelAutoSize(-) true () . , -. Width () Height (-), AutoSize false (). , , .,Button1, Button2, Memo1, Memo2, (published)-. published-, (public), , . , StringGrid -Cells. , ,- . C++ Builder43 Events ,- , (-,,Windows , ). . : OnClick ; OnDblClick ; OnChange ;OnCreate ; OnActivate ; OnMouseDown ; OnMouseUp ; OnMouseMove ; OnKeyPress ; OnKeyDown - ;OnKeyUp - ; OnEnter ; OnExit ; OnStartDrag,- ; OnDragDrop ; OnEndDrag . Events., , , . C++ Builder , , , -, { ... } . , OnClick Button1, Form1, Unit1.cpp : void __fastcall TForm1::Button1Click(TObject *Sender) { } a Unit1.h: void __fastcall Button1Click(TObject *Sender); 244 ,-: , , , . . 2.5 - , . 2.6 . , , , . ->,: Edit1->Show(); 2.5 AutoSize : 1 (true), Label, Edit, Panel, Image Caption Button, Label Color Count Memo, ListBox Enabled . , , , . false , Font Button, Label, Edit, Memo Glyph bmp, BitBtn, SpeedButton Height ItemIndex . 0 ListBox Items ListBox, ComboBox, MainMenu Left . (0, 0) Lines . 0 Memo, RichEdit Name ScrollBars Memo. : None, Vertical, Gorizontal, Both (, , , ) Memo, StringGrid C++ Builder45 . 2.5 Sorted 1 (true), ListBox, ComboBox Text Edit, ComboBox Top . (0, 0) Visible : 0 (false), Width 2.6 int Add (AnsiString S) S . , :int n=Memo1->Lines->Add(S); Memo, ListBox, RadioGroup, RichEdit Clear() Edit, Memo Delete(int n) n,: Memo1->Lines->Delete(n); Memo, ListBox, RadioGroup, RichEdit Hide() Insert(int n,AnsiString S) S n,:Memo1->Lines->Insert(n, S); Memo, ListBox, RadioGroup, RichEdit LoadFromFile (AnsiString fname) Memo, RichEdit SaveToFile (AnsiString fname) fname Memo, RichEdit SelectAll() Memo, RichEdit SetFocus() () SetText(char *S) S , : Memo1->Lines->SetText(S); Memo Show() 246 2.1.2 ++ Builder- ++(,,, , ) . - main (WIN32)WinMain Windows.. , Project/View Source. ++ Builder . - , : ,.- , , Project1.bpr; . , , Unit1.dfm, Unit2.dfm, ; ,. , - . , , Unit1.cpp, Unit2.cpp, ; .h, . , - ,, . , - Open Sourse/Header File + . (). , ( dfm). . - C++ Builder Unit1. :#ifndef Unit1H #define Unit1H //-------------------------------------------------------- #include #include #include #include // // ( include), //-------------------------------------------------------- class TForm1 : public TForm// TForm1 {__published:// IDE-managed Components // TLabel *Label1; TButton *Button1; void __fastcall Button1Click(TObject *Sender); private:// User declarations // . , , // , , C++ Builder47 public:// User declarations // . , , // , , __fastcall TForm1(TComponent* Owner); }; //-------------------------------------------------------- extern PACKAGE TForm1 *Form1; // , , , // ; // #endif ,#. .-- include, . .9.,-, , :#include // math.h #include // Math.hpp TForm1, __published - . -: Label1 TLabel Button1 TButton. -Button1ClickButton1. privatepublic. ,public, . , private, - . PACKAGE , -, , , - .(cpp-)++. ,. , cpp- , h-, cpp-. cpp-#include , h- . #pragma hdrstop,- , . : #include #pragma hdrstop #include "Unit1.h" //-------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" 248 // // ( include), . // ------------------------------------------------------- TForm1 *Form1; // TForm1 //-------------------------------------------------------- // Form1 __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { // ,// . } // , , // - . // , ,// , // , . //-------------------------------------------------------- // , , // Button1. void __fastcall TForm1::Button1Click(TObject *Sender) { Close(); } , ++ -.-,,, -, -.;C++-begin/end.({)- , , (}) . , - - , . .C++Builder- . - + ., - . 2.1.3 C++ Builder C++Builder ,,- . :C++Builder. . C++ Builder - File/New Application; C++ Builder49 - ; Properties()- , ; -.Events() ,. ; ,- . - ; File/Save Project All (. 2.6);

. 2.6. : ,Run / Run,- ; , . , , -,,, . .15. , ; , (-, ). ,,. ,,,- Run / Program Reset; ,-. 250 (. . 2.1), -Run () ( ,,). Run / Add Watch.,- , - (Breakpoint) Run / Add Breakpoint ; - C++ Builder. . : . 2.1 , .- : , , , .. : (Label)(Button)., . Standard (. . 2.2). : 1)( );2) , ; 3) ., Top,Left,Width Height . -, ., , , - C++ Builder51 . . , . ,, (Properties), (Object Inspector). , -, , -, , Properties - . , , . Button1Caption Button2Caption Button3Caption Button4Caption Button5 Caption Height50 Width170 Label1 AlignmenttaCenter AutoSizefalse Caption " " ColorclBlack Font->Color clWhite Font->Size14 Height50 LayouttlCenter Width400 Form1Caption 1 . (Click) . OnClick-.C++ Builder- - . , , { }. - OnClick Button1 : void __fastcall TForm1::Button1Click(TObject *Sender) {Form1->Color = clYellow;} 252 Button2, Button3, Button4 . clBlue, clGreen, clRed. Button5 () Close():void __fastcall TForm1::Button5Click(TObject *Sender) {Close(); } File / SaveAll(,+ +). , Unit1 Project1. Run / Run - . - ( , ). 2.2,-, ,,, ..(Label), (Panel), (Button) (Timer). - Standard (. . 2.2), -TimerSystem(.. 2.4). C++ Builder53 , . Form1 Caption 2 Height210 Width695 Panel1Caption Button1Caption! Button2Caption Timer1Interval1000 , Label1 AlignmenttaCenter AutoSizefalse Caption ColorclBlue Font->Color clWhite Font->Size14 Height50 LayouttlCenter Width500 (Events) OnMouseMove ( - ) Button1. :1) ;2) Object Inspector;3) Events;4) .C++ Builder - . , void __fastcall TForm1::Button1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { if (Button1->Left Left = Form1->Width - Button1->Width - 10; elseButton1->Left = Button1->Left - 5;} , , . Timer OnTimer ( Interval ), : void __fastcall TForm1::Timer1Timer(TObject *Sender) { Panel1->Caption=Now().DateString() + "/" + Now().TimeString();} 254 .Now(). DateString() , TimeString() . - . 10. File/SaveAll(, ++). , Unit1 Project1. Run/Run . 2.3 , , , . ::,-, . / - ..Standard-: (Label), GroupBox, (Panel), (ScrollBar).GroupBox1 RadioButton, GroupBox2 CheckBox. C++ Builder55 , . Form1Caption 3 Label1CaptionR Label2CaptionG Label3CaptionB GroupBox1 Caption Height90 GroupBox2 Caption Height90 RadioButton1 Caption 1 Checkedtrue RadioButton2Caption 2 ScrollBox1, ScrollBox2, ScrollBox3 Max255 Width550 CheckBox1 Caption Checkedtrue CheckBox2 Caption Checkedtrue CheckBox3 Caption Checkedtrue Panel1Caption 1 Panel2Caption 2 OnChange. , -PanelRadioButton.- : -.- RGB (Red-Green-Blue), - . OnChange ScrollBar1. , 2.2, .- :void __fastcall TForm1::ScrollBar1Change(TObject *Sender) { if(RadioButton1->Checked) Panel1->Color = RGB(ScrollBar1->Position, ScrollBar2->Position,ScrollBar3->Position); else Panel2->Color = RGB(ScrollBar1->Position, ScrollBar2->Position,ScrollBar3->Position); } 256 OnChange ScrollBar1 ScrollBar2,, ScrollBar2 - ScrollBar1Change. : ScrollBar2; Object Inspector Events; OnChange ScrollBar1Change: ScrollBar3- OnChange. - , (CheckBox). (-Checked),,. ., CheckBox1,CheckBox2,CheckBox3 OnClick, : CheckBox1:ScrollBar1->Enabled = CheckBox1->Checked; CheckBox2:ScrollBar2->Enabled = CheckBox2->Checked; CheckBox3:ScrollBar3->Enabled = CheckBox3->Checked; (File/SaveAll) - () . : C++ Builder57 2.1.4 .- . , File / New New Items (. . 2.7). Forms - : ,Dialogs- : File / New - View / Project Manager , New. (, , ) Remove. - File / Include Unit Hdr include. -, + ,- 258 include. Open File at Cursor. , + OpenSource/HeaderFile-cpp-h-,cpp- . + - . - , , , - IDE, , treeview, -.,- + IDE. Project / Options, - , , -, , - . , AboutBox, 9.3. C++ Builder59 2.2 2.2.1 ,- , . - , -.- . .. , - . .,- . , - , . , , - . ++ cout"); scanf("%i %i %i",&day,&month,&year); if(month==1||month==2)year--;// m = month-2; // if(mCount; // Memo1 if(NStrings[i]); // if(x%2==1) k++; // . } // . Edit1->Text=IntToStr(k); } //----------------------------- // . void __fastcall TForm1:: Button2Click (TObject *Sender) { Close(); } 4 , 2 = k z = 1 ) 6 () 5 )( 1 (+ +=k kk kz z z k=0, k= 1 125 4.31Memo . . - , . Memo, sum, k aver.

: void __fastcall TForm1::Button1Click(TObject *Sender) { float aver, sum=0; int x, k=0, i, n; n=Memo1->Lines->Count; // n Memo1 if(n==0) // Memo1 , {ShowMessage (" Memo1"); return;}for(i=0; iLines->Strings[i]); // Memo1 if(x>-10 && xText=FormatFloat("0.00",aver); } else // { Edit1->Clear(); ShowMessage(" "); }} 4.32 Memo , . . . , Memo , - , , 0, , , . , - , Memo1, - 4126 return. , , - .

: void __fastcall TForm1::Button1Click(TObject *Sender) { int x, i, n=Memo1->Lines->Count; if(n==0) {ShowMessage (" Memo1"); return;} for(i=0; iLines->Strings[i]); if(xClear(); A = StrToFloat(Edit1->Text); B = StrToFloat(Edit2->Text); h = StrToFloat(Edit3->Text); for (x = A; x Lines->Add(FormatFloat("0.00",x)+""+ FormatFloat("0.0000",y)); Series1->AddXY(x, y, " ", clRed); } } 4128 4.34R(t), t : ( )( )( )( )( ) ( )t s st t< s=+ .2 1 sin;20 cos1t t n et nt et Rn tn t t[0,]h = /20.n . : void __fastcall TForm1::Button1Click(TObject *Sender) { Memo1->Clear();Series1->Clear(); int n=StrToInt(Edit1->Text); float t, R, h=M_PI/20; for(t=0; t=0 && tAdd(FormatFloat("0.000", t)+" " +FormatFloat("0.0000", R)); Series1->AddXY( t, R, "", clRed); } } //------------------------------------------------------------ void __fastcall TForm1::Button2Click(TObject *Sender) { Edit1->Clear();Memo1->Clear(); Series1->Clear(); } //------------------------------------------------------------ void __fastcall TForm1::Button3Click(TObject *Sender) { Close(); } 129 4.35 -( ) 4 4 . 42 3+ = x x x x f : , - | | b a x , e c.. - f(x), [a, b]. - F(x), : ( ) ( ) ( )} =baa F b F dx x f ,, . , , ,(.4.1). ,[a, b] (,n), S si, f(x) f (x), }== =baniis dx x f S10) ( . . 4.1. ,f(x), ().- f(x), i = a + ih , h = i+1 i, , i = 0, 1, , n. : , . f(x)h=i+1 i( = 0, 1,, n) , (. 4.2). - n . f(x) y 0a = x0 x1 x2

x x+1 xn-1b = xn si 4130 ( ) ( ) ==+== = =1010110) (nii inii iniix f h x f x x s S . . 4.2. -,- . , - n (. 4.3). . 4.3. S ( ) ( ) ( ) ( ) ( ) ( )||.|

\|+ + = + = = ==+=111011022 2niinii iniix f b f a fhx f x fhs S . - ,- , f(x) y 0a = x0 x1 x2

x x+1 xn-1b = xn si f(x)y 0a = x0 x1 x2

x x+1 xn-1b = xn si 131 n [xi h, xi + h]. , n/2 (. 4.4). . 4.4. S : ( ) ( ) ( ) ( )||.|

\|+ + + = ==21112 43njjniix f x f b f a fhS , i ,j . ,,, . Image.bmp Picture . : // double f(double x){ return x*x*x-x*x-4.4*x+4; } // double integral_Pr(double a, double b,double eps){ double h=eps,s,x; for(s=0, x=a; xText=FloatToStr(i_bar); i_trap= integral_Trap(a,b,eps);// Edit5->Text=FloatToStr(i_trap); i_simp= integral_Simp(a,b,eps);// Edit6->Text=FloatToStr(i_simp); } for 4.36 , 3. .1099.-12(,3)99 (,3)3, . : #include #pragma hdrstop #include #include #pragma argsused //------------------------------------------------------------- int main(int argc, char* argv[]) {int i, s=0;// 0 for(i=12;iAdd(IntToStr(k)+")"+FormatFloat("0.00000",u)); y += u; k++; } while(fabs(u)>=eps); Edit3->Text=FloatToStr(y);Edit4->Text=IntToStr(k); } while do-while 4.53110 , . . 1, 2, 3, 4, ..., i,1 10. : i; ; 1. for: #include #include //------------------------------------------------------------ 4152 int main(int argc, char* argv[]) {int i, x; for(i=1; iText=IntToStr(k); Edit3->Text=FormatFloat("0.000", max)+" "+IntToStr(ind); Memo2->Clear(); for(i=0; iLines->Add(A[i]); } 1 , 0 = n i n n>15 n=15 [i] p, k, max, ind 1 , 0 = n i[i] k=0, =1, m=[0], ind=0 1 , 0 = n i [ind]=v[0] [0]=m m=[i], ind=i [i]ColCount=j;// SG2 for(i=0; iCells[i][0]=FormatFloat("0.0", b[i]); } 5176 5.2.4 . 8. ,- , - . ,- , , -.,- , -.- , - ., return, . . , .,- : int * function (); ,- . : float fun (int a[10]); float fun (int a[]); float fun (int *a); . . , . , . . 6. , -,C, . -. : float fun (int a[], int n); float fun (int *a, int n); ,-, - void ( , ). - , - , (. 5.9 5.12). ++177 5.811-, . 1.. (a[i]>a[i+1])( ), , , -Button1Click., , , , - . void __fastcall TForm1::Button1Click(TObject *Sender) { double a[11];int i, N=Memo1->Lines->Count; if (N>11) N=11; for(i=0; iLines->Strings[i]); for(i=0; i a[i+1]) {ShowMessage(" "); return;} ShowMessage(" "); } 2. sorted(), true, -,false.,,- , , -false.- , true. . . 8. bool sorted(double a[], int n){ for (int i=0; i a[i+1]) return false; return true; } 5178 void __fastcall TForm1::Button1Click(TObject *Sender) { double a[11]; int i, N=Memo1->Lines->Count; if (N>11) N=11; for (i=0; iLines->Strings[i]); if (sorted(a, N)) ShowMessage(" "); elseShowMessage(" "); } 5.9 15- m .. - -..- . . sort() (bublesort). ,- ., . a[i] a[i+1] . for , - . , - tmp: tmp = a[i];// a[i] a[i] = a[i+1];// a[i] a[i+1], a[i+1] = a[i];// a[i+1] , a[i] , , -. , - , , .>,- , Strings[i]); sort(a, n);// Memo2->Clear(); for (i=0; iLines->Add(FloatToStr(a[i])); } 1 , 0 = n i n n>15 n=15 [i] 1 , 0 = n i[i] sort(a, n) sort() j=i+1,n1 i > j tmp = i i = j i=0,n2 j = tmp 5182 , .sort2()-,ok , (ok=1) -, , - . : void sort2(float a[], int n) { int i; float tmp; bool ok=1; while (ok) { ok=0; for (j=0; j a[j+1]) { tmp = a[j]; a[j] = a[j+1]; a[j+1] = tmp; ok = 1; } } } 7- :0.9, 2.1, 6.3, 3, 8, 5.1, 30. . 0123456 0.92.16.3385.130 1- 2.10.936.35.1830 2- 2.10.935.16.3830 3- 2.10.935.16.3830 ,,-, . , - , , ok (ok=1), , , while. - , sort3(). , ( -)(), . (n+1)/2. ++183 7- : 5, 1.3, 7.1, 4.8, 2, 7, 1.6. ,-. (, ). , , - . 0123456 51.37.14.8271.6 =0 7.11.354.8271.6 =1 7.11.354.8271.6 =2 7.11.31.64.8275 =3 7.11.31.624.875 =4 7.11.31.624.875 =5 7.11.31.624.857 void sort3(float a[], int n) //n { int i, j, imin; float tmp; for (i=0; iClear(); for (i=0; iLines->Add(FloatToStrF(a[i],ffGeneral, 5, 2)); } 5.11 12- ( -, ) , . . StringGrid, . 5.3.2. : void Zamina(int V[12]) { for (int i=0; iClear(); for (i=0; iAdd(st); } ListBox, Memo,Lines Items. , Memo1->Lines->Add(st); ListBox->Items->Add(st); StringGrid ( ) - Additional . -StringGrid,- . , Cells .,53String-Grid1,.5.1. StringGrid -. float [5][3] StringGrid1: for (i=0;iText); sokr(d2); s = sum(d1, d2); Edit7->Text=IntToStr(s.a); Edit8->Text=IntToStr(s.b); } //----------------- ----------------------------- void __fastcall TForm1::Button4Click(TObject *Sender) { drib d1, d2, p; d1.a=StrToInt(Edit1->Text);d1.b=StrToInt(Edit2->Text); sokr(d1); Edit3->Text=IntToStr(d1.a);Edit4->Text=IntToStr(d1.b); d2.a=StrToInt(Edit5->Text);d2.b=StrToInt(Edit6->Text); sokr(d2); p = dob(d1,d2); Edit9->Text=IntToStr(p.a); Edit10->Text=IntToStr(p.b); } //----------------- ------------------------------ void __fastcall TForm1::Button5Click(TObject *Sender) { drib d1, d2, r; d1.a=StrToInt(Edit1->Text);d1.b=StrToInt(Edit2->Text); sokr(d1); Edit3->Text=IntToStr(d1.a);Edit4->Text=IntToStr(d1.b); d2.a=StrToInt(Edit5->Text);d2.b=StrToInt(Edit6->Text); sokr(d2); r = chast(d1, d2); Edit11->Text=IntToStr(r.a);Edit12->Text=IntToStr(r.b); } 9 326 9.3 , , -.++ , , . -++lib.- , - , . Borland C++ Builder : ++ ( -, ++); Windows; Borland ++ Builder, - ++ Builder. , , Borland++Builder, .- :1)Project / Add To Project., , lib, - ; 2)#pragma link. #pragma link "" 9.4 , - , ,,-. C++ . -, #define #include, . 327 ,-, . , , ,, . #. . ()- , -(- ). # ,, , , , , - () - , . # . , . - ( '\', - , - ). : #define ; #include ; #undef -; #if -; #ifdef ; #ifndef ; #else #if; #endif #if; #elif #else/#if; #line ; #error ; #pragma , ; # . , , - #define: defined ;## ; # . #define.- , . 9 328 .,, #define.#define, , , -. , , . , , ,-. #define :#define #define . . - , . - . n 10 #define n 10 const int n = 10; , : 1)-, ; 2), ; 3) n , , , n unsigned short, . , #define ++ - .#include,,- . - . -: #include #include "__" #include_ ,. , (includedirectories). ,, : , #include; , #include; 329 ;, /I; , INCLUDE. , . #include , -,. Text=x/y;} .,-,, . , - . 2) void __fastcall TForm1::Button1Click (TObject *Sender) { int x=5; 559 while(xText=IntToStr(x); } -., Edit12147483647,, . ( x-=2;) - . , Button1. - . , - (=5). + Watch, ,- . 2 15. - int, (, ). 15, Edit1 . 15.1 I = U / R, U- (), R (). : void __fastcall TForm1::Button1Click(TObject *Sender) { float u, r, i; u=StrToFloat(Edit1->Text); 15 560 r=StrToFloat(Edit2->Text); i=u/r; Edit3->Text=FloatToStr(i); } Edit110.5 10,5,, Button1 . . Edit1 .Windows, Edit1 - u =StrToFloat(Edit1->Text); ,StrToFloat- . - DebuggerException Notification- , , . -, Run Program Reset, Step Over. :1) ( ) stack overflow. : void f(int n) { f(n+1); } void __fastcall TForm1::Button1Click(TObject *Sender) { f(5); } 561 , ., , : void f(int n) { if (n>=10) return; f(n+1); } 2)/- :pow: domain error log: SING error., x=pow(-5, 0.3); , - : float x=0; Edit1->Text=FloatToStr(log(x)); : ,