Examination_IT / Programming bases on With C++
.pdf241
=
;@:
1)r ofstream, ifstream
fstream (Z ,
(r) );
2)=, ; = ; open, -
d =;
3)= @ ; = write read;
4)= @ ; = close.
10.1. I 8.4012 A B?2
D =
d – = -
. ?, =-
=
, ,
. ? =-
-
;@ ,
, @,
, =. . -
, = ,
;. B, =
,
@ = d : -
, ; . : Z = ,
, . B
=.
? =, @ d -, , , - -
243
4 |
1 |
3 |
4 |
3 |
6 |
|
|
49 |
51 |
52 |
51 |
54 |
|
ANSI |
||||||
|
|
|
|
|
||
|
00110001 |
00110011 |
00110100 |
00110011 |
00110110 |
|
ANSI |
|
|
|
|
|
3 , :
0011010001111011 |
(1) |
|
; =, -
- ;@ ;
(=):
0011000100110011001101000011001100110110 (2)
~ (1) 2 , - = (2) 5 ,
13436. ~@ =-
@ , -
= ;. : Z
, =
=, ,
. ? = -
. . = ( . 10.1)
, . 5 .
|
245 |
#include <iostream> |
// AQRQPQ<DK <<Q^-<D<Q^. |
#include <locale.h> |
// ^=; setlocale. |
#include <iomanip> |
// <P=mJ>?@> CH?@Ab=;RQBQ<. |
#include <fstream> |
// ^=; ofstream. |
using namespace std; |
|
////////////////////////////////////////////////////////
// t=H<?H; ab?Pc@;. void main()
{
setlocale(LC_CTYPE, "Russian_Russia.1251"); const double PI = 3.1415926535897932;
char text1[] = "•>=D> J@F=H:"; |
// A>B<DK |
|
|
|
// IHdQ=Q<QP. |
char text2[] = "‚>{>FR<>??D> J@F=H:"; // <RQBQK |
||
const int iN = 5; |
|
// IHdQ=Q<QP. |
// PQ=@J>FR<Q c>=DE J@F>=. |
||
int iNumber[iN] = {3, -998, 73, 456, 56}; |
||
const int fN = 4; |
// PQ=@J>FR<Q <>{>FR<>??DE |
|
|
// J@F>=. |
|
double fNumber[fN] = {PI/3.0, PI*345.0, -1.0*PI/56777.0, -1.0*PI*0.567};
char NameFile[] = "TestFile.txt"; // @C; aHK=H.
ofstream file; // FQI^H>C Q9:>PR R@AH aHK=. // 8RPBD<H>C aHK= F @C>?>C NameFile.
file.open(NameFile); |
// QRPBD<H>C aHK=. |
if(!file.is_open()) |
// >F=@ Qw@9PH. |
{ |
|
cout << "8w@9PH QRPBDR@; aHK=H \"" << NameFile; cout << "\"" << endl;
cout << "GBQdBHCCH BH9QRb IHPQ?J@=H." << endl; system("pause");
return;
}
// G@w>C @?aQBCHc@m < aHK=.
file << text1 << endl; |
// A>B<DK IHdQ=Q<QP. |
file << iN << endl; |
// A@w>C PQ=@J>FR<Q c>=DE |
|
// J@F>=. |
for(int i=0; i<iN; i++)
file << setw(5) << iNumber[i]; file << endl;
|
246 |
file << text2 << endl; |
// <RQBQK IHdQ=Q<QP. |
file << fN << endl; |
// A@w>C PQ=@J>FR<Q |
|
// <>{>FR<>??DE J@F>=. |
for(int i=0; i<fN; i++)
file << setprecision(8) << scientific << fNumber[i] << endl;
file.close(); // IHPBD<H>C aHK=.
cout << "~H??D> IHA@FH?D < R>PFRQ<DK aHK=: " << NameFile;
cout << endl;
// †^>C ?HkHR@; =m9QK P=H<@w@ P=H<@HRbBD. system("pause");
}
D. 10.2. e TestFile.txt, -
Ex10_01
.
X ;
t = . ?
= ;
Ex10_01 = ( 10.1) ; = ;
247
. 3 10.2,
… – . 10.3.
?
= . 3 Z -
, Z d =,
-
,
, = -
. . , d ,
=, Z d, -
,
.
:@… . ,
= ; getline. 5
,
. ?
= Ex10_01\TestFile.txt ( -
10.2) Ex10_02. 5
=.
8 58 9 10.2. !6:; Ex10_02.cpp
#include "stdafx.h" |
// AQRQPQ<DK <<Q^-<D<Q^. |
#include <iostream> |
|
#include <locale.h> |
// ^=; setlocale. |
#include <iomanip> |
// <P=mJ>?@> CH?@Ab=;RQBQ<. |
#include <fstream> |
// ^=; ifstream. |
#define LIMTEXT 255 |
|
using namespace std; |
|
////////////////////////////////////////////////////////
// t=H<?H; ab?Pc@;. void main()
{
setlocale(LC_CTYPE, "Russian_Russia.1251"); char buffer[LIMTEXT];
int Len;
char *text1; // A>B<DK IHdQ=Q<QP. char *text2; // <RQBQK IHdQ=Q<QP.
int iN; // PQ=@J>FR<Q c>=DE J@F>=.