Вы находитесь на странице: 1из 73

.. , ..

- 2005

.., ..

:


:
,

:
, C+
+- .
,
, :

` C++-
,
:
(*):

,
:

C++ :


I:
.
.
if else .
switch . .
for . .
.
do while
.
while .
.

.
.
.
.
.
.
.
.
.
.
.
.
.
.

.
.
.
.

.
.
.
.
.
.
.
.
.
.
.

.
.
16
18
.
27
.
.
.
.
.

5
12

24
31
32
38
42
47

I I:
.
.
.
51

.
.
.


.
.
.
:
.
.
.
.
.
.
if else
.
.

.
.
.
55

.
.
.

56
switch .
.
.
.
.
while
.
.
.
do while
.
.
.
for .
.
.
58
.
.
.
.
.
59
.
.
.
.

51
52
52
55
55
.
57
57
57
58
60


.
.
.
.
.
.
.
.
.
.
.

.
.
.

.
.
C++ -
.
.

.
.

61
62
.
.
.
.
.
.
71

63
64
66
67
67
70

I:
,
,



.

C++-

,
`

;


.
_ _;


:

.
_ _ =
_;

()
, , ,
Gumar gumar
;

C++

cout

;
cout<<.1 << .2 << ;

,
. \n- , \-,
\t- , \\-
;


cin .
cin>>._1 >>._2 >>;


, ,

;

,
:


1. ,
.
) ,
;
) int x, y, z Artadryal ;
) ()
;
) x,
y, z ;
) x, y z
artadryal ;
) Artadryal@= Artadryal
;
) main ,
:
2. (1) `

() :
3. C + + -
xyz 3.3 x + 4 y
+ sin 2 4
8
8
x
) x + 8 , )
,
)
:
cos 2 + ctg
10 7 + lg 4
4. , d

) x, y, z ;
) (x1, y1) (x2, y2)
;
) a, b c :
5. x y :

6. x, y z
, x- y- , y- z-, z-
x- :
7. x y
:
8. ,
:
9. a, b c (float )
`
.
a =
b =
c =
10. h l (float )
,

:

(barcrutyun = , erkarutyun =), `
(cm):
11. ,
,
, , :
12. , 1- 4
,
():
.
)
;
)
;
) :

13. ,

,
:
14. :


(
):
ughghankjan makeresi hashvark .
Mutq areq tvjalner@ :
barcrutyun (sm) > 700
erkarutyun (sm) > 60
Uggankjan makeres@ : 42000 sm qar.
15. `
PI :

(
):
Glani cavali hashvark.
Mutq areq tvyalner@ :
Himqi sharavigh (sm) > 6
Barcrutyun (sm) > 15
Glani caval@ : 1695.60 qar. sm.
16.
: (

) :
Gnumneri arzheqi hashvark .
Tetri gin@ (dr.) > 70
Tetreri qanak@ > 8
Matiti gin@ (dr.) > 10.5
Matitneri qanak@ > 5
Gnumneri arzheq@ : 612.50 dr.

10

17. , m1 m2
F ,
r : m1, m2 r

:
18. ,

:


(
) :
Iraric aranqov bazhanvats
Mutq areq koghmeri erkarutyunner@ (sm) > 21 15
Mutq areq ankyun@ > 30
Erankjan makeres@ : 78.75 sm qar.
19. a, b, c : a, b, c
`
:
20.
:

(
):
Teghamasi dimadrutyan hashvark.
Elementner@ miacvats en zugaher.
Mutq areq tvjalner@ :
Arajin dimadrutyun (om) > 25
Erkrord dimadrutyun (om) > 10
Lriv dimadrutyun@ : 9.375 om.

11

21.


(
):
Teghamasi dimadrutyan hashvark.
Elementner@ miacvats en hajordabar.
Mutq areq tvjalner@ :
Arajin dimadrutyun (om) > 25
Erkrord dimadrutyun (om) > 10
Lriv dimadrutyun@ : 35.00 om.
22.
:

(

) :
Hosanqi uzhi hashvark.
Mutq areq tvyalner@ :
Larum (V) > 24
Dimadrutyun (om) > 1500
Hosanqi uzh@ : 0.016 A.
23.
: ( )
( )
:
(

) :
Ekamuti hashvark.
Mutq areq tvyalner@ :
Nerdrats dram@ (dr) > 25000
Tarekan tokosadruyq@ ( % ) > 20
Nerdrman zhamket@ (orer) - > 30
Ekamut@ : 411.0 dr

12

Dram@ zhamketi vergum : 25411.0 dr


24. , sizeof
,

:

if


.

if

;

if-
;

else-

if ,
else- ;


,
`
;

