Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #include #include #include #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 &item, int& count); bool openInputFile( ifstream & inFile ); string makeStringUpper( string s); int searchForVesselByName( vector & dataBase, string vesselName, vector & s ); void printRecord( AISType & item ); bool getNextField(string &line, int &index, string &subString); double stringConvert(string); int findLastOccurrance(string mmsi, vector &d); int findFirstOccurrance(string mmsi, vector &d); void addUniqueString( vector &s, string value); void saveField( int fieldNumber, string subString, AISType &tempItem ); double distanceTraveled( vector & dataBase, int first, int last );

int main() { int count=0; vector dataBase; vector mmsi;

// 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 & dataBase, int first, int last ){ return 0.0; // Keeps the compiler happy, students should replace

} /* 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 &d){ return -1; // Keeps the compiler happy, students should replace } int findFirstOccurrance(string mmsi, vector &d){ return -1;// Keeps the compiler happy, students should replace } int searchForVesselByName( vector & dataBase, string vesselName, vector &s) { return 0; // Keeps the compiler happy, students should replace

} void addUniqueString( vector &s, string value){ } double stringConvert(string s){ return 0.0; // Keeps the compiler happy, students should replace } void printRecord( AISType &item ) {

} bool openInputFile( ifstream & inFile ) { string fileName; cout <<"Enter input file Name/q-Quit): "<> fileName; if (fileName == "q"||fileName == "Q") { cout << "Pressed Quit"<

} void readFile( ifstream & inFile, vector &item, int& count) { int count = 0; while (!inFile.eof()) { inFile >> vector; count++; } } void saveField( int fieldNumber, string subString, AISType &tempItem ){ } bool getNextField(string &line, int &index, string &subString) { return false;// Keeps the compiler happy, students should replace }

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Lo6 Identify several management development methods.

Answered: 1 week ago