Examination_IT / Programming bases on With C++
.pdf21
F ( ) ; -
; , ; , :
"Hello World!", "]Q^@BQ<PH cp1251"
1.7. L9/9; ?M/ < 5 0: ;; / <628 ++
F @
C++. ` ,
1.2. 5 -
; d .
8 58 9 1.2. !6:; Ex01_02.cpp
#include "stdafx.h"
void _tmain()
{
}
? :
#include "stdafx.h"
F Z . …
; . ? ;
.
. C++
void _tmain()
{
}
22
=. : Z = – _tmain – (
main) , d . .
, , =,
;@ – Z ; =
, = _tmain
; C++. F
= _tmain ;
C++. s _tmain ; ;@
;@ ,
. F =
@ = {},
; =. . Z
, Z d
. /, (build) - d , … . ~
( /F) Windows, d ; = -
, Z
d . 3 -
r – =
. ? … -
.
d , -1.3 .
8 58 9 1.3. !6:; Ex01_02.cpp
#include "stdafx.h"
#include <iostream>
void _tmain()
{
system("pause");
}
. …
/F Windows. . ( 1.3). ? Z
, ; ; d . /-
23
, , -
system("pause");
=: « ; ; d…».
D . 1.3. / Ex01_02.
.
#include <iostream>
.
1.8. ; //2
? – Z , -
. ?,
, . ? -
.
; ; -
char, short, int, double, void ( . 1.1). :-
= unsigned ( ) signed ( -
) -.
3 signed int, signed char, . . ; Z-
int, char, . . 5 -
, .
24
3 unsigned int, unsigned char, . .
. ;
, ;@ . B-
Z, ‰d -
, -
.
? r =-
_tmain:
void _tmain()
{
int n;
unsigned int un = 5;
double b, Force = 5.67, Massa = 7.0; double Pover = 4.75e+3;
char ch = 'a', letter; byte Flag = true;
n = 567;
}
. Z = = ( ) -
; n, b, Force, Massa, Pover, ch, letter, Flag. : = .
: = int, unsigned int, double, char byte
; ; .
. = , -
; , . . -
Z . 3 -
un 5, - ;@ Pover – 4,75 ∙ 10 . ?
, , Z
d. ?
… r,
, ; =. 3, n
… r.
: ;, -
, … r
r.
25
? r , -
… Z -
( . 1.1).
~
r , -
r . ~ -
, d .
1.9. /.4 O8P99
: – Z = -
, ;@ Z
. . ; , -
, , .
: C++
. : Z , -
= . ? Z ; -
C++ ,
« » , - d - .
F ;@ = -
r un -
.
int n;
unsigned int un = 5;
1.10. 0: ;; 9 01 /9 80/.0?M/0:0 110 -1210
. - ;
= ; -
26
d , , ,
, . . ? ,
@ ; d . . -
= , -
d , -
. . Z ,
=. , Z
. 10.1
1.1
f 1.4 , ;@ ;
-
. t , ,
,
; , Z . / -
, . 1.4.
8 58 9 1.4. !6:; Ex01_03.cpp
// ^=; ab?Pc@@ setlocale.
// ^=; AQRQPQ<QdQ <<Q^H-<D<Q^H
// (^=; P=HFFQ< cout @ cin). using namespace std; // ^>=H>C <@^@CDC FRH?^HBR?Q>
// ABQFRBH?FR<Q @C>?.
void _tmain()
{
//eHFRBH@<H>C ABQdBHCCb ?H @FAQ=fIb>CDK ;IDP. setlocale(LC_CTYPE, "Russian_Russia.1251");
//i=QP Q9:;<=>?@; A>B>C>??DE @ @E @?@c@H=@IHc@;.
double f; |
// F@=H. |
double a; |
// bFPQB>?@>. |
double m; |
// CHFFH R>=H. |
// i=QP <<Q^H @FEQ^?DE ^H??DE. cout << "j?HJ>?@> CHFFD > "; cin >> m;
27
cout << |
"j?HJ>?@> bFPQB>?@;> "; |
cin >> |
a; |
// i=QP |
<DJ@F=>?@K. |
f = m*a; |
// <DJ@F=>?@> F@=D. |
// i=QP <D<Q^H B>Ib=fRHRQ< BHFJ>RH < QP ?Q AB@=Qk>?@;.
cout << "l@=H = "; |
// <D<Q^ ?H PQ?FQ =f l@=H = . |
||
cout << f; |
// <D<Q^ ?H PQ?FQ=f I? HJ>?@; |
F@=D f. |
|
cout << endl; |
// A>B>EQ^ ?H ^Bbdbm F RBQPb. |
|
system("pause");
}
D. 1.4. / Ex01_3
?
#include "stdafx.h" |
// ^=; ab?Pc@@ se tlocale. |
|
#include <locale.h> |
||
#include <iostream> |
// |
^=; AQRQPQ<QdQ <<Q^H-<D<Q^H |
|
// |
(^=; P=HFFQ< c out @ cin). |
c .
? Z , -
;@ . . -
; # (d, ) .
#i clude ; ; (include – ;)
=: stdafx.h, loc le.h, ;@
d «h» (head – )1, = iostr eam, ;@
1 ? = @ MSC++, ;
d. 3, = iostream d, MSC++
Z = – iostream.h, -
28
d. 3, ,
#include "stdafx.h" d
= stdafx.h. e stdafx.h -
d , @ ; ;-
= , -
. e stdafx.h , Z
; «"…"». D = locale.h, iostream Microsoft Visual Studio. / C:\Program Files\. :
Z , =
C:\Program Files\Microsoft Visual Studio 9.0\VC\include\
: =, Z , -
; < >. . = -
= =, d
. . = locale.h = = setlocale, = iostream = cout cin. B = ,
:
#include <locale.h> #include <iostream>
. Z 12 @ d
=. 5 @
error C3861: 'setlocale': identifier not found
? @ d ,
; . 3, -
. ~@ =-
«c» = -
d. 3, MSC++ = math.h , ;, – cmath. 5
d .
29
double f; |
// F@=H. |
@ d:
error C2065: 'f' : undeclared identifier
? Z @. ` ,
; ; ; … ,
@ d. / ;
, = , Z
C++, -
Z =. t
; Z , ( . 1.11), -
Z = = . :
– , , -
= = C++. Z MSDN. t -
= ,
Z = d <F1>. 3 d
using namespace std;
;, ;@ ; -
. ?
« » ; r C++. t
r, ; ,
Z , ;
using namespace, . . d
, Z std. ?
; d d .
? #include
( . 1.13).
? ; = d – _tmain.
? = _tmain
setlocale(LC_CTYPE, "Russian_Russia.1251");
30
@ ; = ; setlocale ;1,
; d
/F. / /F Windows
. ! -
VSC++, Windows, -
cp1251 ( ANSI). ! Z
; , -
DOS (OEM). 3 Z
( . 1 2), VSC++, -
, -
. . Z , -
= setlocale,
. e setlocale @ ;
/F Windows @ . /,
d, Windows, Z
, Z Z = . F ;@ ( -
) :
// i=QP Q9:;<=>?@; A>B>C>??DE @ @E @?@c@H=@IHc@;.
double f; |
// F@=H. |
double a; |
// bFPQB>?@>. |
double m; |
// CHFFH R>=H. |
;@ double. + C++ @… ;@ – float.
. Z - -
. ? Z
@ , d
double. /, @ long double ( . 1.1), 10 ,
,
3,4 ∙ 10 ; 19- @ =. /
1 f ( . locale) – , , =
, , , ,
.