,
,
;

13

if

:

25. , :
,
( ),
: ,

, float, double
long double :
26. , `
, :

(
) :
Mutq areq tvyalner@ ev seghmeq < Enter >
> 25
25 tiv@ kent e.
27. , `
:
28. ,
: , ,
, ,
:
29. ,

`
:

14

30. ,
(a,b,x), ` a<x<b
:
31. :
,
( ),
:
32.


(
):
Teghamasi dimadrutyan hashvark.
Mutq areq tvjalner@ :
Arajin dimadrutyun (om) > 15
Erkrord dimadrutyun (om) > 27.3
Miacman tip@ ( 1- hajordabar, 2- zugaher ) > 2
Lriv dimadrutyun@ : 9.68 om.
33. :
,

, :
Qarakusi havasarman lucum.
Mutq areq tvyalner@ :
a = 12
b = 27
c = -10
Havasarman armatner@ :
x1 = -25.551
x2 = -28.449
34. ,
: 3% ,

15

50.000 ,
100.000 :

5%

35. ,

a1 x + b1 y = c1

a2 x + b2 y = c2

:
(
),
:
36. ,
,
, Chisht
e Sxal e :
37. , ,

:
. ( )-100:
38. ,

. Ashxatanqayin or , Shabat Kiraki .
39. x1, x2, x3, y1, y2, y3
,
(x1,y1), (x2,y2) (x3,y3)
:

16

40. a, b, c d :
, a, b
c, d
,

:
41. a, b, c, x y : ,
a, b, c x, y
:
,
:
42*. 8-
. `
( ),
( ): k, l,
m, n , 8-:
.
) , (k, l) (m, n)
;
) (k, l) : (m,
n) ;
) ) ` ;
) , (k, l)
(m, n) : , ,
(
):

switch


.

17

switch


case
switch
_

break
switch

_
case
, default
;

_

:

43. ,

,
:
44. , ,
:
.

18

Y c
d + (13m 1) + Y + + 2c + 777 mod 7
5

4 4

d- , m - ,
( -1, 2, ., -12 ), Y- , c :
,
: .
1-, 2-, . . . , 6-, 0-:
45. ,
` ,
, , :

, :
,
, `
:
46.
. 1 290 , 2
450 , 3 990 , 4 760 , 5
680 : ,
2
) ;
) :
switch
,

:

for

19

for ,

- (int)

:

47. ,
:

:
Qarakusineri aghyusak.
-------------------------------Tiv
Qarakusi
------------------------------1
1
2
4
3
9
4
16
.
.
10
100
----------------------------------

20

48. , n
:
:

