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
|
// 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 <string>
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
// prototypes
void GetList(ifstream& InFile, int date[], int airportcode[], int distance[], int level[], int ID[], int& totalRecs);
int strIndex(char inStr[], int start, char searchTarget);
void substring(char inStr[], int start, int end, char outStr[]);
const int Max = 1000; // Max number of data lines
int main()
{
// Array of list elements
char inputLine[60];
int totalRecs = 0;
char id[4];
int date[Max];
char dateString[16];
int airportcode[Max];
int distance[Max];
int level[Max];
char levelstring[6];
char templevelstring[6];
int ID[Max];
int flight, date2, time, pmam, miles, direction, alt, pos, index, oldpos, Level, airport;
ifstream InFile;
InFile.open("flights.txt");
// File initialization
ifstream inFile("flights.txt");
if (inFile.fail()) // Test for file existence
{
cout << "Problem opening file";
exit(-1);
}
// Read file and count balues in array
GetList(InFile, date, airportcode, distance, level, ID, totalRecs);
while (!InFile.eof())
{
// locate date substring
pos = strIndex(inputLine, 0, ',');
substring(inputLine, 0, pos - 1, dateString);
date2 = atoi(dateString);
// locate airport code and convert
pos = strlen(inputLine)- 1;
substring(inputLine, oldpos + 1, pos, id);
// locate distance from city and extract "SW" then conver
// locate flight level and extract "FL"
oldpos = pos;
pos = strIndex(inputLine, oldpos + 1, ',');
substring(inputLine, oldpos + 1, pos - 1, levelstring);
oldpos = pos;
pos = strIndex(levelstring, 0, ',');
substring(levelstring, 0, pos-1, templevelstring);
strcpy(levelstring, templevelstring);
Level = atof(levelstring);
// locate flight ID and convert
}
// Output message
cout << "Flight: " << flight << endl;
cout << "Date: " << date2 << endl;
cout << "Time: " << time << " " << pmam << endl;
cout << "Location: " << miles <<" miles " << direction << " of " << airport << endl;
cout << "Altitude: " << alt << " feet" << endl;
system("pause");
return 0;
}
void GetList(ifstream& InFile, int date[], int airportcode[], int distance[], int level[], int ID[], int& totalRecs)
{
int i = 0;
// Priming read
InFile >> date[i] >> airportcode[i] >> distance[i] >> level[i] >> ID[i];
while (!InFile.eof())
{
i++; // Add one to pointer
// continuation reads
InFile >> date[i] >> airportcode[i] >> distance[i] >> level[i] >> ID[i];
}
totalRecs = i;
}
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
}
// This function puts the flight ID into a different format
void FlightID()
{
}
// This function converts the date into a different form and displays it
void DateChg()
{
}
// This fucktion takes the data from the date and converts it to time
// Displays it
void Time()
{
}
// 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()
{
}
// This function takes the fightlevel and converts it to feet
// Then displays it
void Altitude()
{
}
|