-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfms.c
More file actions
168 lines (154 loc) · 5.87 KB
/
Copy pathfms.c
File metadata and controls
168 lines (154 loc) · 5.87 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include "fms.h"
#define M_PI 3.14159265358979323846
void Generate_Time_Table(FMS *pFMS);
void Main_Print(char* var_string, int spaces, int bar);
void Time_Print(Time Deptime, Time Arrtime);
void Generate_Duration_Table(FMS *pFMS);
int TimeCalc(Time Departure, Time Arrival);
void Generate_Distance_Table(FMS *pFMS);
double DistanceCalc(Airport *Departure, Airport *Arrival);
double calculateDegree(double D, double M, double S);
double sinDeg();
double cosDeg();
void Generate_Time_Table(FMS *pFMS){
printf(" Airline|Flight No.|from| to|Departure| Arrival|Airplane\n");
printf("----------|----------|----|----|---------|--------|--------\n");
for (int Line_Count = 0; Line_Count < pFMS -> cntAirline; Line_Count++)
{
Airline *airline = &pFMS->pAirline[Line_Count];
Airplane *airplane = airline -> pAirplane;
for (int Path_Count = 0; Path_Count < airplane -> cntFlightPath; Path_Count++)
{
FlightPath *flightpath = &airplane ->pFlightPath[Path_Count];
Main_Print(airline -> AirlineName, 10,1);
Main_Print(flightpath -> pathName, 10,1);
Main_Print(flightpath -> pDepAirport ->iata,4,1);
Main_Print(flightpath -> pArrAirport ->iata,4,1);
Time_Print(flightpath -> DepTime, flightpath ->ArrTime);
Main_Print(airplane ->AirVehReg, 8,0);
printf("\n");
};
}
};
void Main_Print(char* var_string, int spaces, int bar)
{
int length = 0;
char* temp = var_string;
while (*var_string != '\0'){
length++;
var_string++;
}
int align = spaces - length;
for (int count = 0; count < align; count++){
printf(" ");
}
printf("%s", temp);
if (bar == 1)
{printf("|");}
}
void Time_Print(Time Deptime, Time Arrtime){
printf(" %02u:%02u| %02u:%02u|",
*Deptime.Hours, *Deptime.Minutes,
*Arrtime.Hours, *Arrtime.Minutes);
}
void Generate_Distance_Table(FMS *pFMS){
for (int Line_Count = 0; Line_Count < pFMS -> cntAirline; Line_Count++)
{
Airline *airline = &pFMS->pAirline[Line_Count];
Airplane *airplane = airline -> pAirplane;
double total = 0;
printf("\n Airline|Flight No.|from| to|Distance\n");
printf("----------|----------|----|----|--------\n");
for (int Path_Count = 0; Path_Count < airplane -> cntFlightPath; Path_Count++)
{
FlightPath *flightpath = &airplane ->pFlightPath[Path_Count];
Main_Print(airline -> AirlineName, 10,1);
Main_Print(flightpath -> pathName, 10,1);
Main_Print(flightpath -> pDepAirport ->iata,4,1);
Main_Print(flightpath -> pArrAirport ->iata,4,1);
double distance = 0;
distance = DistanceCalc(flightpath ->pDepAirport, flightpath -> pArrAirport);
printf(" %.2f", distance);
printf("\n");
total += distance;
}
printf("\nTotal flight distance for %s %s is %.2f\n", airline->AirlineName, airplane -> AirplaneName, total);
}
}
double DistanceCalc(Airport *Departure, Airport *Arrival){
double deplat = calculateDegree(
Departure ->pCoordLat.CoordDeg,
Departure ->pCoordLat.CoordMin,
Departure ->pCoordLat.CoordSec
);
double deplon = calculateDegree(
Departure ->pCoordLon.CoordDeg,
Departure ->pCoordLon.CoordMin,
Departure ->pCoordLon.CoordSec
);
double arrlat = calculateDegree(
Arrival ->pCoordLat.CoordDeg,
Arrival ->pCoordLat.CoordMin,
Arrival ->pCoordLat.CoordSec
);
double arrlon = calculateDegree(
Arrival ->pCoordLon.CoordDeg,
Arrival ->pCoordLon.CoordMin,
Arrival ->pCoordLon.CoordSec
);
double dist = r * acos(sinDeg(arrlat) * sinDeg(deplat) +
cosDeg(arrlat) * cosDeg(deplat) * cosDeg(arrlon - deplon));
return dist;
}
double calculateDegree(double D, double M, double S){
double combined = D + (M / 60.0) + (S / 3600.0);
return combined;
}
double sinDeg(double deg) {
return sin(deg * M_PI / 180.0);
}
double cosDeg(double deg) {
return cos(deg * M_PI / 180.0);
}
void Generate_Duration_Table(FMS *pFMS){
for (int Line_Count = 0; Line_Count < pFMS -> cntAirline; Line_Count++)
{
Airline *airline = &pFMS->pAirline[Line_Count];
Airplane *airplane = airline -> pAirplane;
int Duration = 0;
printf("\n Airline|Flight No.|from| to|Duration\n");
printf("----------|----------|----|----|--------\n");
for (int Path_Count = 0; Path_Count < airplane -> cntFlightPath; Path_Count++)
{
FlightPath *flightpath = &airplane ->pFlightPath[Path_Count];
Main_Print(airline -> AirlineName, 10,1);
Main_Print(flightpath -> pathName, 10,1);
Main_Print(flightpath -> pDepAirport ->iata,4,1);
Main_Print(flightpath -> pArrAirport ->iata,4,1);
int DurationLocal = TimeCalc(flightpath ->DepTime, flightpath ->ArrTime);
printf("\n");
Duration += DurationLocal;
}
printf("\nTotal flight Time for %s %s is ", airline -> AirlineName, airplane -> AirplaneName);
int TotalHours = Duration / 60;
int TotalMin = Duration % 60;
printf("%02d:%02d\n", TotalHours, TotalMin);
}
}
int TimeCalc(Time Departure, Time Arrival){
int DepHours = *Departure.Hours;
int DepMin = *Departure.Minutes;
int DepartureTime = DepHours * 60 + DepMin;
int ArrHours = *Arrival.Hours;
int ArrMin = *Arrival.Minutes;
int ArrivalTime = ArrHours * 60 + ArrMin;
int TotalTime = ArrivalTime - DepartureTime;
int TotalHours = TotalTime / 60;
int TotalMin = TotalTime % 60;
printf(" %02d:%02d", TotalHours, TotalMin);
return TotalTime;
}