
Лабараторки_Плотников(теория_и_задания) / Лабораторная работа ППП 3
.pdf
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
2
,
.
.
1.
,
System.Console.Write()
System.Console.WriteLine(),
.
-
,
-
.
int
value:
int value = 250;
-
:
System.Console.WriteLine ("value =" + value);
: value = 250
value,
(
5):
System.Console.WriteLine("value = {0, 5}", value);
– 0,
value
System.Console.WriteLine(). -
,
-
.
5.
-
-
41

|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
.
,
.
-
:
int a = -12; int b = 20;
System.Console.WriteLine("a = {0, 4}, b = {1, 3}", a, b);
: a = -12, b = 20
.
,
double
myDouble: double myDouble = 1234.56789;
myDouble,
|
, |
|
|
: |
System.Console.WriteLine("myDouble = |
{0, |
10:f3}"; |
||
myDouble); |
|
|
|
|
f3 |
|
, |
|
|
|
( |
f) , |
|
|
|
. |
|
|
|
float decimal. |
: |
|
|
|
float myFloat = 1234.56789f; |
|
|
|
|
System.Console.Write("myFloat |
= |
{0, |
10:f3}", |
|
myFloat); |
|
|
|
|
decimal myDecimal = 1234.56789m; |
|
|
||
System.Console.Write("myDecimal |
= |
{0, |
10:f3}", |
|
myDecimal); |
|
|
|
|
42

|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
: myFloat = 1234.568; myDecimal 1234.568;
WriteLine Write
{n, w:
k} –
n
WriteLine,
-
– , w –
,
(
),
k –
.
-
.
2.1.
2.1
W
W:Fk
W:Ek
W
W
F, E (-
. 2.2) –
. |
w – |
, |
( |
), |
- |
43

|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
.
k –
-
:
,
(
F);
,
E
G).
:
2.2
|
|
|
|
C c |
. |
|
|
|
. |
|
. |
|
NumberFormatInfo |
|
|
|
|
|
|
D d |
( |
- |
|
|
|
) |
. |
|
|
|
|
E e |
|
|
- |
|
|
|
. |
|
|
|
6 |
|
|
|
|
F f |
|
|
|
|
|
|
|
G g |
( |
|
- |
|
, |
|
. |
|
|
) |
|
|
|
|
|
44

|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
N n
X x
P p
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
-
.
- – 2,
,
1.
. public static void Main()
{
int a = -14;
float c = -0.00151f; double i = 1234.56789; bool l=false;
string name="Petrov"; System.Console.WriteLine("name = {0, 6}, l = {1, 4}", name,l); System.Console.WriteLine("a ={0, 4}, c = {1,10:f5}, i = {1,20:e8}", a,c,i); System.Console.WriteLine(" "); System.Console.WriteLine(" Enter");
System.Console.ReadLine();
}
45

|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
2. |
|
|
. |
|
|
public static void Main() |
||
{ |
|
|
int a; |
// = |
-14; |
float c; |
// = |
-0.00151f; |
double i; |
// = |
1234.56789; |
bool l; |
// = |
false; |
string name; //="Petrov"; |
|
Console.WriteLine("Input |
"); |
name = Console.ReadLine(); |
|
Console.WriteLine("Input |
"); |
a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Input c");
c = Convert.ToSingle(Console.ReadLine());
Console.WriteLine("Input i");
i = Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Input l");
l = Convert.ToBoolean(Console.ReadLine());
46

|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
System.Console.WriteLine("
\n name = {0, 6}, l = {1, 4}",
name,l);
System.Console.WriteLine("a ={0, 4}, c = {1,10:f5}, i = {2,20:e8}", a,c,i); System.Console.WriteLine(" "); System.Console.WriteLine(" Enter");
System.Console.ReadLine();
}
#-
,
.
(stream)
– ,
.
-
(-
,
)
(
,
-
,
).
,
,
-
.
.
-
, |
. , |
-
47

|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
|
. |
|
|
|
, |
, |
|
|
|
, |
- |
|
|
. |
, |
|
int-, |
double-, short- |
- |
, |
|
|
- |
, |
|
, |
- |
|
. |
|
|
|
#- |
|
|
Stream |
System.IO. |
Stream |
- |
|
. |
|
- |
|
Stream ( |
, FileStream) " |
" |
|
StreamWriter |
StreamReader. |
|
|
|
|
- |
|
. |
|
|
|
StreamWriter |
|
|
|
. |
|
- |
. , |
, |
StreamWriter - |
|
|
: |
|
|
StreamWriter fileOut = new StreamWriter(new
FileStream("text.txt", FileMode.Create,
FileAccess.Write));
:
FileStream(string filename, FileMode mode, FileAccess how)
:
48

|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
1. filename
mode
,
;
2. how,
,
FileAccess:
FileAccess.Read - |
; |
FileAccess.Write - ; |
|
FileAccess.ReadWrite - |
, . |
: |
|
StreamWriter(string name), |
|
name |
. |
, |
- |
: |
|
StreamWriter fileOut = new |
|
StreamWriter("c:\temp\t.txt"); |
|
StreamWriter:
StreamWriter(string name, bool appendFlag), name
;
appendFlag true –
-
,
false –
-
.
:
StreamWriter fileOut=new StreamWriter("t.txt", true);
fileOut
WriteLine.
:
fileOut.WriteLine("test");
t.txt
test.
49

|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu-tra |
|
|
|
|
|
|
|
|
-X |
C |
ha |
n |
|
|
|
||
|
|
|
|
F |
|
|
|
|
g |
|
|||
|
|
|
D |
|
|
|
|
|
|
|
|||
|
|
P |
|
|
|
|
|
|
|
|
e |
|
|
|
|
|
|
|
|
|
buy |
NOW! |
|
||||
|
|
|
|
|
|
to |
|
|
|
|
|
||
|
|
Click |
|
|
|
|
|
|
|
||||
w |
|
|
|
|
|
|
|
m |
|||||
w |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
w |
|
|
|
|
|
|
|
|
|
o |
|
|
|
|
|
|
|
|
|
|
|
|
.c |
|
||
|
|
. |
|
|
|
|
|
|
|
k |
|
||
|
|
|
d |
|
|
|
|
|
|
c |
|
|
|
|
|
|
|
ocu -tra |
|
|
|
StreamReader
.
-
:
StreamReader(Stream stream),
stream
-
.
ArgumentException,
stream
.
,
StreamWriter
:
StreamReader fileIn = new StreamReader(new FileStream("text.txt", FileMode.Open, FileAccess.Read));
StreamWriter
StreamReader
,
-
:
StreamReader (string name);
name
.
-
:
StreamReader fileIn=new StreamReader ("z:\temp\t.txt");
C# Unicode.
,
,
,
,
,
,
StreamReader:
StreamReader fileIn=new StreamReader ("z:\temp\t.txt", Encoding.GetEncoding(1251));
Encoding.GetEncoding(1251)
,
Windows-1251 (
50