Question
Data for this code 367430850,2019-01-01T00:00:05,30.40366,-88.85801,0.0,126.3,511.0,MISS NIZ,IMO8987539,WDF2697,31,0,22,8,2.4,52,B 255806194,2019-01-01T00:00:05,29.91171,-90.10790,0.0,137.2,272.0,NORDBALTIC,IMO9241475,CQAJ8,70,0,207,30,9.4,70,B 548799000,2019-01-01T00:00:06,29.20933,-89.27852,9.5,-78.6,332.0,BOW HECTOR,IMO9363493,DYWK,80,0,174,27,11.0,80,B #include #include #include #include #include #include using namespace std; struct AISType { string MMSI; // 0
Data for this code
367430850,2019-01-01T00:00:05,30.40366,-88.85801,0.0,126.3,511.0,MISS NIZ,IMO8987539,WDF2697,31,0,22,8,2.4,52,B 255806194,2019-01-01T00:00:05,29.91171,-90.10790,0.0,137.2,272.0,NORDBALTIC,IMO9241475,CQAJ8,70,0,207,30,9.4,70,B 548799000,2019-01-01T00:00:06,29.20933,-89.27852,9.5,-78.6,332.0,BOW HECTOR,IMO9363493,DYWK,80,0,174,27,11.0,80,B
#include
using namespace std; struct AISType { string MMSI; // 0 string baseDateTime; // 1 double lattitude; // 2 double longitude; // 3 double sog; // 4 double cog; // 5 double heading; // 6 string vesselName; // 7 string imo; // 8 string callSign; // 9 string vesselType; // 10 string status; // 11 double length; // 12 double width; // 13 double draft; // 14 string cargo; // 15 string transceiverClass; // 16 }; void readFile( ifstream & inFile, vector
int main() { int count=0; vector
// input file ifstream inFile;
// temporary strings string temp; string ansYN;
int found=0; string stars=""; int first =0, last =0;
// open the input file if (openInputFile( inFile ) ) cout << "File opened correctly "< cout << count << " records read "< cin.ignore( 40, ' '); // user interaction loop do{ temp.clear(); mmsi.clear(); cout << "Enter vessel name: "; getline(cin, temp, ' '); if ( temp != "q" or temp == "Q" ){ cout << endl<< "Searching for records with names containing \"" << temp << "\"" << endl; }else return 0; // search for the number of items that contain the name/phrase // All names in the vessel dataBase are upper case, so make the search // string upper. MMSI is built by the function and contains the vector // of unique vessels that contain the name searched for. found = searchForVesselByName( dataBase, makeStringUpper(temp), mmsi ); if( found <= 0) { cout << "Vessel \"" << temp << "\" not found" << endl; continue; }else{ // output the results of the search cout << stars << endl; cout << found << " vessels found with name containing \"" << temp << "\", "; cout << "Unique vessels: " << mmsi.size() << endl; cout << stars << endl; // ships were found, see if the user wants to display them cout << mmsi.size() << " vessels found. Would you like to see their" << " first records? [y/n] " ; cin >> ansYN; if (ansYN =="y" or ansYN == "Y"){ // print all the first records for the ships found for (unsigned int i=0; i // find the vessels using MMSI and print the records int index = findFirstOccurrance( mmsi[i], dataBase ); // verify that a valid record was found, print the record if ( index != -1) printRecord( dataBase[index]); } // Ask user if they want to calculate the distance traveled for // the vessel. cout << "Would you like to find the distance traveled for a vessel?" " [y/n] " ; cin >> ansYN; if ( ansYN == "y" or ansYN == "Y"){ cout << "MMSI for vessel: "; cin >> temp; cout << stars << endl; // locate the index value of the first and last record first = findFirstOccurrance( temp, dataBase); last = findLastOccurrance( temp, dataBase); //output the sitances and miles traveled cout << "Vessel: \"" << dataBase[first].vesselName; cout << "\" MMSI: " << dataBase[first].MMSI; cout << " Trip Starting time: " << dataBase[first].baseDateTime; cout << endl; cout << "Distance Traveled from (" << dataBase[first].lattitude; cout << ", " << dataBase[first].longitude << ") to ("; cout << dataBase[last].lattitude << ", "; cout << dataBase[last].longitude << ") "; cout << distanceTraveled(dataBase, first, last); cout << " Miles" << endl; cout << endl; } } } cin.ignore( 40, ' '); } while ( true ); } double distanceTraveled( vector } /* findLastOccurrance - finds the last occurrance of an entry in the dataBase using the MMSI as the matching criterion. The vector is search from the last entry forward. The vector data is in time sequential order. string mmsi - the MMSI of the desired vessel. vector return value - the index of the last record in the dataBase for the vessel with the matching MMSI. If the MMSI is not found, return -1. Algorithm Use a for loop the to seach from the last element of the vecotor toward the first. Since the data is time ordered, oldest first, search the vector from the bottom towards the top. This is a linear search and returns as soon as a match is found. */ int findLastOccurrance(string mmsi, vector } void addUniqueString( vector } bool openInputFile( ifstream & inFile ) { string fileName; cout <<"Enter input file Name/q-Quit): "< } void readFile( ifstream & inFile, vector string makeStringUpper(string s) { int i; for (i = 0; i < s.size(); i++) { s[i] = toupper(s[i]); } return s; // Keeps the compiler happy, students should replace } Can anyone please help me with the code? I just come from part-time job as returning student and forget almost everything,,,,,
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started