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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#include <fstream>
#include <string>
#include <iomanip>
#include <stdlib.h>
using namespace std;
void read(static ifstream &, string &, float[], float[]);
float calculate(float[], float[]);
void write(static ofstream &, string, float);
int main()
{
ifstream input;
input.open("pilot_routes.txt");
ofstream output;
output.open("pilot_areas.txt");
string name;
float area;
float numbers_x[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
float numbers_y[15] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
while (input)
{
read(input, name, numbers_x, numbers_y);
area = calculate(numbers_x, numbers_y);
write(output, name, area);
}
output.close();
return 0;
}
void read(static ifstream & input, string & pilot, float x[], float y[])
{
int i;
char comma;
input >> pilot;
for (i = 0; i < 15; i++)
{
input >> x[i];
input >> comma;
input >> y[i];
}
}
float calculate(float x[], float y[])
{
float size, result, num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, num11, num12, num13, num14;
int i;
for (i = 0; i < 14; i++)
{
result = (x[i] * y[i + 1]) - (y[i] * x[i + 1]);
if (i == 0)
num1 = result;
else if (i == 1)
num2 = result;
else if (i == 2)
num3 = result;
else if (i == 3)
num4 = result;
else if (i == 4)
num5 = result;
else if (i == 5)
num6 = result;
else if (i == 6)
num7 = result;
else if (i == 7)
num8 = result;
else if (i == 8)
num9 = result;
else if (i == 9)
num10 = result;
else if (i == 10)
num11 = result;
else if (i == 11)
num12 = result;
else if (i == 12)
num13 = result;
else
num14 = result;
}
result = (num1 + num2 + num3 + num4 + num5 + num6 + num7 + num8 + num9 + num10 + num11 + num12 + num13 + num14) / 2;
if (result >= 0)
size = result;
else
size = result * -1;
return size;
}
void write(static ofstream & output, string fighter, float patrol_area)
{
output << fighter << "\t" << setprecision(2) << showpoint << fixed << patrol_area << endl;
}
|