(
):
Drakan tveri gumari hashvark.
Mutq areq gumarelineri qanak@ > 23
Arajin 23 drakan tveri gumar@ = 276
49. , 2` :
50. , n
:
:
51. ,
:
:
1
1
1
52. , 1+
+
+
+ .
2
3
4
n :
:
53.
: (n 1 n ):

:
Factoriali hashvark.
Mutq areq tiv@, vori factorial@ petq e hashvel > 7
7! = 5040
54. , y=-2.4x 2 +5x-3
[-2; 2]
0.5 :
:
------------------------------

21

x
|
y
_____________________
-2
|
-22.60
-1.5
|
-15.90
-1
|
-10.40
-0.5
|
-6.10
0
|
-3.00
0.5
|
-1.10
1
|
-0.40
1.5
|
-0.90
2
|
-2.60
------------------------------55. , 5

:
(

):
Mijin tvabanakani hashvark.
Mutq areqhertov 5 tiv ev seghmeq < Enter> :
> 5.4
> 7.8
> 3.0
> 1.5
> 2.3
Mijin tvabanakan@ = 4.00
56. ,

:

:
:
57*. x :

22

x 3 x 5 x 7 x 9 x 11 x 13
:
+

+
3!
5!
7!
9! 11! 13!

58. , 1- 10

10

,
:

:
* * * Patahakan tver * * *
5 6 1 5 7 9 4 1 2 3 Mijin tvabanakan@ = 4.3
59. , 1- 10

10

,
:
60. , 2-
10000
:
61. ,
:
`
:
:
8 2 = 16
8 3 = 24
8 4 = 32
..............
62. ,
`
:
:
1

23

10

1
2
3
4
5
6
7
8
9

1
2
3
4
5
6
7
8
9

2
4
6
8
10
12
14
16
18

3
6
9
12
15
18
21
24
27

4
8
12
16
20
24
28
32
36

5
10
15
20
25
30
35
40
45

6
12
18
24
30
36
42
48
54

7
14
21
28
35
42
49
56
63

8
16
24
32
40
48
56
64
72

9
18
27
36
45
54
63
72
81

10
20
30
40
50
60
70
80
90

63. , y = x +2 + x 1
[-4; 4]
0.5 :
64. , ( 1

1 1 1 1
+ + ... )
3 5 7 9

4

(

):
65. ,

:
:
Tvi dzevapoxum.
Mutq areq 0-255 tiruyti tiv ev seghmeq < Enter >
> 49
2-akan hamakargum : 00110001
66. ( )

:

24

:
,
,
500:
for ,
:

67*. x0 .

x
2

x2 +

x2 +
x2 +

8
x + ....
.
256
x2 + 2
x
2

do while


.

do while
;

do while
, while
;
25

while
;

do while

,
;

do while- ,

:

68. ,
:

(
):
Mijin tvabanakani hashvark.
Mutq areq tver@ kam 0 avartelu hamar.
> 27
> 58
> 19
>0
Murq e arvel tiv : 3
Tveri gumar@: 104
Mijin tvabanakan@: 34.67
69. ,

( ):
70. , ,
:

26

(
):
Mutq areq tiv@ ev seghmeq < Enter >
> 51
51-@ parz tiv che.
71. ,

(
):
72. , 1- 10
5
:
(

):
Gushakir tiv@
Meqenan mtapahel e 1-10 tiruyti tiv.
Gushakeq tiv@ 5 hnaravorutyunic.
Mutq areq tiv@ ev seghmeq < Enter >.
>5
Sxal e.
>7
Duq haxteciq! Shnorhavor!
73. a :
1
1 1
) 1 , 1 + , 1 + + ,
2
2 3
, a-;
) n- ,
1+

1
1
+ ... + > a :
2
n

74.

27

128

(2i)
i =1

100

;
2

i +1

i + 2 ;
i =2

1 ;

i!
i =2
10

75 . c, d (c < d,

> 0):

cos e

dx

.
b
h
a f ( x)dx I n 2 [ f (a) + 2 f (a + h) + 2 f (a + 2h) + .... + 2 f (b h) +
,
b a
:
h =
n

, I n
n=n0, 2n0, 4n0, 8n0 ,
n0

I 2n I n

<
3
I 2 n -:

while


.

while
;
28

while
, while
;

while
;

while
, ;

while- ,
,
:

76. , y=3x 2 -4x-7


[-5;5]
0.5 :
77. f=10!
(for, while, do/while):
78.
float :
79. ,
float ,
1.0 1.0
:
80. x 0 = 1 , x k =

2 x k21
,
5

29

k =1,2,3,...

x n ,
x n x n 1 <10 5 :
81. ,
:
82. ,
: -

(
1 1 1 1
1 + + ... )
3 5 7 9

-:
4
(
):
Mutq areq tvi voroshman
chshtutyun@ > 0.001
Nshvats chshtutyamb = 3.143589
Gumarvel en sharqi 502 andamner.
83. ,


: 1 20
: ,
5,
* * * **
*
*
*
*
*
*
* * * * *
84. n

30

(2k +1)
k =1

( 1) k
;
)
k =1 ( 2k +1) k
n
k!
:

*
1
) k =1 1 1
+ + ........ +
2 3
k +1
n

85. n
1 3 5
) ... ;
2 4 6
1 3 5
) ... :
1 2 3
86. ( > 0) :
, ,

-. ,

.

i
i =1

;
2

( 1) i
;
i!

i =1

4
i =0

1
;
+ 5 i +2

87.

.
) y = (2n-1)!! = 1.3.5.... . (2n-1), n>0;
) y = (2n)!! = 2.4. ... .(2n), n>0:
n-
:
88. , (lnx, ex)
: x-

31

(x>1)
:


89. , n
:
90. , 100
:
91. m n : n ,
m -:
92.
100

50

i + j
i =1 j =1

100 100

i =1 j =1

100

j i +1
;
i+j
1

2 j + i :
i =1 j =1

93. ,
,
.
) ;
) :

32

94*. x, y1, y2,., y25 :


yn ,
x :
95. a1, a2,, a30 : M-
, m-`
: (m, M)
,
an :
96. ,
0 - 100 20
:
97. ,

