1
’
Visual ++ Microsoft Visual Studio, , , Visual C++ Express Edition.
Visual ++ , , Windows Forms "", ’ . Visual ++ - .NET Framework, ""
Windows.
, Visual ++ , , ’ .
. . , , .
:
· ;
· ;
· ’ ;
· ++;
.
, .
:
· ;
· ++;
: , ’,
++
, ’ ’ , , ’- Visual ++ ++ .
:
:
· ++ ( , , );
· Visual ++;
· ++;
· , - ;
· ;
· - - ;
· ’;
· ();
· ;
:
, - ’, - ’ - ;
5
· , ’- ; -;
· , -
;
· - , ; ;
· C++ - ’, : - , , () , , ;
· - ’;
· ;
· - ;
· .
6
: Microsoft Visual C++ – - C++ - .
Visual ++ - ( Windows Forms) .
- ++
cout<< " : "; cin>> x;
cout<< " : " << x* << endl;
cout<< - . , '\0'. x. , - ( endl).
, endl, - '\n'. '\t', .
, setlocale(0,".1251") ( setlocale(LC_ALL, "Russian")). , Visual
Studio - Windows 1251, – DOS. cin>> setlocale(LC_ALL,
".OCP"), .
, :
system("chcp 1251");
SetConsoleCP (1251); SetConsoleOutputCP(1251);
Lucida Console.
7
cout<< , , - dec, hex oct :
setlocale(0,".1251");
cout<< ":\t\t " << oct << 10 << " "
<< 255 << endl; cout<< ":\t"<<
uppercase<<hex<<10<<"
"<<255<<endl;
cout<< ":\t\t " << dec << 10 << " "
<< 255 << endl;
:
:
12
377
:
FF
:
10
255
, , , .
cout<< - setw, ( - ) . - . - iomanip. - , setw , . ,
#include <iomanip>
. . . . .
cout<< "x=" << setw(1) << 155 << endl;
cout<< "x=" << setw(3) << 155 << endl;
cout<< "x=" << setw(5) << 155 <<
endl;
: x=155
x=155 x= 155
155 , ’ .
, - , - setprecision(int count):
cout
fixed .
cout<< -. , . cerr, ' -. ,
cerr<< " " << endl;
, .
8 1
-
1) - scanf ( ) printf ( ), stdio.h. :
scanf(<>, < _>); printf(<>, <_>);
: − . : %i − , %f − float double, %s − ;
_ − , .
, printf("x= %7.3f\n", x) , scanf("%i %f", &kol, &vart)
kol
· vart.
2) - – gets() puts(), . : puts - puts, :
puts("Hello, Dolly"); char s[13]; gets(s);
puts(s) s , - Enter. gets(s) - Enter s ( Enter -, -).
- .NET FrameWork
1) Console CLR (Common Language Runtime –
.NET-) .NET FrameWork - . System, :
using namespace System;
Read ReadLine , Write WriteLine – .
:
f, F – ; d, D – Decimal ( ); , – ;
p, P – ;
e, E – ;
g, G – General double - ;
n, N – Number ddd,ddd.dd
Console::WriteLine();
// x=54.32
y=0.01
// :
$54.32
Console::WriteLine("y={0:e} x={0:E2}",y,x); // y=1.250000e–002
x=5.43E+001 Console::WriteLine("n= {0:n}", n ); // n=
1,234.00
, -, :
Console::WriteLine("={0:0.##}", );
% 1.25
// y=12.5e–3
2) Convert System - . , double
ToDouble, float – ToSingle, int – ToInt32 . double x =
Convert::ToDouble(textBox1->Text); textBox2->Text =
Convert::ToString(x*x);
.NET
- . .NET
.
String
ToInt32()
double
ToString()
double
Parse()
int
ToString()
int
Parse()
:
// n
Console::WriteLine(n.ToString());
x = Double::Parse(s); // s
2. Visual C++
Visual ++ Microsoft Visual Studio, , . Visual C++ , - Visual
Studio, "" Windows, (managed) C++.
10 1
1 Common Language Runtime ( CLR – " ", Microsoft .NET Framework),
.NET Framework.
:
– Win32;
– CLR;
– Windows Forms.
Win32
Visual Studio , - , . ++ - Win32 – Win32. , ’ , - . , Win32, - .
cpp- - :
#include "stdafx.h"
}
:
#include "stdafx.h" #include <iostream> using namespace
std;
int _tmain(int argc, _TCHAR* argv[]) { setlocale(0,".1251");
double a,b;
cout << "i ( i)\n"; cin >> a >> b;
cout <<" - "<< a + b << endl; system
("pause>>void");
return 0;
, - .
:
– – ;
– Ctrl – F5.
( - ):
1 -. , - , , .
– – ;
– ;
, - . , system("pause>>void") :
cin.get(); cin.get();
, F9 -
– . , , , - . , .
, , - , .
- - cin cout iostream. , std, – using namespace std.
_tmain() - 1251. ( double) a b. nod(), .
(system("pause>>void")) - .
– -
, Ctrl+Shift+S, .
CLR
CLR – ++, Microsoft, - , ’, ’, .
– CLR – CLR. ’ cpp- - :
12 1
int main(array<System::String ^> ^args)
{ Console::WriteLine(L", !"); return 0;
}
System - "" WriteLine(). - CLR- ++ (. . 8) System, : ReadLine(),
WriteLine() . (. . 8 … 9). , - , . 10, :
#include "stdafx.h" using namespace System;
int main(array<System::String ^> ^args) { double a,b;
Console::Write("i ( Enter)\n"); a =
Convert::ToDouble(Console::ReadLine());
b = Convert::ToDouble(Console::ReadLine()); Console::WriteLine(" -
{0:f}", a+b); Console::Read();
return 0;
Studio / Visual ++ / CLR /
Windows Forms. , , ’ . .
, -: textBox, button label. Text label1 button1, . button1
button1_Click:
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
}
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{ double a, b;
a = Convert::ToDouble(textBox1->Text);
}
system, : "color <A><B>", <A> <B> – - – , –
(-
).
:
1) Visual ++.
2) ?
3) Visual C++.
4) - -?
5) - ( )?
6) --?
7) ?
8) ?
1) .
2) ++ ’ .
3) Visual ++ ’ :
– Win32;
– CLR;
– Windows Forms.
- .
14
: - ++ Visual
++.
:
– ();
, , , . - . - , :
– ;
– ;
2. ++
· ++ , . , ++ -
- .
’, - .
– , . . , ’ , .
++ : -. ++ . 2.1.
() char, int, float double, short (), long (), signed ( ) unsigned
( ).
() , - , , , , , , ’, .
2 348, 60 864
* – int 4 2 .
char, short, int, long. - unsigned ( ), signed – , ’. , signed -
’.
float double 32 64 -, long double – 80 . ++ . , . : 2.383 ( 2.38
103 = 2380), 3.61–4 ( 3.61 10–4 = 0.000361). “” , “” – -, 10 “e”, ,
: 13 (1 103 = 1000), –2.7–4 (–2.7 10–4 = 0.00027).
16 2
, (char, int, float, double) :
signed ( – ) unsigned () – - char int;
long (), short () – double int. :
unsigned int n;
int c; //
short ; //
unsigned d; //
signed f; //
signed int c signed short int unsigned int d signed int f
, .
int i, j = 1, q = 0xFFF;
i ; j – 1; q – - 0xFFF ( 4095).
: long MB=1024*1024;
:
char tol=''; // tol ''
char , c='\n'; // , – <Enter> char *s=""; //
, ().
void (, ) , , - . .
’, , sizeof(), , :
a
const double Pi = 3.14159;
, - . :
const double Pi2 = 2 * Pi, k = Pi / 180;
2.2
C++
Math::bs()
Math::Pow(,y)
Math::Log(,N)
Math::Cosh()
Math::Sinh()
++ (-) math.h, #include <math.h>.
, math (, M_PI ( 3.14159), M_E ( - 2.71828, ) ) - C/C++. ,
_USE_MATH_DEFINES, cmath math.h. #define _USE_MATH_DEFINES
#include <math.h> // C #include <cmath> C++
.NET Math::PI Math::. , Math::Log(,N), - - N ( ""
log(x)/log(N)).
18
, , . -
.
,
(+ , –, *, /, %, ++, --) (=).
i--;
()
--i
(%) . .
int n = 49, m = 10, x, y;
x = n / m; // x = 4
y = n % m; /* y = 9 */
, (//) (
/* */), .
++ () -- () ,
. ++ , -- . , - . - : . -, , : ++i, --j, , . , , , : i++, j--, ,
.
, :
int j, i = 1;
. - i = 1:
1) j = ++i * ++i; // 1) i=i+1=2, 2) i=i+1=3, 3) j=i*i=3*3=9. i=3,
j=9.
19
2) j = i++ * i++; // 1) j=i*i=1*1=9, 2) i=i+1=2, 3) i=i+1=3. i=3,
j=1.
3) j = i++ * ++i; // 1) i=i+1=2, 2) j=i*i=2*2=4, 3) i=i+1=3. i=3,
j=4.
:
1) , ++, --;
3) (+) (–).
++:
– () (;);
– ++ , – ;
– ;
– (3ab –> 3*a*b);
– (+, −, *, /), - ;
– , ,
, , 2
k
– ( ) ,
, 3 x 1 pow(x+1, 1/3.0);
– , - .
6.
<’_> = <>;
; .
++, , -: += ( ), – = ( ), *= ( ), /= ( ) . , x += y x = x + y, -
.
+ , - , :
a = b = c = x * y;
, x * y, c, b .
7.
, , , . :
// =7, 7.65 .
20 2
, , -
. , short int, int, – .
.
1) , , , . , 2/3 0, 2.0/3 ( 2./3) – 0.666(6).
2) , -
“=”; , , :
float a = 5.1, b = 1.5;
int c = a * b;
2) :
(<>) <_>
double a = (double) m/n; // a=0.66(6).
1.0: double a = (m*1.0)/n; // a=0.66(6).
++
1.
0.2x2
x
1) Visual Studio.
2) / Visual ++ / CLR / CLR. , -, ’ . .
3) -
/ ( , Ctrl+Shift+ S). 4) /
F5.
:
#include <iostream> #include <math.h> using namespace
std;
y=(0.2*x*x-x)/((sqrt(3.)+x)*(1+2*x)) +
2*pow(x-1,3)/(pow(sin(x),2)+1);
cout<<" y= "<< y <<endl; system
("pause>>void");
return 0;
2. -
2
3
x b
. -
m = 7.4 , b .
:
{
setlocale(0,".1251");
const double m=7.4, pi=3.1415; double b, x, p, y;
cout<<"i b= "; cin>>b; x=atan(b*b+sqrt(b+m));
p=cos(pow(exp(fabs(b-x))-
log10(fabs(x-b)),2)); y=pow(pow(sin(m*p-pi),2)/(b*x+p),1./3);
cout<<":\n x= "<< x <<endl; cout<<" p=
"<< p <<endl;
cout<<" y= "<< y <<endl; system
("pause>>void"); return 0;
}
sin2 mp y 3
x= 1.55738 p= -0.128333 y= 0.3709956
22 2
0
d – , . :
#include <iostream> #include <math.h> using namespace
std; int main ()
{
const double E0 = 8.85e-12, E = 2.8;
cout<< "i ii i d= " ; cin>>d;
cout<< "i i S= "; cin>>S;
C=(E0*E*S)/d;
}
:
4. , : 1) ’ 2) ’ .
’. ,
’ R r1 r2 , r1 r2
’ – R = r1 + r2.
:
23
Visual Studio / Visual ++ / CLR /
Windows Forms. , , ’ . .
:
{
textBox3->Text = Convert::ToString(R);
{
textBox3->Text=Convert::ToString(R);
}
}
2) ++ ?
3) j i int j, i=2;
) j = i++ + i++; ) j = i++ + ++i;
) j = ++i + ++i; ) j = ++i + i--;
4) 0.27313 .
5) 0.0001 .
6) y = x3 + sin 2x ++.
7) y :
) y = (1 + 2) / (3 + 2); ) y = 1 + 2.0 / 3 + 2;
) y = 1 + 2 / 3 + 2; ) y = (1 + 2) / (3.0 + 2).
24 2
1) .
2) ++ , . 2.4 … 2.6 .
3) ++ ’ , . 2.7 … 2.9 - .
4) ’ Visual ++ . .
“ ”
2.4
y
4.831
9
R
16
L
0.81cosi
17
W
4t3
ln
m2
e 2
2t 2
3l 7.2
cos2
y
cos3 x4
8
A
ln(x 1) y3
cos(x3 6) sin(y a)
16
G
tg(x4
sin
cos 2 y 1
eax arcsin 6x2
lny k 3y2
27
L
28
f
a xc
V5 = 15.4x
3
2
sin
lg x
sin 3
x e3
( )
3
(x 3)(x 1)2
27
y
(x 3)
( , – )
.
1
x
x3
b2 ; a
a c k 2 ; c arctg
x
a sin 5 b
b = 3; c = 1.7
13
y a cosx bsin x; x 3 a b; a t 2b
t = 2.2; b = 3
a lg
a
x2
b2 ;
k = 2; m = 1.8
pa ; t p3
e q
23
a
x
a
c t 2
t = 2; b = 1.8
b = 5;
k = 2.8
.
1 . , : S = p(p–a)(p–b)(p–c), p = (a+b+c)/2; a, b c – . . (x1, y1),
(x2, y2)
( x1 x2 )2 ( y1 y2 )2
2 , − , − L. L .
T 2LC , 1T
3 .
4 – a, b, c, – - (. 1).
30
.
5
a = (a1, a2) b = (b1, b2)
cosα a b
.
a b = a1b1 +a2b2
6
22x 4 y 20z 45 0
a2 b2 c2
7
n = 1000 1
= 0,03 . 1 = 710–4 ,
= 310– 7 .
W1 = P1 ;
= W1k;
k = c / , c = 30
8
a, b, c (, a 0 ). a = 2,
b = −8, c = −10
9
2x / a b 12 0
a b. a, b
10 - . .
11
3
S = t – t .
t. t . (
)
13
Z v1 v2 v3 3 , v1, v2, v3 – ’
R1, R2, R3 . ’ V = 4/3 R3.
14 = 10–6, L = 0,04 , U = 100 . I U C L , W LI 2 / 2
15 . .
16 W sh(x) tg(x 1) tg2 (2 sh(x 1)) , sh(x) ex ex 2 . x
17 , L = 0,5 ,
n = 2 W = 3 .
W1 W /(n2 1) I1 2W1 / L
18 , .
19 a, b, c, . (, a,
bc(a b c)(b c a) /(b c) )
20 a, b, c. (, a, 0,5 2b2 2c2 a2 . a, b, c
21 Z = (R1 + R2 + R3)/3, R1, R2, R3 – ’ V1, V2, V3 . R = 3 3V 4π .
’
22 a, b c . , . , a, 0,5 2b2 2c2 a 2
23 ( u /U ) ( t/T) n ?
n . u /U n /(n 1) ; t /T arccosn /(n 1) (2π)
24 ’ , b. V h(S1 S1S2 S2 ) 3 ; S1, S2 – , h – . a, b, h
25
= / 100 %, 2 %.
26
= 120( ln2λ/(πd )– 0,577), = (3 + 0,1 n). n d
27 R r n a.
R a /2sin(π / n), r a / tg(π / n) . n a
28 ’ , R r. V hS1 S1S2 S2 / 3; S1, S2 – , h – . R, r, h
29 (x, y).
( , ), x 2 y 2 , tg = y/x
30 S = t3 – 3t2 + 2. t. t .
( )
32
: - if ++.
1.
, . - .
- , . ++ : - – goto, – if – switch. - () .
2.
: true () false (-). ++ 1 0 (1 – , 0 – ). , , . bool, :
bool m;
(<, >, <=, >=, = = (), != ( )) -
1 (true – – “”) 0 (false – – “”). int ( bool).
– , , - 1 (true) 0 (false). .
:
|| – ( “”, ’), - 1 (true), . , ;
&& – ( “”, ’), 1, , – 0. 0, ;
! – ( “”, ) , true (1), - false (0), false (0) – true (1).
. if
33
?
,
, -
{}, -
.
else <2>;
, , 1
b x
if , if :
1) if(x == b) y = 1 + pow(b, x); if(x != b) y = (x + b)/(b –
x);
2) if(x == 0) y = 1 + pow(b, x); else y = (x + b)/(b – x);
++
1.
x2
8
int main ()
{
setlocale(0,".1251"); double y, x; int n; cout<<" =";
cin>>x;
if(x <= –4) { y=x*x–8; n=1;} else
34 3
if(–4<x && x<0){ y=3*x–2; n=2;} else { y=2–x;
n=3;}
}
=0.4 y=1.6 3
2.
:
#include <iostream> using namespace std; int main ()
{
bx
cout<<"i x= "; cin>>x;
z = pow(x + b, 2);
if (fabs(1-x*x) == a+z) y = pow(cos(a+x*z),3.5) + exp(fabs(b*x));
else
if (fabs(1-x*x) > a+z) y = z+log(fabs(a+b*x)); else y = sqrt(a *
pow(b,4) + pow(z*x*x,1./5));
cout<<"\n y = "<< y <<endl; system
("pause>>void");
return 0;
= 2.45 y = 1.77414
3. B ( x y) , -
ex x4
eps = 10–3 ( |f(x) – y| < eps). .
. if 35
:
{ double x, y, fx;
const double eps = 1e-3;
fx = -Math::Exp(x) + Math::Pow(x, 4); else
fx = Math::Pow(Math::Acos(Math::Pow(x,4)),2); if (Math::Abs(fx - y)
< eps)
MessageBox::Show(" f()"); else
MessageBox::Show(" f()");
}
4. , ’ , ’: - ( . 3 2).
’ 3 2 ’ . groupBox, radioButton. radioButton1 Checked True.
radioButton
“” , .
if-else.
:
{ double r1, r2, R;
else R = r1+r2;
2) ++ ?
3) .
4) (–3 >= 5) || (7 < 9) && (0 < 3).
5) w bool w=2*5<=17%3; .
) if(x>0)y=ln(x) else y=x;
8)
) float =1.5;
) float =1.5;
if(x<=0.5) =7.7;
9) z :
float z, x=2.5;
1) .
2) ++ if ’ , . 3.1 … 3.3 .
3) ’ Visual ++ . .
3.1
1
2
3
4
5
37
8
Y
Y
9
Y 2x
4x3 2x
Y
20
21
2(x 1)
28
Y
p ax b
39
13
y
2
2
2.5
ln
.
1
, :
.
2
, :
.
3
4
5
B(x y) :
f(x) = 6x7–4.5x5+4x2 eps = 10–3
( |f(x) – y| < eps)
6
(0, 0) (1, 1) –
– ((0,0)).
7
a, b c ,
.
8
, ’
9
(x y) :
.
10 x y , R. .
. if
41
11 ( ) ,
12 R , .
13 – a1,b1,c1 i a2,b2,c2. -, .
14 B (x y) :
f(x) = 6cos2x – 0.25x5 + 3.2x2 – 2.7 eps = 10–3 ( |f(x) – y| <
eps).
15 , ’ – 0
16 a, b, c. - . ,
17 (x y) , .
18 ,
19 .
20 Q(x y) , f(x) = 7tg2x – 0.31x3 + 3.2x2 – ex eps = 10–3 ( |f(x) –
y| < eps).
21
22 , : .
23 (0, 0) (1, 1) , – – (0,0).
24 (x y) , - , r R O(0,0)
25 B(x y) ,
sin2 x3
eps = 10–3 ( |f(x) – y| < eps).
26 (x y) , .
27 a, b c , .
28 a, b, c , (2 = 2 + b2).
29 (x y) , , = 2 – 2
30 A1(x1, y1), A2(x2, y2), A3(x3, y3) , .
42
: - switch goto, ?: ++.
1. goto
goto ( ) - - (), .
goto: goto <>;
, , - (:). ++ . - , , : start, 1, second.
, , - . ++ goto . , , .
2. ?:
<> ? < o1> : < o2>;
, o-1, – o2. , , .
:
j = (i<0) ? (–i) : (i);
j i, , i , j -i, , i , j i.
x y : max = (x > y) ? x : y;
(-1)i , ' , - : (i%2) ? –1 : 1
, - :
button1->Text = (button1->Text == "on") ? "off" : "on";
. switch 43
. , :
int k;
cout<<" i " << k << " '"
· ((!n || n>4) ? "i." : (n>1) ? "." : ".")<<endl;
3. switch
switch:
switch (<>)
…………………….
[ default: < >; ]
}
. . - case. - , , , break. , , default. default ' - switch, [] .
break switch. break - case, - break switch case .
switch , - .
#include <iostream> #include <locale.h> using namespace
std; int main()
{
44 4
cout << "i i i 1 7: "; cin >> n; switch (n)
{ case 1: s="i"; break;
case 2: s="i"; break;
case
3:
case
6:
break;
}
}
cout << endl << n << "- - " << s <<
endl; system("pause>>void");
return 0;
switch .
#include
<iostream>
using
f=true;
switch (op)
{ case '+' : res = a+b; break; case '-' : res = a-b; break; case
'*' : res = a*b; break; case '/' : res = a/b; break;
default: cout << "\n i !\n "; f=false;
}
return 0;
45
x2a 1
k 1;
x
switch (k)
{ case 1: { L = pow(x,2+a) + 1; break; } case 2: { L = (x+1)/a;
break; }
}
if(k <= 4) goto M1; system("pause>>void"); return 0;
}
, :
1) a = –3,7;
k = 3
47
system("chcp
cout<<" i i (i ) 1, 2 3: ";
cin>>n;
cin>>x;
switch (n)
case
3:
system("pause>>void");
return 0;
k=1;}
if (x>=a && x<b) {
y=pow(a+fabs(5.3*b),1.0/3)+c;
k=2;}
if (x>=b) { y=pow(cos(a+b),2)+sin(x*x); k=3;}
cout<<" y= "
system("pause>>void"); return 0;
:
a = 13.6;
b = 6.5;
c = –6.2.
’. ?:, – - listBox, Items . - ( SelectedIndex), 0.
48 4
k
1
2
int k = listBox1->SelectedIndex;
default: MessageBox::Show(" "); return;
}
}
?: max = (a>b && a>c)? a : (b>c)? b : c;
if-else, :
if(a>b && a>c) max=a; else if(b>c) max=b;
else max=c;
49
1) ++ ?
2) f :
int f = 1, n = 3, i = 2; M1: if (i > n) goto PP;
f = f * i; i++; goto M1;
AP: ;
) double y=0; int n=1;
) double y=0; int n=3;
switch (n)
switch (n)
{case 1:
switch (n)
switch (n)
{case 2:
case 9:
{ y=n;
}
}
switch (nom)
{ case 2 : y=d; break; case 8 : y=d*exp(x); break;
case 10 : y=d*x; break;
}
1) .
2) ++ switch ’- , . 4.1 … 4.3 .
3) ’ Visual ++ . .
50
51
2 x
2 a 0.2; b 0.8; z e
x
53
2 a 0.15; b 0.2; z e2ax ;
4
y
c 5.6;
c 2.6
z e x ;
z e
2 x
3.5
3
arctg kx rs
z e2ax ;
1 a 4.5; b 8.4;
z tgbx2 ;
2 a 8.2; b 15.2; z tgbx2 ;
tgax z sin
2
z e
z e
2
y
18
e
55
;
20
y
f e1.5ax ;
f e
2
x
z ln
bx3 1.5
z ln
bx
1.8
z ln
tgbx
z ln
tgbx
z ln
p 4;
p 4
bx
a x b;
bx
b
x
arctgkx tgrs
z tgbx;
arctga bx z
1
2
3
1
2
3
1
2
3
1
2
3
1
2
3
7
1 x0 = 2; y0 = 2; x1 = -4;
y1= 0;
2 x0 = 8; y0 = 9; x1 = 12;
y1= 1;
3 x0 = -3; y0 = 0.9; x1 = 2; y1=3
8
1
2
3
57
1
2
10
1
A3(x3, y3) – ,
y2 = 0; x3 = -2; y3 = 6;
11
1
2
3
1
1
,
2
3
1
15
1
2
1
2
3
17
– x, y, z –
1
x = -2;
y = 1.2;
z = 9.5;
,
2
– x, y z –
1
x = -7.2; y = 3.14; z =-2.5;
,
2
19
1
2
(0, 0) (1, 1) ,
1
2
((0,0))
21
1
2
3
– a, b, c –
1
3
23
1
2
1
R,
2
3
– a, b, c –
1
, 3
2
3
26
– a, b, c –
1
2
27
1
2
1
2
– a, b, c –
1
1 x = 0;
2 x = -2.43;
for
: - ++ for.
– for;
:
for (<>; <>; <>) < >;
, - (;), ( ), . (), . - , (true ), - ( {}) . - , , . (false ), - ,
, - for. , . , , - . () .
10
s = 0
i1
s = s + i
: “ -
s += i 10 ( 1 10 ,
1)”. -
: s=0 i=1, : (<=10) : ++. s += i.
60 5
· (s=0, i=1);
· (i<=10);
· (true), ( ) : , , ;
· 1.
2. 2 (false), .
, : - , ; – , , , break; – . , (;) -. ( ) . , - :
for(int s = 0, i = 1; i <= 10; s += i++);
, , “”, - s i.
for F = n! (, n! = 123...(n–2)(n–1)n, : 4! = 1234 = 24). for:
· int F=1, n=5; for(int i=1; i<=n; i++) F *= i;
· int F, i, n=5; for(F=1, i=1; i<=n; F *= i++);
· int F=1, i=1, n=5; for( ; i<=n; ) F *= i++;
- continue, :
for(i = 0; i < 20; i++)
{ if(a[i] == 0) continue; a[i] = 1/a[i]; }
break ( ), goto ( ) return ( ).
’ , - for. - (-), , .
. for
61
, for
1. . n , -
x
x3
x5
n
int i, n;
cout<<"i i n= ";
cin>> n;
{ u = pow(-1,i+1.0)*pow(x,i)/(2*(i+1));
S
( -
) y(x)
x3 cos2 x
2x
62 5
’. , :
– textBox ( ), ( ) ( h), . - textBox label;
– button, ;
– richTextBox -. Scrollbars () Both;
– Chart ( ) . , (Series) Spline.
, - Series, (Series1) ChartType Spline ( Column). – LegendText, : y
= f(x). (- Color), ( BorderDashStyle) .
, Series2, – z = f(x). ,
Series.
private:System::Void
button1_Click(System::Object^sender,System::EventArgs^e)
A,B,h
double x, y, z, A, B, h;
x
z 2sin3 2xln(0.5 x)
{ y=x*x*x*Math::Pow(Math::Cos(x),2)/Math::Pow(2,x);
z=2*Math::Pow(Math::Sin(2*x),3)*Math::Log(0.5+x);
x, y, z
richTextBox1->Text += "x = " + x.ToString("0.00")
63
2) ++?
3) , -
s:
4)
) int k, m=2, n=3;
) int n=–7, m=2;
for(k=1; k<=n; k++)n=n+m;
for(int k=n; k<=m; k--)k++;
5)
) int k, m=1;
) int m=1, n=5;
for(k=1; k<=5; k++)m++;
for(int k=n; k>=1; k--)m*=k;
1) .
2) ++ for ’ , . 5.1 (. - 1).
3) () y = f(x) z = f(x), x , . 5.2 - (. 2).
4) ’ Visual ++ . .
64 5
.
x2
x3
n
xi
1
...
...
2i 1
i1
3 n m (n < m), 4 n m
n ,
4
cos(2x)
cos(3x)
n
cos(ix)
n
5
n , s 1 a a2 a3 ... (a)i
i 0
s 1
i1 i
7 N, 1 N
m
8 n m (n < m), s i
i n
...
i 1
4) N, 3 1 N
x3
x5
n
11
...
12
n
i1
...
3i 1
i 1
· n m (n < m), n m
2
3
n
...
16
65
17
...
18
N, 1 N
19
20
N, 3 1 N
21
22
1
3
5
n
23
...
2
· N 10, 2 1 N
n ,
25
cos(2x)
cos(4x)
cos(6x)
n
cos(2ix)
s
...
2i 1
i 1
3. n ( 10) , 1 n
1
s
s
...
.
4
6
1/ex
7
e x sin
13
16
17
2,5sin(x/2)
x
2
sin x
26
27
30
cos(x)/x
, , . , , . ' ' ( ), - , .
.
1. . ’. :
1) x;
2) , : max = x;
3) . max , x max, ’
max:
#include <iostream> using namespace std; int main()
{ setlocale(0,".1251"); int i; double x, max;
cout << " 1- : "; cin >> x; max=x;
for (i=2; i<=6; i++)
{ cout << " "<< i <<" "; cin >> x;
if (x>max) max=x;
}
return 0;
:
1 : 5.5 2 : 0.2 3 : –7 4 : 3.1 5 : 15.2 6 : –1.4 : 15.2
2. 12 .
’. , 12 , :
– ;
– ;
– , , - .
-:
#include <iostream> using namespace std; int main()
{
//
cin >>
x;
// , .
}
return 0;
// .
69
. , 1. - , . - . 0, . , 0 ( -). , 1.
:
{
setlocale(0,".1251"); int i, x, p=1, k=0; for(i=1; i<=12;
i++)
{ cout << " " << i << " : ";
k++;
}
}
}
if(k > 0) // 0, cout << " : " << p << endl; //
,
else // – , . cout << " ." << endl;
system("pause>>void"); return 0;
:
1 : 3 2 : 1 3 : –7 4 : 5 5 : 3 6 : –7 7 : 3 8 : 7 9 : 11 10 : –17
11 : –5 12 : 3 .
70 6
3. ’- .
’. richTextBox1 - Windows Forms. - richTextBox1 ( –
Lines->Length).
:
private:System::Void button1_Click(System::Object^
}
}
4. (1, 2, 3, ...) min(|a2 – a1|, |a3 – a2|, …).
:
private:System::Void button1_Click(System::Object^
{
double min=1e3, x0, x=Convert::ToDouble(richTextBox1->Lines[0]);
for(int i=1; i<richTextBox1->Lines->Length; i++)
{ x0=x; x=Convert::ToDouble(richTextBox1->Lines[i]);
if (min>Math::Abs(x-x0)) min=Math::Abs(x-x0);
}
1) ++ - ’ , . 6.1 6.2 (. 1 … 4).
2) ’ Visual ++ . .
6.1
.
1 7 , 6
2 10
3 6 ’
4 5
5 8
6 9 , 5
7 11 ,
8 6 , [3, 6]
9 8
10 7 , 3
11 14
12 9
13 6
14 10 -, [10, 20]
15 8 , [5, 10]
16 7 ’
17 9 , 4
18 12 ’
19 8 ( )
20 6
21 11
72
22 9
23 14 , 3
24 7
25 6 ,
26 9
27 8
28 11 , 3
29 7 , 5
30 10
6.2
,
3
,
min(1+2, 2+3, ...)
min(1, 3, 5, ...) + max(2, 4, 6, ...)
7
max(|a1 – a2|, |a2 – a3|, …)
8
1*2 + 2*3+ ... + n-1*n
10
(a2 – a1)*(a3 – a2)* ... * (an – an-1)
11 ,
.
12 ,
13 ',
14
15 , 5 7
16
17 ’
18 , ,
19 ’,
20 ,
21
22 ,
23 ,
24
25 ’
26 , 10
27
28 2
29 ’
30
74
: - .
. , , . , . - . - :
for(k=1; k<=10; k++)
{ . . .
{ ...
}
}
}
7
,
i = 1, 2, …, 7.
’. s - , - (2i 1)!. -
u.
-:
#include <iostream> #include <math.h> using namespace
std; int main()
{
int i, k, f;
S
{ f = 1;
u = 2*pow(x,2*i-1)/(3*f);
s += u;
2. S
k
,
.
m
k
s = 0
(k 1 +1). -
i1 k 3
k
i≠2
p = 1
S,
k 1,i
p=p (k+3)/k
, , -
,
s=s+pi/(i – 2)
;
3: (k+3.0)/k.
s
cout<<"i m = "; cin>>m;
double S = 0, p;
{ p = 1;
p*=(k+3.)/k;
S += i/(i-2.) * p;
1) .
2)
) for(k=1;k<=10;k++) ) for(k=1;k<=10;k++)
) for(k=1;k<=10;k++)
3) s
) for(s=0,k=1; k<=3; k++) ) for(s=0,k=1; k<=2; k++)
for(j=1; j<=k; j++) s+=j; for(m=k; m<=2; m++) s+=m;
1) .
2) ++ ’ , . 7.1 … 7.2 - (. 1 … 2).
3) ’ Visual ++ . .
7.1
5
10
k
i 5
i j
i
7
k
while do-while
: - ++ while -
do-while.
- for. - , . - , - . -.
:
?
, -
.
,
.
: -
.
:
( ) -
, (false ). (-
), . do-while -
, -
, - .
, {} ’.
3)
80 8
while do-while - break, goto, return .
, -, , - .
- 10 100:
1) for
int i, s=0;
2) while
int s=0, i=11;
while (i<100) { s += i; i += 2; }
do-while
do { s += i; i += 2;} while (i<100);
,
(2k 1)!
, 104 .
. (–2 < x < 2) .
’. - for, - . - do-while, .
-:
#include <iostream> #include <math.h> using namespace
std; int main()
{
i = 1, 2k – 1
double x, f, u, s=0; int i, k=0;
cout << "i x= "; cin >> x;
cout << "\n:\n";
81
do
//
return 0;
1
, -
(k 3)(2k )!
k 1
, . . (– 2 < x < 2) 104 .
’. (–1)k+1 k = 1, 3, 5, … 1, - k = 2, 4, … – (–1). , , ’, – "+". -
’ .
, - , . - k.
u = x/8; s = u;
r = -x*x*(k+2)/((3+k)*(2*k) *(2*k-1));
u *= r ;
s += u;
82 8
(k
3)(2k )!
R
uk
(k – 1) k:
2k (k
3)(2k 1)
R, k = 1:
u
int k=0;
83
u *= r ;
return 0;
3: 0.248832
4: -0.0398131
5: 0.00351005
ii i = 6
, -
k = k + 1
a
: a) for; ) while; ) do-while
84 8
{
double S = 0, x = Convert::ToDouble(textBox1->Text); for (int
k=1; k<=5; k++)
S += Math::Pow(x,k+1)/(Math::Pow(2,k)+k); textBox2->Text =
S.ToString("0.0000");
}
{
while (k <= 5)
}
{
do {
}
85
4. . :
#include <iostream> int main()
unsigned int x, i;
if (x%i == 0)
// ,
#include <iostream> using namespace std; int main()
{ unsigned int N, kol;
cout << "N="; cin >> N;
for (kol=1; N/10>0; kol++,N/=10); cout << "kol=" <<
kol << endl; system("pause>>void");
return 0;
6. - .
:
{ unsigned int N, z, min, max; cout<<"N=";
cin>>N;
for (max=min=N%10; N>0; N/=10) { z=N%10;
if (z>max) max=z;
if (z<min) min=z;
}
return 0;
86 8
7. . – ( ), -
, , , - . , 404, 12521 – .
:
{
setlocale(0,".1251");
unsigned long long n,m,d; // int kol, i; bool Fl; cout<<"N=";
cin>>n;
d = 0; m = n; while ( m!=0)
{ d = d*10 + m%10; m /= 10;
}
if (d==n) cout<<", i"<<endl; else cout<<"i, i
"<<endl; system("pause>>void");
return 0;
2) , , ,
while: ) ; ) ;
) while.
3) n :
) int k=0, n=17; ) int m=1, n=1;
while(k<7){ k++; n--; } while(m<5){ m+=2; n=n*m; }
4) do-while?
5) y :
) int i=1, y=1; ) int k=1; float y=0;
do {y*=i++;} while(y<7); do{k+=2;y+=1./k;}while(k<5);
6) S i2 .
i 1
s=0.5; i=0; while(i<5) i++; s+=1.0/i;
while do-while
87
1) .
2) , ,
104 . -. (–2 < x < 2), . . 8.1 (. 1 … 2).
3) ++ f(x) - (. 3). f(x) . 8.2.
4) ++ ’ , . 8.3 (. 4 … 7).
5) ’ Visual ++ . .
8.1
k
1
6
k 2
22
25
1
2 , , 3406 3
3
4
5
6 , ,
1234, 4321
7 , 3
while do-while
89
.
8 1
9
10 10
11 3
12 -, , 1234 4231
13 , ,
· 1234 12341234
14
15 , , 1234
12341234
16
17
18 , 5
19 2
20
21 , 5 5
22 , 47 43, 43 47
23
24
25 , 7, 7
26 , 9 9
27 , 13
28
29 , , 1234 2134
30 , , 1234 11223344
90
: ++ .
, , , . , . , , , ’- . .
– , - , . ’, . - :
3) , -, : sin(), pow() ;
4) , .
. . - , () .
()
[] < > <’ > (< >);
,
float seredne (int a, int b);
seredne – ’ ;
a b – (), ;
float – , . return.
, . , , .
, ().
++
< > <’ > (< >)
{ < >
double seredne (int a, int b) { return (a+b)/2.0;
}
a b return.
seredne() :
int
a=5, x=2, y=-3; double z, s1, s2;
1) z = seredne(5, 4);
// s2
= –0.5
5 4 ,
a b:
double seredne(int a, int b)
z = seredne( 5,
4);
, – 11. – x y.
, , void ( , ). return - , . - Windows Forms, :
private: System::Void button1_Click(System::Object^ sender,
System::EventArgs^ e)
{
}
1) .
2) , , - , - .
3) , , .
4) , .
5) ’ -, , , :
float seredne(int, int);
92 9
6) , ( ) void:
double func(); double func(void);
7) , , -, . , :
int [10] func(); // !
8) ++ ’, - .
.
: -. ( ) - () - . - , , .
- , . ’ , "" - , . : (*) (&).
(), - . , , .
-, :
void f(int i, int* j, int& k)
{ i++; (*j)++; k++;
int main()
{ int i=1, j=2, k=3; cout << "i j k\n";
cout << i << ' ' << j <<' '<< k
<< '\n'; f(i, &j, k);
cout << i << ' ' << j << ' ' <<
k;
1 2 3
1 3 4
i , . j
++
, - &j, (-) *j. k -. k - .
, , , , "" (. 7).
, - ( ), ( ) . - - . .
6 6
2
2
2
’. ,
:
a a
2
6, – 13, – 21. , a, : 6, 13, 21.
:
#include <iostream> #include <math.h> using namespace
std;
double f (double a)
{ setlocale(0,".1251");
double x = f(6) + f(13) + f(21); cout<<" = "<< x
<< endl; system ("pause>>void");
return 0;
13
7
15
32
21
’. , .
:
include <iostream> #include <math.h> using namespace
std;
double f(double a, double b)
{ return (a+sqrt(b))/(b+sqrt(a));
setlocale(0,".1251");
double x = f(13,7) + f(15,12) + f(21,32); cout<<" = "<<
x << endl; system ("pause>>void");
return 0;
= 3.37
3. - () .
’. .
1. (. nsd1()) - . , , . .
2. - , . - : . , . - (. nsd2()).
3. , -
, - (. nsd3() while nsd4() – do-while).
4. (. nsd5()) -
, , () , .
++
95
, - .
:
#include <iostream>
{
n++;
return n;
{
return a;
{
else b %= a;
return a | b;
{ int n; do
{ n = a % b;
}
{
if(!b) return a; else return nsd5(b, a % b) ;
}
int x, y;
cin >> x
else
{ cout<<": "<< nsd1(x,y) <<endl; cout<<":
"<< nsd2(x,y) <<endl;
}
}
:
- x, y z , :
cout << ": " << nsd1(x, nsd1(z,y)) <<endl;
4. , - (, 1208 8021), "" .
:
#include <iostream> using namespace std; int reverse(int
n)
{ int a=0; do
n = n/10 ; } while(n);
return 0;
: 98041
5. , - , .
:
#include <iostream> using namespace std;
int first_last(int n)
{
{
}
return 0;
6. z 2 5! 3 8! .
6! 4!
’. . .
:
long long fact(int n)
{ long long c=1;
return c;
{ double z = (2.0*fact(5)+3*fact(8))/(fact(6)+fact(4));
textBox1->Text = Convert::ToString(z);
x b
eb0.1
’. , return, – . , : , z ( ) – y, z.
:
#include <iostream> #include <math.h> using namespace
std;
double f(double x, double b, double& a, double& z)
{
setlocale(0,".1251"); double x, b, a, z;
cout <<" i = "; cin >> x ; cout <<" i b= "; cin
>> b ; cout<<" y= "<< f(x,b,a,z)
<<endl;
cout<<" a= "<< a << endl <<" z= "<< z
<<endl; system ("pause>>void");
return 0;
1) return?
2) , ?
3) : int fun(double x)
4) ?
5) - ?
1) .
2) ++, ’ . , , ’, . - . 9.1 … 9.2.
3) ’ Visual ++ . .
9.1
2
m
n!
-
3 3 x y z
b
4 z min( a,2b) min( 2a b,b) ,
a, b c a
5 0.5 2b2 2c2 a2 . -
x x
.
7
sh(x) (ex ex ) / 2
sh(x) tg(x 1) ctg2 (2 sh(x 1))
b
8
y max( 2a b,2b a) max( a,b) ,
9
( )
10 ( )
11 ( pow)
12
(
13 pow)
14 y
15
16 z
3 7! 2 6!
, 4, 5 8 ,
17 n n!
6, 7 9
· 3 , n k, 1 n k,
18 n!k
19 4 a b c d
()
21
++
22 ()
23
24 ch(x) (ex ex ) / 2 ch(x) ctg2 (x 1) tg(0.5 ch(x 1)) -
25
x y
26 -
27 -
28 ( pow)
x cos y
()
30 ’
9.2
.
; b
x
; a b3 ln
x
; t 3 x a2
e
7
x
b
a
a c k 2 ; c arctg
x
k,
x
12
b, c
; a t 2b
x,
p
15
y lg a / lg b; a x2 b2 ; x eb n
n, b
y ln
x t
16
m
t b2
; t b2
k, m
; t p3 a3
22
x
y v3 cos 2 w; v cos 2 a; w
23
a
x
a
x lg
Math::bs()
Math::Pow(,y)
Math::Log(,N)
Math::Cosh()
Math::Sinh()
2 348, 60 864
* – int 4 2 .
105
++. : . . / [. . -, . . , . . , . . .] ; . . . .
– : , 2011. – 587 .
++. . : / [. . , . . , . . , . . .] ; . . . . – : , 2010. – 544
.
. ++. ; . . / . – . : "-", 2006. – 1104 .
. ++. : ; . / . – .: "", 2005. – 1104 .
. . MS Visual C++ 2010 .NET. - / . . – . : , 2012. – 320 .
. Visual C++ 2010: .; . . / . – . : ".. ", 2011. – 1216 .
. . Visual C++ / .. , .. ; . . .. . – . : -, 2007. – 528 .
8. Visual C++ .NET: C++ / [. ,
. , . .]. – . : , 2003. – 398 .
9. . . ++; . / . . , . . . – . : "-", 2008. – 1456 .
10. . . ++ : . . 4 / . ., . ., . . – . 2. – : , 2009. – 93 .
11. . : . . . / . . , . . , . . , . . . – . 1.
– : . . . , 2014. – 108 .
12. . : . - . . / . . , . . , . . , . . . – . 2. – : . . . , 2014.
– 130 .
13. . : . . . / . . , . . , . . , . . -. – . 3. – : . . . , 2015. –
80 .
14. . . Visual C++: . - " " / . ., . . – : . . . , 2015. – 44
.
106
6
13
2
23
24
3
32
36
42
switch 45
49
59
for 61
63
67
67
71
76
76
8
79
80
90
99
99
105
LOAD MORE