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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249
|
// This program processes air traffic control data stored in a comma-delimited file
// The data relates to incidents of severe turbulence
// and displays a plain text summary report for the file.
#define _CRT_SECURE_NO_WARNINGS
#include <fstream>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;
typedef char AirportType[4];
typedef char AirportNameType[50];
typedef char LocationType[31];
void substring(char inStr[], int start, int end, char outStr[]);
int strIndex(char inStr[], int start, char searchTarget);
void DateChg(char dateTime[]);
void Location(char distanceCity[]);
void flightchg(char flightID[]);
void flightlev(char flightlevel[]);
const int MAX_ARRAY = 1200;
char buffer[MAX_ARRAY + 1]; // +1 for null char
int main()
{
char datetime[16];
char airportCode[4];
char distCity[8];
char flightlevel[6];
char flightID[20];
// File initialization
ifstream inFile("flights.txt");
if (inFile.fail()) // Test for file existence
{
cout << "Problem opening file";
exit(-1);
}
// Read file and count values in array
while (inFile.getline(buffer, MAX_ARRAY))
{
int start = 0;
int end = strIndex(buffer, start, ',');
substring(buffer, start, end - 1, datetime);
start = end + 1;
end = strIndex(buffer, start, ',');
substring(buffer, start, end - 1, airportCode);
start = end + 1;
end = strIndex(buffer, start, ',');
substring(buffer, start, end - 1, distCity);
start = end + 1;
end = strIndex(buffer, start, ',');
substring(buffer, start, end - 1, flightlevel);
start = end + 1;
end = strIndex(buffer, start, ',');
substring(buffer, start, strlen(buffer) - 1, flightID);
flightchg(flightID);
DateChg(datetime);
Location(distCity);
flightlev(flightlevel);
}
system("pause");
return 0;
}
void substring(char inStr[], int start, int end, char outStr[])
{
strcpy(outStr, ""); // Empty output string
int pos = 0; // To mark curr position of substring
for (int i = start; i <= end; i++)
{
outStr[pos] = inStr[i]; // Move character to output string
pos++; // Manually advance position marker
}
outStr[pos] = '\0'; // Add null character to complete string
}
int strIndex(char inStr[], int start, char searchTarget)
{
int pos = start; // Set position marker to start index
int returnPos = -1; // Character position marker, assume not found
bool found = false; // Assume not found at start
while (inStr[pos] != '\0' && !found)
{
if (inStr[pos] == searchTarget) // If character found,
{
returnPos = pos; // Mark position
found = true; // Ready for exit from loop
}
else
pos++; // Otherwise, move to next character
}
return returnPos; // Return value
}
// get airport name date
// This function converts the date into a different form and displays it
void DateChg(char dateTime[])
{
char year[5];
char month[3];
char day[3];
char hours[3];
char minutes[3];
substring(dateTime, 0, 3, year);
substring(dateTime, 5, 6, month);
substring(dateTime, 8, 9, day);
substring(dateTime, 11, 12, hours);
substring(dateTime, 13, 14, minutes);
cout << "Date: ";
int m = atoi(month);
switch (m)
{
case 1: cout << "January "; break;
case 2: cout << "February "; break;
case 3: cout << "March "; break;
case 4: cout << "April "; break;
case 5: cout << "May "; break;
case 6: cout << "June "; break;
case 7: cout << "July "; break;
case 8: cout << "August "; break;
case 9: cout << "September "; break;
case 10: cout << "October "; break;
case 11: cout << "November "; break;
case 12: cout << "December "; break;
}
cout << day << ", " << year << endl;
if (strcmp(hours, "00") == 00)
cout << "Time: " << "12:" << minutes << "AM" << endl;
else if (strcmp(hours, "01") == 00)
cout << "Time: " << "1:" << minutes << "AM" << endl;
else if (strcmp(hours, "02") == 00)
cout << "Time: " << "2:" << minutes << "AM" << endl;
else if (strcmp(hours, "03") == 00)
cout << "Time: " << "3:" << minutes << "AM" << endl;
else if (strcmp(hours, "04") == 00)
cout << "Time: " << "4:" << minutes << "AM" << endl;
else if (strcmp(hours, "05") == 00)
cout << "Time: " << "5:" << minutes << "AM" << endl;
else if (strcmp(hours, "06") == 00)
cout << "Time: " << "6:" << minutes << "AM" << endl;
else if (strcmp(hours, "07") == 00)
cout << "Time: " << "7:" << minutes << "AM" << endl;
else if (strcmp(hours, "08") == 00)
cout << "Time: " << "8:" << minutes << "AM" << endl;
else if (strcmp(hours, "09") == 00)
cout << "Time: " << "9:" << minutes << "AM" << endl;
else if (strcmp(hours, "10") == 00)
cout << "Time: " << "10:" << minutes << "AM" << endl;
else if (strcmp(hours, "11") == 00)
cout << "Time: " << "11:" << minutes << "AM" << endl;
else if (strcmp(hours, "12") == 00)
cout << "Time: " << "12:" << minutes << "PM" << endl;
else if (strcmp(hours, "13") == 00)
cout << "Time: " << "1:" << minutes << "PM" << endl;
else if (strcmp(hours, "14") == 00)
cout << "Time: " << "2:" << minutes << "PM" << endl;
else if (strcmp(hours, "15") == 00)
cout << "Time: " << "3:" << minutes << "PM" << endl;
else if (strcmp(hours, "16") == 00)
cout << "Time: " << "4:" << minutes << "PM" << endl;
else if (strcmp(hours, "17") == 00)
cout << "Time: " << "5:" << minutes << "PM" << endl;
else if (strcmp(hours, "18") == 00)
cout << "Time: " << "6:" << minutes << "PM" << endl;
else if (strcmp(hours, "19") == 00)
cout << "Time: " << "7:" << minutes << "PM" << endl;
else if (strcmp(hours, "20") == 00)
cout << "Time: " << "8:" << minutes << "PM" << endl;
else if (strcmp(hours, "21") == 00)
cout << "Time: " << "9:" << minutes << "PM" << endl;
else if (strcmp(hours, "22") == 00)
cout << "Time: " << "10:" << minutes << "PM" << endl;
else if (strcmp(hours, "23") == 00)
cout << "Time: " << "11:" << minutes << "PM" << endl;
}
// This function takes the distance and airport code
// Changes it to the airport name and distance in miles
// Displays it in the proper format
void Location(char distanceCity[])
{
char distance[6];
char direction[3];
int start = 0, end;
for (end = start; isdigit(distanceCity[end]); ++end);
substring(distanceCity, start, end - 1, distance);
start = end;
end = strIndex(distanceCity, start, '\0');
substring(distanceCity, start, strlen(distanceCity) - 1, direction);
cout << "Location: " << distance << " miles ";
if (strcmp(direction, "SW") == 0)
cout << "southwest of ";
else if (strcmp(direction, "SE") == 0)
cout << "southeast of ";
else if (strcmp(direction, "NE") == 0)
cout << "north east of";
else if (strcmp(direction, "NW") == 0)
cout << "north west of";
else if (strcmp(direction, "N") == 0)
cout << "north of ";
else if (strcmp(direction, "S") == 0)
cout << "south of ";
else if (strcmp(direction, "E") == 0)
cout << "east of ";
else if (strcmp(direction, "W") == 0)
cout << "west of ";
}
// This function takes the Flight ID and
// Displays it properly
void flightchg(char flightID[])
{
char word[5];
char num[4];
substring(flightID, 0, 4, word);
substring(flightID, 5, 7, num);
cout << "Flight: " << word << " " << num << endl;
}
// This function takes the flight level and changes
// the altitude to feet and displays it
void flightlev(char flightlevel[])
{
char flight[3];
char level[4];
substring(flightlevel, 0, 2, level);
substring(flightlevel, 3, 4, flight);
cout << "Altitude: " << level << "00 feet" << endl;
}
|