20
1
p =
:
2
i , j =1 i + j
98*. ,
,
: R
(R>0)
:

33

,

;


() :

`

:
0 (n-1),
n ;

,

:

99. ,

: (

) :
Minimal tarri pntrum.
Mi toghov mutq areq 5 tiv ev
Seghmeq < Enter >
> 20 11 0 -3 37
Minimal tarr@ = -3

34

100. ,

: (

):
Mi toghov mutq areq10 tiv ev seghmeq < Enter >
> 27 0 40 -3 11 0 -5 28 0 71
Massivi tarreri gumar@: 169
0-neri qanak@: 3
Mijin tvabanakan@ aranc 0-akan andamaneri: 24.14
101. ,
`
:

(
):
Mijini hashvark aranc min & max tarreri.
Mi toghov mutq areq 10 tiv ev seghmeq < Enter >
> 12 10 5 7 15 4 10 17 23 7
Minimal tarr@: 4
Maximal tarr@ : 23
Mijin@ aranc min & max tarreri: 10.36
102. , ,
:
:
103. , ,

:
104. , ,
:

35

105. , ,
:
106.
: 10- 100
: ,
,
,
: ,
:
:
107. ,

:
108*. , ()

:
109*. ,
:
110. ,

:
111. ,

:
112. ,

:
113. ,
, :

36

114. 12 : 0-

:
115. (7 7) ,
: ,

:
116. ,
(9 9)
:

117. , A

37

0 0 0.

0 1 0.

) 0 0 2 .

. . .
0 0 0.

0
0

. 9

.
.
.

1 2 3.

0 1 2.

) 0 0 1.

. . .
0 0 0.

1 0

9
8

. 1

.
.
.

1 2 3. . 1 0

1 1 1 2 1 3. . 2 0
2 1 2 2 2 3. . 3 0

. . .

9 1 9 2 9 3. . 1 0 0

118 . , ,
, :
,
,

: `

38

1
3
2
3
1
6

8
1
1
1
0
5

1
2
7
6
9

1
1
4
1
5
4

119*. [1, 9]
9 :

, 0-,

1-,
:
120*. A- (n n) , x- (1 n)
,
: , .
) A x-;
) A
x-;
) A 6 x-:
A, x :
121. , A B (n n)
[1, 10]
, C

) C = A + B;
) C = A.B;
T
*) C =A T (. aik = a ki )

39

122. , (7 7)
900-
:
123. ,
`
:
124. ,
i :
125. ,

