-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.cpp
59 lines (54 loc) · 1.08 KB
/
file.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include <fstream>
#include "file.h"
#include "geometry.h"
using namespace std;
int countPoints(const char* fileName)
{
ifstream in(fileName);
if (!in.is_open())
return -1;
double x, y;
int i;
for (i = 0; ; i++)
{
in >> x >> y;
if (in.fail())
break;
}
return i;
}
istream& operator >>(istream& in, Point& p)
{
in >> p.x >> p.y;
return in;
}
ostream& operator <<(ostream& out, const Triangle& tr)
{
for (int i = 0; i < 3; i++)
out << tr.vertexes[i].x << ' ' << tr.vertexes[i].y << ' ';
out << "P = " << tr.perimetr << ' ' << "S = " << tr.area << ' ';
return out;
}
bool readPoints(const char* fileName, Point* pointArray, int maxPointNum)
{
ifstream in(fileName);
if (!in.is_open())
return 0;
for (int i = 0; i < maxPointNum; i++)
{
in >> pointArray[i];
if (in.fail())
return false;
}
return true;
}
bool writeTriangles(const char* fileName, const Triangle* trArray, int trNum)
{
ofstream out(fileName);
if (!out.is_open())
return false;
for (int i = 0; i < trNum; i++)
out << "#" << i + 1 << ": " << trArray[i] << endl;
return true;
}