1
MICROSOFT VISUAL C++ , ֲ
Ͳ
. . : , ; , , , 㳿, , , . , .
, , .
ϳ , , .
, -. , .
. . .
(. ).
, . .
.
, (. , , ).
, . , , .
:
1. ++.
|
|
2. C++ (IDE) , .
3. .
4. .
5. .
6. .
7. C++ .
:
1. , :
- : , , , , ;
- .
2. C++.
3. .
4. , .
5. .
( ):
- , , ( );
- ;
- ;
- " " , , ;
- " " ;
- ;
- .
.
, , .
Microsoft Visual C++. , . ++.
1.2
ϳ (. 1.3), , , : ++, , , ++: , , , , ++
, - () ѳ . ѳ- , - . , . , ѳ-, .
|
|
ѳ :
, h-;
, ѳ-.
".h". ".c" ѳ ".cpp", ".cxx" ".cc" C++. . , C-, . , ѳ- , h- - .
, . . , . #include. .
ѳ. . , . , . , . .
, "Hello, World".
#include <stdio.h> int main() { printf("Hello, World\n"); return 0; }
ѳ-. printf ( ). main, ( return 0;), , . , .
C++ , . , ( ) . , , .
ֳ . char, short, int long. , unsigned signed () .
ij : double ( " ") float ( ""). ij double 8 , float 4 . double '.
C++ bool. bool : false true. false true C++.
, .
ѳ , .
, , . ' . :
int a[10];char c[256];double d[1000];
10 . , ѳ , 0 9. 256 ( 0...255), 1000 ( 0...999). ' , : a[10], c[255], d[123].
|
|
, '. ', . ' , . :
int *a, *b, c, d;char *e;void *f;
a b int c d int (c d !). 䳿:
1. . , &. , a = &c; a c;
2. ', ; *, . , d = *a; d , a.
. , . " ", " ", " ", ", ", " " . :
, , int *(x[10]); " 10 int ";
:
o * . , int *x[10]; " 10 int ". ' x [] ( ), , . . " ", ! , : int (*x)[10]; ' x * ;
o [] ( ') ( ') , , . :
- int f(); f , int;
- int (*f())[10]; f , 10 int;
. . '. , ' . , ( ), ( ), ( ). . , , , . :
void (*a[100])(int x);a. 100 , , x int, , , void. :
|
|
1. a -
2. 100
3.
4. x int,
5. void.
a:
void (* a [100])(int x);5) 3) 1) 2) 4)
ѳ . ( ). , , . :
char str[10];str[0] = 'e'; str[1] = '2';str[2] = 'e'; str[3] = '4';str[4] = 0;
str 10 , 9, . str " e2e4 ". . 5 str 0...4. 5 . , :
char t[] = "abc";
t, . ϳ " abc ", t. t , 4 , . , , .
ѳ , . .
³, , , , , ѳ , . , ( ) ѳ; +, += ++. , .
, , .
+, , * / ѳ , %. % , . ³, % ( ), ,
. true false . :
bool res;int x, y;res = (x == y); // true, x y, falseres = (x == x); // trueres = (2 < 1); // false
ѳ :
== ,!= ,> , >= ,< , <= ., ѳ , . :
& ("")| ("")~ ("")^ 2 ( "")
( ', && ||, .)
. , x ', . A, B, C, D. A x ( , ). ( ), , ' A. B, C, D 1, 2, 3. , , ( ):
const int MASK_A = 1;const int MASK_B = 2;const int MASK_C = 4;const int MASK_D = 8;
ֳ . , x , , , D, . x MASK_D; , , ' D, , . :
|
|
MASK_D x, D, D x. :
x: 0101110110...10*101MASK_D: 0000000000...001000x & MASK_D: 0000000000...00*000
dz D x.
D x :
x = (x | MASK_D); // D x
" ":
x |= MASK_D; // D x
:
x: 0101110110...10*101MASK_D: 0000000000...001000x | MASK_D: 0101110110...101101
"~" :
x: 0101110110...101101~x: 1010001001...010010
( ) D :
x = (x & ~MASK_D); // D x
, "&=" " ":
x &= ~MASK_D; // D x
, D,
MASK_D: 0000000000...001000~MASK_D: 1111111111...110111
, D. x :
x: 0101110110...10*101~MASK_D: 1111111111...110111x & ~MASK_D: 0101110110...100101
x D , .
: . "" >>, "" <<. :
int x, y;...x = (y >> 3); // 3 y = (y << 2); // 2
k k . k 2k. , - . k k , , . , :
unsigned x; x = 110111000...10110011x >> 3 = 000110111000...10110
k 2k. " ". , , , , , , . , , , k , . , , . k = 1 2 , -1. -1, , . ( ):
int x;x = 110111000...10110011x >> 3 = 111110111000...10110
, . , x0, x1, x2, x3, x0, x3. . :
int x;int x0, x1, x2, x3;...x0 = (x & 255);x1 = ((x >> 8) & 255);x2 = ((x >> 16) & 255);x3 = ((x >> 24) & 255);
255 . , 255 . x n, n = 0,1,2,3, x 8n , , n . .
. , ( ).
if (" ") . ³ : " " " ... ". "" :
if () ;" ... "
if () 1;else 2;
- . , " " - . " " if. , , , . , m x y:
double x, y, m;...m = x;if (y > x) m = y;
" ... " , , , if; else. , :
double x, y, m;...if (x > y) m = x;else m = y;
, , , :
double x, y, d;...if (d > 1.0) { x /= d; y /= d;}
x y d , d .
ʳ " ... " ( else ). . . : x, y sign(x):
sign(x) = -1, x < 0sign(x) = 1, x > 0sign(x) = 0, x = 0
:
double x, s;...if (x < 0.0) { s = (-1.0);}else if (x > 0.0) { s = 1.0;}else { s = 0.0;}
x < 0.0. , s = (-1.0); x < 0.0. s = 1.0, s = 0.0. Գ .
, (, ). . , .
" " while:
while () ;
while , . while : . , . ; , , . , . :
int n, p;...p = 1;while (2*p <= n) p *= 2;
p , n.
,
break;
. : f(x), .
int f(int x); // ...int x;...// f(x) x = 0;while (true) { if (f(x) == 0) { break; // } // x // 0, -1, 1, -2, 2, -3, 3,... if (x >= 0) { x = (-x - 1); } else { x = (-x); }}// : f(x) == 0
" while (true) ". " break ".
- , . :
continue;
continue, , break, , . , . : n+1 , i = 0, 1,..., n; . n, , . k - 1. :
x = t. :
double x[100]; // ( 100)int n; // ʳ int k; // double t; // , double L; // L_k(x) t int i;...L = 1.0; // i = 0;while (i <= n) { if (i == k) { ++i; // continue; // k - } // L *= (t - x[i]) / (x[k] - x[i]); ++i; // }// ³ L
continue , i = k.
for :
for (; ; ) ;. . , , . ( ).
, for , while, . , , , ( ).
for:
double a[100]; // a 100 -int n; // a (n <= 100)double sum; // - int i; // ...sum = 0.0;for (i = 0; i < n; ++i) { sum += a[i]; // a[i]}
i . i 0. i<n. ++i i . , i 0, 1, 2,..., n-1. i .
, ().
1.3
1. :
0 5 0,5. [ 2 4 ] 0,1.
2. :
y =
0 5 0,5. [ 3 11] 0,1.
3. :
;
= 0,75 2 + m;
0 5 1,1; 0 3 0,2; m=3. () .
4. :
r =
m 5 5 0,5; = 3; [ 3 3] 1; 0 50 10. (x, l) .
5. :
0 4 0,1, 2 5 0,2. () .
6. :
;
0 3 1, 0 4 0,5. (a, m) .
7. . , , .
8. .
9. . . ( 3- ).
10. :
.
0 3 1,2, n 10 -56 5,
11. :
0 5 0,5. [ 2 4 ] 0,1.
12. :
y =
0 5 0,5. [ 3 11] 0,1.
13. :
;
p 0 5 0.9; x 0 3 0,3; m=3. () .
14. :
r =
m 5 5 0,5; = 3; [ 3 3] 1; 0 50 10. (x) .
15. :
0 5 0,1, -2 5 0,2.
16. :
;
2 15 1, 0 5 0.5, m -2 2 0.41. (, a) .
17. :
,
.
x 0 5 0.58, n 1 -5 0.5.
18. :
.
0 5 0.2, n -5 10 2.5.
19. :
0.1 5 0,5. [ 2, 4 ] 0,1.
20. :
y =
0 8 0,5. [ 3,11] 0,2.
21. :
;
p 0 15 0.741; x 0 3 0,3; m=3. () .
22. :
r =
m 5 5 0,5; = 3; [ 3 3] 1; 0 50 10. (x) .
23. :
0 5 0,1, -2 5 0,2.
24. :
;
2 15 1, 0 5 0.5, m -2 2 0.41. (, a) .
25. :
,
.
a 3 15 0.58, n 1 -5 0.5.
26. :
,
.
x 3 21 0.62, n 1 -5 0.5.
27. :
,
.
a 3 15 0.74, n 1 -5 0.5.
ֲ Ͳ Ͳ
1. , , .
2. .
3. .
4. , 璺, , 䳿, .
5. , 䳿, , , , .
6. , . .
² ί
̳
:
2
++ Ҳ ֲȻ
: . .. -09-1 . . | : ____________ ___________________20___. |
20___
IJ˲ ² ί
:
1. . .
2. .
3. . : , , , .
4. . : . .
5. . , , ++ Microsoft Visual Studio ( IDE, ).
Ҳ ²
1.1 . , , , ,
1.2 . , . , , ,
1.3 . , , , , . Times New Roman, 14, , . : , ; ; . !
: 0 ; 1,25 ; 0 ; ; .
, . , . .
1
.
. . , : , ( ) .
. | (1) |
.
:
14 .
12 .
10 .
20 .
12 .
( , )
Times New Roman
Times New Roman
Times New Roman
. Symbol
. Symbol
Symbol
- Times New Roman
Times New Roman
Microsoft Word. . , .
1
% |
1.4 . , : , , , Screenshot , .
. , , : ? ? ? ? ? , . , .
abs | |
acos | |
asin | |
atan | |
atan2 | |
ceil | |
cos | |
random | 0 . |
exp | |
fabs | ( ) |
floor | |
fmod | |
frexp | . |
ldexp | |
log | |
log10 | 10 |
modf(x,p) | ( ) |
pow(x,y) | x y, xy |
sin | |
sinh | |
sqrt | |
tan | |
tanh |
C++
acosh | ||||||
asinh | ||||||
atanh | ||||||
cbrt | ||||||
copysign(x, y) | , x, y | |||||
erf | ||||||
erfc | ||||||
exp2(x) | 2, x, 2 x | |||||
expm1(x) | ex − 1 | |||||
fdim(x, y) | x y, fmax(x − y, 0) | |||||
fma(x, y, z) | (x * y) + z (. FMA) | |||||
fmax(x,y) | x y | |||||
fmin(x,y) | x y | |||||
hypot(x,y) | , sqrt(x ² + y ²) | |||||
ilogb | , int | |||||
lgamma |
: 2016-11-24; !; : 557 | : : - , , . |
: 0.371 .