:
126. ,
:
127. ,

:

`
;

C++- ;
40


, 0,
' \0 ' :

128. ,
:

(
):
Inchpes e Dzer anun@ ?
Mutq areq Dzer anun-azganun@ ev seghmeq < Enter >
> Aram Asatryan
Barev, Aram Asatryan.
129. ,
:
130. ,
.
- :
131. ,
: ,
, , :

(
):
Mutq areq simvol@ ev seghmeq <Enter>
Avartelu hamar mutq areq ket
>1

41

Simvol:1 Kod:49
>w
Simvol:w Kod:119
> #
Simvol:# Kod:35
>.
132. ,
().
133. ,
(0-127
):
:
0-15 ,
` 16 - 31 :
134. , ,

() : , 42239 ,
.
4 2 2 3 9
135. , ,
:
136. ,

:
137. , h
k
(, k=130985,
h=9):

42

138. , h
l
(, l=32.597, h=5):
139. , h
k :
140*. , N 0 O1 N 1O2 ... Ok N k
, N i ,
Oi (+) (-)
:

(
):
Mutq areq tvabanakan artahaytutyun,
orinak, 3+2-1-4+9 ev seghmeq <Enter>
> 8-4+7-6+2
Mutq arvats artahaytutyan arzheq@: 7
141*. ,
: : :
, ` :
,
,
: , 281 ,
187 , (8
1) (8-) :

(
):
Mtapahvats e eranish tiv. Duq petq e gushakeq.
Amen tvits heto haghordvum e, te qani nish e
gushakvats ev qanisn en irenc teghum.
Tiv@ mutq aneluc heto seghmeq <Enter>.
Avartelu hamar seghmeq <Esc>.

43

Dzer tarberak@

>
>
>
>
>

123 Gushakvats e:0


456
:1
654
:2
657
:2
658
:3
* * * Duq gushakeciq ! * * *

Irenc teghum en: 0


:0
:2
:2
:3


: , ,
,
;


( )

;

,

:

142. , :

44

143. ,
:
144. ,

:
145. , (x1,y1)
(x2,y2) :
float :
146.


( ):

( 0- , 1). ,
-1:
147. Tokos ,
:
148. Faktorial ,

:
149. , e
`
1
1
1
1
e =1 + + + + ...
1! 2! 3! 4!
150. e x -

45

ex =1 +

x x2 x3 x4
+
+
+
+ ...
1! 2!
3!
4!

151. Ogut ,
:

,
( )
( ):
152. ,

:
153. void ,

:
154.
,
:

: 2- , 1 , 0- :

. ,
-1:
155. ,

(
)

:
156. ,

46

157. ,
:
158.
0, 1, 1, 2, 3, 5, 8, 13, 21, ..
0 1- ,

: ,
n-
` Fibonacci
:
159. ,
:
160. ,
,
1000-:
161*. , 21 :

:
162*. , , ,
.
, 7821 , 1287 :
163*. , , ,
. , 7821
1287 : 1,
0
164. x y
() ,
:
amb , x y
:

47

. y=0, amb(x,y) x,
amb(x,y) amb(y,x%y),
%- :
165. , max
( )
:
,
:
166. swap ,
:
167. , min

:
,
:
*

168 .
, ,
:
. ,

, ,
, :
(
,
):
*

169 .
:
:
170. ,
:

48


:
171*. ,
a[n][m][k] ,

:
:

a[0][0][0]
:

, ifstream
ofstream ;



,

: cin
cout
ifstream
ofstream ,
;

49


close() :

ofstream -

, ,

:

172. n- : g ()
b1 , b2 ,..., bn ,
.
) bn = n ;

2
) bn = n ;

) bn = n! ;

n +1
) bn = 2 :

173. f , :
.
) f ;
)f ;
) f ;
) :
174. f , : .
) ;
) ;
)

;
) ;

50

)
:

175. f1 f2 :
f1
f2 , f2- ` f1 :
h :
176. f : g
f- , h-`
:
:
177. f g : h
f , g
` :
178. f : g f
:
179. f , :
g , f
:
180. f :
e, n d ( ,
g ):
181. f g :
` f g-
: ,
, :
182. f g : h
f- g- :

51

183*. f : ,
( )
,
:
: g :
184*.
, : f
,
: .
)
;
) :
185. f ,
.

,
-
: ,

- :
186*. ,

`
,

