: (Ken-Yi Lee), E-mail: feis.tw@gmail.com 9
[P.11] : Dev C++ [P.12] : http://c.feis.tw [P.13] [P.14] [P.15] [P.17] [P.23] Dev C++ [P.24] [P.27] [P.34] C / C++ [P.35] 10
C / C++ C C++ C C++ C++ C ( ) C++ C (C 2.0?) 11
C/C++ : (Compiler): Microsoft Visual C++ (MSVC++) The GNU Compiler Collection (GCC) (IDE: ): Microsoft Visual Studio 2010 (MSVC++) Dev C++ (GCC) : Code blocks, Qt Creator,. Microsoft Visual Studio Dev C++ Dev C++ 12
(http://c.feis.tw) 13
( ) : 14
C : How To Program C The C Programming Language The C++ Programming Language C C/C++ 15
(60%) (40%) 70 19:00 20:00 20:10 21:00 1 Q&A 21:30 2-8, 10-12 19:00 19:20 19:30 Q&A 19:40 20:40 20:40 21:30 9 19:00 20:50 21:00 Q & A 21:30 16
( 100 ) ( ) 17
18
(Programming Language) : A programming language is an artificial language designed to express computations that can be performed by a machine, particularly a computer. Programming languages can be used to create programs that control the behavior of a machine, to express algorithms precisely, or as a mode of human communication. - Wikipedia (control) (machine) 19
什麼是電腦 from Wikipedia 20
電腦的組成 抽象來說 電腦內包含了 輸入單元 (Input): 例如鍵盤和滑鼠 (感官) 輸出單元 (Output): 例如螢幕和印表機 (嘴巴 肢體) 輔助儲存單元 (Storage) : 例如硬碟和光碟 記憶單元 (Memory): 例如記憶體 程式設計核心 (記憶與計算) 中央處理單元 (CPU) 21
: : +1300042774 (01001101011111010001010000010110) +1400593419 (01010011011110110101110000001011) +1200274027 (01000111100010101011101001101011) : LOAD A ADD B STORE SUM : SUM = A + B : (x86, ARM,...) C, C++, Java, Pascal, Python,... 22
C / C++ C 1972 Dennis Ritchie 1978 The C Programming Language C 1989 (ANSI) ANSI C ( C89) 1999 (ISO) ISO/IEC 9899:1999 ( C99) [ ] C++ C C (OOP) 23
24
Dev C++ > > Bloodshed Dev C++ > Dev C++ (IDE) (*.cpp) (*.exe) 25
Dev C++ Dev C++ Microsoft Visual Studio (IDE) Tab Dev C++ : Tools ( ) > Editor Options ( ) > General ( )
: File ( ) > New ( ) > Source file ( ) : File ( ) > Save [As] ( ) ( ) cpp : File ( ) > Open Project or File ( / ) 27
(.c,.cpp) (Compile) (.exe) (Run) : Execute ( ) > Compile ( ) Ctrl + F9 Done F9 Execute ( ) > Run ( ) Ctrl + F10 Execute ( ) > Compile&Run( ) F9 28
Hello world (1) (helloworld_1.cpp) /* My first program */ #include <stdio.h> int main() { printf( Hello world!\n ); return 0; } printf( ) 29
Hello world (2) (helloworld_2.cpp) /* My first program */ #include <stdio.h> #include <stdlib.h> int main() { printf( Hello world!\n ); system( pause ); return 0; } system( ) pause MS-DOS 30
Hello world (3) (helloworld_3.cpp) /* My first program */ #include <stdio.h> #include <stdlib.h> int main() { printf( Hello ); printf( world!\n ); system( pause );; return 0; } 31
(print.cpp) H H A H H A A HHHHHH A A H H AAAAAAA H H A A print(...) 32
printf \n Newline ( ) \t Tab ( ) \\ \ 33
(add.cpp) /* Addition program */ #include <stdio.h> #include <stdlib.h> int main(){ int integer1; int integer2; int sum; printf("please enter the first integer: "); scanf("%d", &integer1); printf("please enter the second integer: "); scanf("%d", &integer2); sum = integer1 + integer2; printf("sum is %d\n", sum); system("pause"); return 0; } 34
/* Addition program */ #include <stdio.h> #include <stdlib.h> int main() { int integer1; int integer2; int sum; int printf("please enter the first integer: "); scanf("%d", &integer1); scanf (%d ) 2293620 integer1 (int)? integer2 (int)? } printf("please enter the second integer: "); scanf("%d", &integer2); sum = integer1 + integer2; printf("sum is %d\n", sum); system("pause"); return 0; printf 内 %d printf( Sum is sum );? 2293616 2293612 sum (int)? 35
C / C++ 3 + 4 * 5! ( ) (=) + - * / % = 36
(multi2.cpp) : add.cpp Please enter the first integer: 3 Please enter the second integer: 4 Product is 12 (multi3.cpp) : multi2.cpp Please enter the first integer: 3 Please enter the second integer: 4 Please enter the third integer: 5 Product is 60 37
(calc.cpp) Please enter the first integer: 3 Please enter the second integer: 4 Please enter the third integer: 5 Sum is 12 Average is 4 Product is 60 (squared.cpp) N = 3 N^2 = 9 38
printf scanf printf : printf( Sum is %d\n, sum); printf( Average is %d\n, average); printf( Product is %d\n, product); : printf( Sum is %d\naverage is %d\nproduct is %d\n, sum, average, product); scanf : scanf( %d%d%d, &integer1, &integer2, &integer3); printf % printf( Sum is %5d\n, sum); printf( Sum is %05d\n, sum); 39
(digit1.cpp) % : 12345 : 5 : 54321 : 1 (digit3.cpp) : 12345 : 3 : 54321 : 3 40
(1) [E0101] : Alice: How are you? Bob: Fine. Thank you. [E0102] Welcome to C world! Hope you have a nice day! : \ [E0103] 7 [E0104] 129263 + 54628 41
(2) [E0105] [E0106] x 3x 2 +4x-1 [E0107] helloworld_2.cpp [E0108] = - 1911 42
(3) [E0109] = 5 ( -32)/9 [E0110] (BMI) BMI = (kg) / (m 2 ) [E0111]* 129263 * 54628 [E0112] 43
44
45
46
47
48