Examination_IT / Programming bases on With C++
.pdf81
? Z =
1 1 1 0
? -
: true, false, 1, 0 -
, @ a>b
a>b && c==d.
4.3. /.4 O8P99 1270
! if, if…else
;. ~ @… ; -
(switch). :
= @ Z
; .
: -* (/ -* /)
;@ =
;@ = . / -
; ,
. ? = :
x++;
{// ?HJH=Q 9=QPH @?FRBbPc@K. double d = sin(u);
k = sqrt(d * d + z); y = z + k;
} // PQ?>c 9=QPH @?FRBbPc@K. u = y * pow(u, 4.75);
82
) / -* / if
/ @ if:
if( ) _1 _ _1;
?:
if(x > 10) cut << ("x 9Q=fw> 10");
? x > 10 -
x 9Q=fw> 10
. Z . t @ ; d , ; ;
; :
if(x > 10)
cut << ("x 9Q=fw> 10");
? :
if(x > 10) { cut << ("x 9Q=fw> 10"); y++;}
.Z x > 10 -
«x d 10»
y 1.
3 @ , ; @ - ; :
if(x > 10)
{// ?HJH=Q 9=QPH @?FRBbPc@K. cut << "x 9Q=fw> 10";
y++;
}// PQ?>c 9=QPH @?FRBbPc@K.
83
~ = , - ;@ ,
if(x > 10)
cut << "x 9Q=fw> 10";
y++;
. Z @ , x d 10,
, x > 10, -
y++ , x > 10. : = ; else
( ):
if( ) _1 _ _1; else _2 _ _2;
?:
if(x < y) |
z |
= |
1; |
else |
z |
= |
2; |
? :
z = (x < y)? 1 : 2;
3 . F … , , d -
Z x < y, z 1, 2.
. 1 2 -
.
t
if (x == 1)
cut << "„PF BH<>? 1"; else if(x == 2)
cut << "„PF BH<>? 2"; else if(x == 3)
{ // ?HJH=Q 9=QPH @?FRBbPc@K. cut << "„PF BH<>? 3";
y = 1;
} // PQ?>c 9=QPH @?FRBbPc@K.
84
else
cut << "e>AB>^bFCQRB>??Q> I?HJ>?@> @PF";
;
. B F++ ;
;@ :
if ( _1 && _2)
_1 _ _1;
if ( _2 || _3)
_2 _ _2;
if ( _4 || ! _5 && _6)
_3 _ _3;
?:
if (x>3 && x<10)
|
|
cut << "x < ^@HAHIQ?> (1, 3)"; |
|
|
||||||
4.1 |
|
|
|
|
|
|
|
|
||
|
@ , |
|
|
/, |
||||||
. |
|
' + ' + |
0 |
@ |
||||||
|
|
|
|
|
|
|
( ≠ 0). |
|
||
|
D d . B - |
|||||||||
F |
. ~ |
F 0 |
, |
- |
||||||
|
|
|
|
|
|
|
|
|
@ . ? Z d Z , , ;@ ; -
:
// ‚DJ@F=>?@> ^@FPB@C>?H?RH. double D = b * b - 4.0 * a * c; if(D == 0)
cut << "pBH<?>?@> @C>>R ^<H " "Q^@?HPQ<DE <>{>FR<>??DE PQB?;.";
else
cut << "pBH<?>?@> ?> @C>>R ^<bE " "Q^@?HPQ<DE <>{>FR<>??DE PQB?>K.";
85
. Z = , -
,
. e: «
@ », -
.
3 @ . ? @ -
d. ? d,
, ; -
@ . ?-
Z , D == 0 -
. . @ ;
, G.
|
if(a == |
b) |
|
if(a >= |
b) |
|
|
a b.
! d -
4.1, . 4.3.
8 58 9 4.1. !6:; Ex04_01.cpp
#include "stdafx.h" |
// ^=; setlocale. |
#include <locale.h> |
|
#include <iostream> |
// AQRQPQ<DK <<Q^-<D<Q^. |
#include <iomanip> |
// ^=; CH?@Ab=;RQBQ<. |
#include <cmath> |
// ^=; CHR>CHR@J>FP@E ab?Pc@@. |
using namespace std; |
|
/////////////////////////////////////////////////////////
//
void _tmain()
{
setlocale(LC_CTYPE, "Russian_Russia.1251"); double eps = 1.0E-12; // QJ>?f CH=>?fPQ> J@F=Q. double a, b, c;
// ‚<Q^ ^H??DE.
86
cout << "]QŒaa@c@>?R a> "; cout << "]QŒaa@c@>?R b> "; cout << "]QŒaa@c@>?R c> ";
cin >> a; cin >> b; cin >> c;
// ‚DJ@F=>?@> ^@FPB@C>?H?RH. double D = b * b - 4.0 * a * c; if(fabs(D)<eps)
cout << "pBH<?>?@> @C>>R ^<H " "Q^@?HPQ<DE <>{>FR<>??DE PQB?;.";
else
cout << "pBH<?>?@> ?> @C>>R ^<bE " "Q^@?HPQ<DE <>{>FR<>??DE PQB?>K.";
cout << endl;
// †^>C ?HkHR@; =m9QK P=H<@w@ P=H<@HRbBD. system("pause");
}
D. 4.3. D Ex04_01
! /; C++
` ,
; 1,
0 . /
C++ d. f; -, 0, 0 – ;. ? Z
;@ = -
:
int a;
87
… …
if(a)
cout << "„FR@?H" << endl;
F «:» ;-
, ; a.
= ! ( -* / 2 6)
? ; -
. / ;@ :
switch ( $%$&_ )
{
case _' %_1:
_1; break;
case _' %_2:
_2; break;
…
case _' %_n:
_n; break;
default:
@?FRBbPc@@; break;
}
;@ switch
case, _' %
$%$&_ ,
$%$&_
(char, byte, short int). ! case
d break. / break
;. ~ switch
case break, ;@
case , case
88
break switch.
default , $%$&_
_' % case. ? ;
4.2, - – .4.4,
– . 4.5.
/ , case
, , r
= .
|
B |
|
|
|
|
. x |
|
|
|
|
x? |
|
: |
|
|
|
|
switch (x) |
|
~ |
~ x==2 |
~ |
: |
|
x==1 |
x==3 |
x==4 |
(default) |
|
x=1 |
x=2 x=3 |
x=4 |
B |
|
x |
||||
|
|
|
||
y=10 |
y=-10 |
y=20 |
y=-20 |
y
!
D. 4.4. - ( 4.2)
89
8 58 9 4.2. !6:; Ex04_02.cpp
#include "stdafx.h" |
// ^=; setlocale. |
#include <locale.h> |
|
#include <iostream> |
// AQRQPQ<DK <<Q^-<D<Q^. |
#include <iomanip> |
// ^=; CH?@Ab=;RQBQ<. |
#include <cmath> |
// ^=; CHR>CHR@J>FP@E ab?Pc@@. |
using namespace std; |
|
/////////////////////////////////////////////////////////
//
void _tmain()
{
setlocale(LC_CTYPE, "Russian_Russia.1251"); int x, y;
cout << "‚<>^@R> J@F=Q < ^@HAHIQ?> QR 1 ^Q 4> "; cin >> x;
switch (x)
{
case 1:
cout << "x=1"; y = 10; break;
case 2: case 3:
cout << "x=2 @=@ x=3"; y = -10;
break; case 4:
cout << "x=4"; y = 20; break;
default:
cout << "e>AB>^bFCQRB>??Q> I?HJ>?@> x"; y = -20;
break;
}
cout << endl << "y=" << y << endl;
// †^>C ?HkHR@; =m9QK P=H<@w@ P=H<@HRbBD.
90
system("pause");
}
D. 4.5. D Ex04_02
4.4. 0 6 < /2 05 P99
? ( ) ; -
1. : ; -
, @ ; -
«=» . 3,
int 4 , 32 . 3 -
, int 32- ,
=, ;@ 0 1.
=
C++ – Z
B~, :, :f: :F!f‘t-‘’~~_:f:, -
( . 4.4).
3 4.4 ? C+
|
|
|
|
~ |
? B~ |
. |
|
|
|
&? : ( )
1 ? ;@ .