:
: srand
,
:

52

II:

#include < _>
main()
{
1;
2;

.
return 0;

// ,
/ /

bool

()
1

unsigned short int

0 65 535

short int

-32 768 32 767

unsigned long int

0 4 294 967 295

long int

-2 147 483 648 2 147 483 647

int (16 )

-32 768 32 767

int (32 )

-2 147 483 648 2 147 483 647

unsigned int (16 )

0 65 535

unsigned int (32 )

0 4 294 967 295

char

256

float

1.2e-38 3.4e38

double

2.2e-308 1.8e308

true false

53

.
_ _;
.
const _ _ =
;
.
_ = ;
cin .
cin >> _1 >>
_2 >> ;

cout .
cout<<1 << 2 << ;

\n
\t

54

\r

:
,

\\

:

:

() :
<iomanip.h>
:


setprecision(n)

n (
): n
,
, 6:
,
: cout -
:
.

cout<< setprecision(4) << y;


setw(n) ,
n (),
, n

:
n ,

55

:
n,

:
.

cout <<

setw(15) <<

y;

setiosflags

:
setiosflags

( | ):
.

cout << setprecision(2)<<


setiosflags(ios::fixed|ios::showpoint)<< y;
ios::fixed
, ,
(
ios::scientific):
ios::showpoint


,
, , 88.00:
ios::showpoint 88
, ,
:
,
,
: , 87.945
67.543 , , 87.95 67.54
:

56

if else
if ( )
1;
else
2;
.

if (x < y)
else

z = x;
z = y;


C++

.
.

C++

+
*

f+7
p-
bm

/ y

mod s

%s

f+7
p-
b*m

: int = 3, d = 5, = 4, f = 6, g = 12;

+=
-=
*=
/=

+=
-=
*=
/=

7
4
5
3

=
=
=
=

57

+ 7
- 4
* 5
/ 3

=
=
=
=

10
1
20
2

%=

g %= 9 g = g % 9
g=3


-
++
1- -


,

++

-- b

b --


-
,
-

1-
b-
1- b-


,


b-
,
b -

1-

58

switch
switch (_) {
case __1 :
1; break;
case __2 :
2; break;
case __3 :
3; break;

default:
//
//
4; break;
}
while
while (__)
;
.

while (p <= 100)


p++;
do while
do

}
while(__);

59

do {
p++ }
while (p <= 100);

for

for .

for (._1; ._2; ._3)


;
._1
, ._2

._3

for ( i = 1; i <= 10; i++)


cout << i << endl;

C++- -

C++
C++ -
-

==
!=

>

>

==
!=

>
60

<

<
>=

<
>=

<=

<=


(&&)

._1

._2

._1 && ._2

(||)

._1

._2

._1 || ._2

( ! )

61


()

, ,
,
:

:
.
__ _

(_);

.
__ _

(_)
{
;

return ;
}
_
() :
__

: void
,

62

:
int :
_
,
:
, _
void:
:

:
: ,
:
,
:

:
,

,

return;

:
,

return ;



<math.h> :

Sqrt(x)

63


( )
(10 )
-
-
,

floor(x)
- ,

Pow{x, y)
fmod(x, y) / ,
sin(x)
( )
cos(x)
( )
tan(x)
( )

()
log(x)
log10(x)
Fabs(x)
cell(x)



rand() , <stdlib.h>
.
_ = rand();
rand()
0- RAND_MAX (
, <stdlib.h>
): RAND_MAX
32767`
( 16) : rand
:
rand

, ,

: ,

64

:
srand
: srand
unsigned

, rand

:


, .

srand(time(NULL));

()
: time NULL



: time
<time.h> :


:
:

, ,
:
12
` .
int [12] ;

