C++
I need help writing these functions. I provided a skeleton of the code just missing the functions. if you can at least do one function that would nice. Thank you.
There's not enough room to copy and paste.
; 8 // Include libraries 9 #include
10 #include 11 #include 12 #include 13 #include 14 #include 15 10 16 using namespace std; 47 17 18 // Structure to hold item data 10 19 struct AISType 20 { 21 string MMSI; // @ 22 string baseDateTime; // 1 23 double lattitude; // 2 24 24 double longitude; // 3 25 double sogi 20 // 4 26 double cogi // 5 double hoodi 27 double heading; // 6 28 string vesselName; // 7 29 string imo; // 8 20 30 string callsign; // 9 21 31 string vesselType; // 10 32 string status; // 11 33 double length; // 12 34 34 double width; // 13 35 double draft; // 14 36 string cargo; // 15 37 string transceiverClass; // 16 38 }; 39 40 // Prototypes for functions void readFile( ifstream & infile, vector &item, int& count); 42 bool open InputFile( ifstream & inFile ); 43 string makeStringUpper( string s); int searchForVesselByName( vector & database, string vesselName, 45 vector &s ); 46 void printRecord( AISType & item ); 47 bool getNextField(string &line, int &index, string &subString); 48 double stringConvert(string); 49 int findLastOccurrance(string mmsi, vector &d); 50 int findFirstOccurrance(string mmsi, vector &d); 51 void addUniqueString( vector &s, string value); 52 void saveField( int fieldNumber, string substring. AISType &tempItem ); 53 double distanceTraveled( vector & database, int first, int last ); 54 55 int main() 56 { 57 // number of records read into the database 58 int count=0; 59 60 // the dataBase 61 // vector type is used because it's too big for an array. 62 69 // (on my computer anyway) 63 vector dataBase; 64 vector mmsi; LE 65 00 66 // input file 67 o ifstream inFile; 68 20 69 // temporary strings 20 70 string temp; 70 71 string ansYN; 7 72 72 73 int found=0; 74 2 string stars=""; 25 75 int first =0, last =0; 76 76 77 // open the input file 78 ze if (openInputFile( inFile ) ) 10 79 cout > ansYN; II II 136 if (ans YN =="y" or ans YN == "Y"){ 137 138 // print all the first records for the ships found 139 for (unsigned int i=0; i> ansYN; 155 156 if (ansYN == "y" or ans YN == ""){ 157 cout > temp; 159 cout & database, int first, int last ) { 189 190 191 return @.@; // Keeps the compiler happy, students should replace 192 193 } 194 195 // Example functon header comment. 196 /* findlastOccurrance - finds the last occurrance of an entry in the database 197 using the MMSI as the matching criterion. The vector is search from the 198 last entry forward. The vector data is in time sequential order. 199 string mmsi - the MMSI of the desired vessel. 200 vector &d) { 214 return -1; // Keeps the compiler happy, students should replace 215) 216 217 /* comments here 218 */ 219 int findFirstOccurrance(string mmsi, vector &d) { 220 return -1;// Keeps the compiler happy, students should replace 221 } 222 223 /* comments here 224 */ 225 int searchForVesselByName( vector & dataBase, string vesselName, 226 vector &s) 227 { 228 bool getNextField(string &line, int &index, string &subString) string &line - the line of data read from the file that needs to be parsed int &index the current starting position of the parsing. The first time this function is called for a new line, index should be set to zero. The function should update the index before returning, so that on the next call it will look at the next field. string &subString - the parsed string This function will receive the line of data read from the file, and starting at index, find the next string, which is all characters upto the next comma or ' '. Fields are delimited by commas. The string found, not including the comma, is saved in the subString. The commas that separate the data should be skipped. The value of index should be updated as the line is processed. When the function returns, index should point to the next character to be processed, and will be used as the starting point for the next call to the function. This function must parse the line one character at a time. String functions like.find() may not be used. Pseudo Code for getNextField ( suggested, you may do it differently) string line; string str; index = first character of next field while not at end of string and line[index] != ',') str += line[index]; index++; end while; index ++; // increment past the next',' // getting ready for the next call getNextField // test to see if there is more data in the string. if line.length() & dataBase, string vesselName, vector & matchesAIS ); vector & dataBase - The database of AIS records read from the file string vesselName the string to be searched for in the vessel names. vector & matchesAIS all vessel whose names contains the passed string, vesselName, should have their MMSI string added to the passed vector matchesAIS. matchesAIS is a vector that only contains the MMSI of vessels. return value the number of records found that match the passed string, vessel Name. This function performs a linear search on all records in database for records whose vesselName member contains the string passed in vesselName. The search should be done from 0 to maximum valid index. This function calls addUniqueString() to add the MMSI to the matches AIS vector. string makeString Upper( string s); string s - the string to be converted to upper case. return value - upper case version of passed string. This function converts the passed string to upper case and returns it. The library function toupper() may be called by this function. double stringConvert(string s) string s - the string to be converted into a double return value - the double converted from the string This function converts a string to it's corresponding double value. Implementation of the function must use string stream. All other implementations are not allowed and will have significant point deductions. int find LastOccurrance(string mmsi, vector &d) string mmsi - the mmsi value being searched for vector &d - the vector being searched. return value - the index of the last record in the vector that contains the mmsi value passed in. This function performs a linear search to locate the last record in the passed vector with the specified MMSI. For efficiency, the search should be started at the last element and work toward the first. int findFirstOccurrance(string mmsi, vector &d) string mmsi the mmsi value being searched for vector &d the vector being searched. return value - the index of the first record in the vector that contains the mmsi value passed in. This function performs a linear search to locate the first record, in the passed vector, with the specified MMSI. The search should be started at the first element and work toward the last. void addUniqueString(vector &s, string value) vector &s - the vector that the string should be added to string value - the string to be added This function first searches the vector to determine if the string in already present. If the string is already present, the function simply returns. If the string is not present, the it is added at the end of the vector. A string will never appear twice in the vector. void saveField( int fieldNumber, string subString, AIS Type &tempItem) int fieldNumber - the number of the field, starting at zero string substring - the value to be saved in the field, may require conversion to double inside the function. AISType &tempItem- the record which the field will be added This function saves the substring in to fieldNumber in the record passed, temp/tem. The subString may need to be converted to a double, depending on the fieldNumber. See the definition of struct AIS Type for specific field data types. This function must use string Convert() to perform the conversion from string to double. A error message should be output from the function if an unknown field number is specified. double distance Traveled( vector & dataBase, int first, int last) vector & dataBase - vector containing the AIS data records int first - index of starting location record int last - index of ending location record return value - calculated distance. In the case of a bad index value, 0.0 should be returned. Use the haversine formula to calculate the great circle distance between the vessel location in records first and last, using latitude and longitude. Remember that C++ functions, sine, cosine, and are tangent require the input values to be in radians. a=sin(40/2)+cos 01.cos 02.sin? (11/2) c=2. atan 2(Va,V(1-a)) distance=R.C qis latitude, is longitude R=3958.8(mean radius of earth, miles) PI=3.14159 radians=(degrees * PI/180.0