Question: C++, I need help plz /*********************** Assignment 1 ***********************/ // Include libraries #include #include #include #include #include #include using namespace std; // Structure to hold
C++, I need help plz





/***********************
Assignment 1
***********************/
// Include libraries
#include
#include
#include
#include
#include
#include
using namespace std;
// Structure to hold item data
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
};
// Prototypes for functions
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()
{
// number of records read into the dataBase
int count=0;
// the dataBase
// vector type is used because it's too big for an array.
// (on my computer anyway)
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
else{
cout
return 0;
}
// read the entire file into the dataBase
readFile( inFile, dataBase, count);
cout
cin.ignore( 40, ' ');
// user interaction loop
do{
// prompt the user for the input to search for. q to quit
temp.clear();
mmsi.clear();
cout
// read the user input. getline is used so that spaces may be included
// in the input
getline(cin, temp, ' ');
// check to see if the user wants to exit the program.
// If not exiting, output the search string.
if ( temp != "q" or temp == "Q" ){
cout
}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 );
// Let the user know if any ships were found with the name
if( found
cout
continue;
}else{
// output the results of the search
cout
cout
cout
cout
// ships were found, see if the user wants to display them
cout
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
" [y] " ;
cin >> ansYN;
if ( ansYN == "y" or ansYN == "Y"){
cout
cin >> temp;
cout
// 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
cout
cout
cout
cout
cout
cout
cout
cout
cout
cout
}
}
}
cin.ignore( 40, ' ');
} while ( true );
}
/* comments here
*/
double distanceTraveled( vector & dataBase, int first, int last ){
return 0.0; // Keeps the compiler happy, students should replace
}
// Example functon header comment.
/* 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 for efficiency.
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
}
/* comments here
*/
int findFirstOccurrance(string mmsi, vector &d){
return -1;// Keeps the compiler happy, students should replace
}
/* comments here
*/
int searchForVesselByName( vector & dataBase, string vesselName, vector &s){
return 0; // Keeps the compiler happy, students should replace
}
/* comments here
*/
void addUniqueString(vector &s, string value){
auto it = std::find (s.begin(), s.end(), value);
if (it != s.end()) // If string is already present
{
return;
}
else
s.push_back(value);
}
/* comments here
*/
double stringConvert(string s){
stringstream dou(s);
double res = 0.0;
dou >> res;
return res;
}
/* comments here
*/
void printRecord( AISType &item ){
}
/* comments here
*/
bool openInputFile( ifstream & inFile ){
return false ; // Keeps the compiler happy, students should replace
}
/* comments here
*/
void readFile( ifstream & inFile, vector &item, int& count){
}
/* comments here
*/
void saveField( int fieldNumber, string subString, AISType &tempItem ){
}
/* comments here
*/
bool getNextField(string &line, int &index, string &subString)
{
return false;// Keeps the compiler happy, students should replace
}
/* comments here
*/
string makeStringUpper(string s){
string res = s;
transform(res.begin(), res.end(), res.begin(), ::toupper);
return res;
}
void addUniqueString(vector &s, string value){
auto it = std::find (s.begin(), s.end(), value);
if (it != s.end()) // If string is already present
{
return;
}
else
s.push_back(value);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/// That's all I have, any question let me know. thank you and for sure thumbs up vote
Problem: This program will implement the same functionality as Assignment 1, but as a C++ class. The class definition is provided and should not be modified except as specified. Refer to the Assignment 1 write up for program functionality. AISClass - makeStringUpper( string s): string - getNextField(string &line, int &index, string &sub String): bool distance Traveled( int first, int last) : void - findLast Occurrance(string mmsi ) : int findFirstOccurrance(string): int - stringConvert( string): double - addUnique String( string value) : void - saveField( int fieldNumber, string subString, AISType &tempItem ): void openInputFile(ifstream &): bool - readFile( ifstream &): void AIS Data : vector - uniqueMmsi : vector - recordCount : int + printRecord( int) : void + searchForVesselByName ( string vesselName) : int + AISClass() + AISClass + readDataBase() : void + new Search(): void Detailed Function Descriptions void readFile( ifstream & inFile) inFile - already open file to be read This function performs similarly to the version from assignment 1, but stores the data in the class variable vector AISData, and the count is saved in member recordCount. The same algorithm may be used to parse the file or students may implement their own algorithm. Optional 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 return value - true if more data is available, false if the whole string has been parsed. This function is the same as in Assignment 1, but is a member of the class now. This function may be omitted if students develop their own algorithm to parse the input data file. bool openInputFile( ifstream& inFile ) ifstream& infile - file stream variable for the file to be opened. This function is the same as assignment 1 but a member of the class now. void printRecord( int record Number ) int record Number The element number of the record to print from AISData. The function is similar to the version from Assignment 1, but is passed the element number instead of the record itself. All fields for the record are printed. See example output for formatting. int searchForVesselByName( string vesselName) string vesselName the string to be searched for in the vessel names return value the number of records found that match the passed string, vesselName. This function is very similar to Assignment 1 but is a member of the class now. The function searches the member vector, AISData for possible matches, and adds vessels found to the member vector unique Mmsi by calling addUnique String(). 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. This is the same as Assignment 1 but is now a member of the class. double string Convert(string s) strings - 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. This is the same as assignment 1 but now is a member of the class. int find LastOccurrance(string mmsi) string mmsi - the mmsi value being searched for return value - the index of the last record in the vector that contains the mmsi value passed in. This function is very similar to the Assignment 1 function, but searches the member vector AISData for the matching vessel. int findFirstOccurrance(string mmsi) string mmsi the mmsi value being searched for return value the index of the first record in the vector that contains the mmsi value passed in. This function is very similar to the Assignment 1 function, but access the member vector AISData for the matching vessel. void addUniqueString( string value) string value - the string to be added This function is very similar to the version from Assignment 1, but adds the string to the member vector uniqueMmsi. Optional void save Field( int field Number, 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 to which the field will be added This function is the same as Assignment 1. If students choose to implement their own algorithms to parse the data, this function may be omitted. void distance Traveled( int first, int last) int first - index of starting location record int last - index of ending location record This function is similar to the version from Assignment 1, but access the member vector AISData to retrieve the values used for the distance calculation. The function also output the distance calculated. Functions New in Assignment 2 void newSearch This function handles a large part of what was handled by main in Assignment 1. After the file has been open and read in, all user interaction occurs in this function. The user is prompting for the vessel name to be searched for, exiting if 'q' is entered, calling searchFor VesselByName(), asking the user if they want to see the first record for the vessel, calling printRecord() if required, asking if they want to calculate the distance, and calling distance Traveled. Notes: This function loops until the user enters 'q' at the prompt for the vessel name to search for. The member vector unique Mmsi should be cleared at the beginning of a new search. AISClass() The default constructor for the class should initialize member recordCount to zero. -AISClass() The default constructor should clear both member vectors, AISData and uniqueMmsi. The message "Memory returned for vectors" should be output. void readDataBase() This function performs a portion of what was done in main() in Assignment 1. It calls openInputFile(), and exits the program if a false is returned from the open function. If true is returned, then readFile() is called to read the data into the member AISData, lastly the number of records that were read is output. Example Output dolly@Snoopy: AS2$ g++ main_solution.cpp -Wall -pedantic dolly@snoopy:AS2$ /a.out Enter input File Name/ (q-quit): AISData.csv File opened correctly *** 1800000--- End of file reached ---Items read: 1899355 1899355 records read Enter vessel name: bill 1543 vessel records containing name "bill", Unique vessels: 2 Would you like to display the first record of each vessel? [y) y ******* MMSI: 367007060 Base Date Time: 2019-01-01T00:00:00 Lattitude: 30.2898 Longitude: -91.2234 SOG: 0.2 COG: -196.3 Heading: 511 Vessel Name: BILL S imo: IMO7030963 Call Sign: WDC3383 Vessal Type: 31 Status: 15 Length: 30 Width: 8 Draft: 3.6 Cargo: 0 Transceiver Class: B MMSI: 366751770 Base Date Time: 2019-01-01T11:27:05 Lattitude: 49.9244 Longitude: -125.12 SOG: 6.5 COG: 131.1 Heading: 132 Vessel Name: BILLIE H imo: IMO8 964719 Call Sign: WCY4992 Vessal Type: 31 Status: 0 Length: 27 Width: 8 Draft: 4.7 Cargo: 32 Transceiver Class: B Would you like to find the distance traveled for a vessel? [y) y MMSI for vessel: 366751770 *************** Vessel: "BILLIE H" MMSI: 366751770 Trip Starting time: 2019-01-01T11:27:05 Distance traveled from (49.9244, -125.12) to (49.1369, -123.534) 89.5485 Miles Enter vessel name: maersk 15706 vessel records containing name "maersk", Unique vessels: 29 **** Would you like to display the first record of each vessel? [y] n Would you like to find the distance traveled for a vessel? [y) n Enter vessel name: mearsk O vessel records containing name "mearsk", Unique vessels: 0 Enter vessel name: atomic 363 vessel records containing name "atomic", Unique vessels: 1 Would you like to display the first record of each vessel? [y] y MMSI: 319071600 Base Date Time: 2019-01-01T00:04:11 Lattitude: 26.7489 Longitude: -80.0499 SOG: 0 COG: 186.5 Heading: 182 Vessel Name: ATOMIC imo: IMO1009807 Call Sign: ZGEG8 Vessal Type: 37 Status: 5 Length: 45 Width: 9 Draft: 2.8 Cargo: Transceiver Class: A Would you like to find the distance traveled for a vessel? [y) y MMSI for vessel: 319071600 Vessel: "ATOMIC" MMSI: 319071600 Trip Starting time: 2019-01-01T00:04:11 Distance traveled from (26.7489, -80.0499) to (26.7489, -80.0499) 0.00151337 Miles ************* ***** Enter vessel name: nothing 0 vessel records containing name "nothing", Unique vessels: 0 Enter vessel name: a Memory returned for vectors dolly@snoopy: AS2$ dolly@Snoopy:AS2$ ./a.out Enter input File Name/ (q-quit): 9 Error opening file Exiting.... dolly@Snoopy:AS2$ Problem: This program will implement the same functionality as Assignment 1, but as a C++ class. The class definition is provided and should not be modified except as specified. Refer to the Assignment 1 write up for program functionality. AISClass - makeStringUpper( string s): string - getNextField(string &line, int &index, string &sub String): bool distance Traveled( int first, int last) : void - findLast Occurrance(string mmsi ) : int findFirstOccurrance(string): int - stringConvert( string): double - addUnique String( string value) : void - saveField( int fieldNumber, string subString, AISType &tempItem ): void openInputFile(ifstream &): bool - readFile( ifstream &): void AIS Data : vector - uniqueMmsi : vector - recordCount : int + printRecord( int) : void + searchForVesselByName ( string vesselName) : int + AISClass() + AISClass + readDataBase() : void + new Search(): void Detailed Function Descriptions void readFile( ifstream & inFile) inFile - already open file to be read This function performs similarly to the version from assignment 1, but stores the data in the class variable vector AISData, and the count is saved in member recordCount. The same algorithm may be used to parse the file or students may implement their own algorithm. Optional 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 return value - true if more data is available, false if the whole string has been parsed. This function is the same as in Assignment 1, but is a member of the class now. This function may be omitted if students develop their own algorithm to parse the input data file. bool openInputFile( ifstream& inFile ) ifstream& infile - file stream variable for the file to be opened. This function is the same as assignment 1 but a member of the class now. void printRecord( int record Number ) int record Number The element number of the record to print from AISData. The function is similar to the version from Assignment 1, but is passed the element number instead of the record itself. All fields for the record are printed. See example output for formatting. int searchForVesselByName( string vesselName) string vesselName the string to be searched for in the vessel names return value the number of records found that match the passed string, vesselName. This function is very similar to Assignment 1 but is a member of the class now. The function searches the member vector, AISData for possible matches, and adds vessels found to the member vector unique Mmsi by calling addUnique String(). 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. This is the same as Assignment 1 but is now a member of the class. double string Convert(string s) strings - 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. This is the same as assignment 1 but now is a member of the class. int find LastOccurrance(string mmsi) string mmsi - the mmsi value being searched for return value - the index of the last record in the vector that contains the mmsi value passed in. This function is very similar to the Assignment 1 function, but searches the member vector AISData for the matching vessel. int findFirstOccurrance(string mmsi) string mmsi the mmsi value being searched for return value the index of the first record in the vector that contains the mmsi value passed in. This function is very similar to the Assignment 1 function, but access the member vector AISData for the matching vessel. void addUniqueString( string value) string value - the string to be added This function is very similar to the version from Assignment 1, but adds the string to the member vector uniqueMmsi. Optional void save Field( int field Number, 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 to which the field will be added This function is the same as Assignment 1. If students choose to implement their own algorithms to parse the data, this function may be omitted. void distance Traveled( int first, int last) int first - index of starting location record int last - index of ending location record This function is similar to the version from Assignment 1, but access the member vector AISData to retrieve the values used for the distance calculation. The function also output the distance calculated. Functions New in Assignment 2 void newSearch This function handles a large part of what was handled by main in Assignment 1. After the file has been open and read in, all user interaction occurs in this function. The user is prompting for the vessel name to be searched for, exiting if 'q' is entered, calling searchFor VesselByName(), asking the user if they want to see the first record for the vessel, calling printRecord() if required, asking if they want to calculate the distance, and calling distance Traveled. Notes: This function loops until the user enters 'q' at the prompt for the vessel name to search for. The member vector unique Mmsi should be cleared at the beginning of a new search. AISClass() The default constructor for the class should initialize member recordCount to zero. -AISClass() The default constructor should clear both member vectors, AISData and uniqueMmsi. The message "Memory returned for vectors" should be output. void readDataBase() This function performs a portion of what was done in main() in Assignment 1. It calls openInputFile(), and exits the program if a false is returned from the open function. If true is returned, then readFile() is called to read the data into the member AISData, lastly the number of records that were read is output. Example Output dolly@Snoopy: AS2$ g++ main_solution.cpp -Wall -pedantic dolly@snoopy:AS2$ /a.out Enter input File Name/ (q-quit): AISData.csv File opened correctly *** 1800000--- End of file reached ---Items read: 1899355 1899355 records read Enter vessel name: bill 1543 vessel records containing name "bill", Unique vessels: 2 Would you like to display the first record of each vessel? [y) y ******* MMSI: 367007060 Base Date Time: 2019-01-01T00:00:00 Lattitude: 30.2898 Longitude: -91.2234 SOG: 0.2 COG: -196.3 Heading: 511 Vessel Name: BILL S imo: IMO7030963 Call Sign: WDC3383 Vessal Type: 31 Status: 15 Length: 30 Width: 8 Draft: 3.6 Cargo: 0 Transceiver Class: B MMSI: 366751770 Base Date Time: 2019-01-01T11:27:05 Lattitude: 49.9244 Longitude: -125.12 SOG: 6.5 COG: 131.1 Heading: 132 Vessel Name: BILLIE H imo: IMO8 964719 Call Sign: WCY4992 Vessal Type: 31 Status: 0 Length: 27 Width: 8 Draft: 4.7 Cargo: 32 Transceiver Class: B Would you like to find the distance traveled for a vessel? [y) y MMSI for vessel: 366751770 *************** Vessel: "BILLIE H" MMSI: 366751770 Trip Starting time: 2019-01-01T11:27:05 Distance traveled from (49.9244, -125.12) to (49.1369, -123.534) 89.5485 Miles Enter vessel name: maersk 15706 vessel records containing name "maersk", Unique vessels: 29 **** Would you like to display the first record of each vessel? [y] n Would you like to find the distance traveled for a vessel? [y) n Enter vessel name: mearsk O vessel records containing name "mearsk", Unique vessels: 0 Enter vessel name: atomic 363 vessel records containing name "atomic", Unique vessels: 1 Would you like to display the first record of each vessel? [y] y MMSI: 319071600 Base Date Time: 2019-01-01T00:04:11 Lattitude: 26.7489 Longitude: -80.0499 SOG: 0 COG: 186.5 Heading: 182 Vessel Name: ATOMIC imo: IMO1009807 Call Sign: ZGEG8 Vessal Type: 37 Status: 5 Length: 45 Width: 9 Draft: 2.8 Cargo: Transceiver Class: A Would you like to find the distance traveled for a vessel? [y) y MMSI for vessel: 319071600 Vessel: "ATOMIC" MMSI: 319071600 Trip Starting time: 2019-01-01T00:04:11 Distance traveled from (26.7489, -80.0499) to (26.7489, -80.0499) 0.00151337 Miles ************* ***** Enter vessel name: nothing 0 vessel records containing name "nothing", Unique vessels: 0 Enter vessel name: a Memory returned for vectors dolly@snoopy: AS2$ dolly@Snoopy:AS2$ ./a.out Enter input File Name/ (q-quit): 9 Error opening file Exiting.... dolly@Snoopy:AS2$