65

b 100
27 .
int b[100], x[27];
(,
) : ,

char :

:

:
,
() () :

: , 64 m
.

int m[8][8];

m[4][3]
:


:
: .
char string1[ ] = "first";
string1
"first"
: string1

66

: , "first"

, :
, string1
:

'\0'
:
: ,
,
,
:

`

:
,

.
char stringl[]={'f', 'i', 'r', 's' ,'t' ,
'\0'}:
,

,
: , string1[0] - 'f ' ,
string1[3]-` 's' :

`
cin >> : .

char string2[20];
,
19
:

cin >> string2;


string2 :

cout << :
string2 .

67

cout << string2 << endl;




<string.h> :
strcpy(sl, s2)

strncpy (sl , s2, n)

strcat(sl, s2)

strcat(sl, s2, n)

strcmp(sl, s2)

strncmp(sl, s2,n)

strlen(s)

s2 s1
: s1-
:
s2 n
s1 :
s1- :
s1 s2 : s2
s1
:
s1- :
s1 s2 n
: s2
s1
: s1-
:
s1 s2 :
0, ,
, , s1 , ,
, s2-:
s1 n
s2 :
0, ,
, , s1 , ,
, s2-:
s :
,

:

68

()
[]
++ -- ! ()
*
/
%
+
<<
>>
< <=
>
>=
==
!=
&&
||
?:
= += -= *= /= %=
,

()



myfile.cpp
<fstream.h>
ofstream ,
fout
.

ofstream fout ("myfile.cpp");



.
ifstream
, fin .

ifstream fin("myfile.cpp");
fin
fout :
close() ,

69


:
1:

#include <fstream.h>
int main()
{
char fileName[80];
cout << "File name: ";
cin >> fileName;
ofstream fout(fileName);

//

//
fout << "\nFirst line written to the file..." << endl;
fout << "Second line written to the file..." << endl;
fout.close();
//
ifstream fin (fileName);
//

//
cout << "Here's the contents of the file:\n";
char ch;
while (fin.get(ch))
cout << ch;
cout << "\nEnd of file contents\n";
fin.close();
//
return 0;
}
2:

#include <iostream.h>
#include <fstream.h>
main() {
const int n = 10 ;
float a [n], b [n] ;
70

int i ;
for ( i = 0; i < n; i ++) {
a [i] = 1./ (i+1) ;
cout << a [i] << \n;
}
ofstream fileout ( test .txt) ;
for ( i = 0; i < n; i ++)
fileout << a [i] << ;
fileout . close ( ) ;
ifstream filein ( test .txt) ;
for ( i = 0; i < n; i ++)
filein >> b [i] ;
filein . close ( ) ;
cout << \n \n \n ;
for ( i = 0; i < n; i ++) {
cout << b [i] << \n;
return 0;
}

ofstream -
,
,

:

. `
ofstream myfile(FileName,ios::app);

.
ios::app

;

71

ios::ate

,
;
ios::trunc ; ( )
;
ios::nocreate ,
;
ios::noreplace
, ;


. append (), ate at
end (), trunc truncate ( ) :

C\C++ -
C\C++ -
C++
auto
break
default
do
float
for
register
return
struct
switch
volatile
while
C++
Asm
catch
New
operator
This
throw

case
double
goto
short
typedef

char
else
if
signed
union

const
enum
int
sizeof
unsigned

continue
extern
long
static
void

class
private
try

delete
protected
virtual

friend
public

inline
template

72


1. .., ..
++. .: . , 2000.
2. . ++. ,
-, , 2003.
3. . ++ 21
. .: . , 2000.
4. .., .., ..
++. , . ,
2002.
5. .. ++. .: .
, 2004.
6. . /++ . , . -, 2003.
7. ..
. .:, 1989.
8. .., ..,. .,
.. .
.:, 1989.
9. . Turbo Pascal .
-, . -, 2002.

73

Вам также может понравиться