C++ Program #include #include #include #include #include using namespace std; // Provided Method - no need to change vector < string > split(const string& s, const string& delim) { /* Split lines of text using a delimiter http://programmingknowledgeblog.blogspot.com/2013/04/the-most-elegant-way-to-split-string-in.html This method will split a string and create (return) a vector of strings using a delimiter. Thus the code split("HELLO,EARTH,AND FRIENDS", ","); would return a vector of strings because the passed delimiter was "," v[0] = "HELLO" v[1] = "EARTH" .... */ vector < string > result; if (delim.empty()) { result.push_back(s); return result; } string::const_iterator substart = s.begin(), subend; while (true) { subend = search(substart, s.end(), delim.begin(), delim.end()); string temp(substart, subend); if (!temp.empty()) { result.push_back(temp); } if (subend == s.end()) { break; } substart = subend + delim.size(); } return result; } /******************************** Main Body of Work */ int main() { // Declare variables vector < string > dataLineVector; vector < string > airPortCodes; //TODO Create a vector of airport codes here // ... const string INPUT_FILE_NAME = "airports.dat"; constint AIRPORT_CODE_ELEMENT = 4; string inputLine, dataElement; // Open data file cout << "Opening data file: " << INPUT_FILE_NAME << endl; ifstream inputFile; inputFile.open(INPUT_FILE_NAME.c_str()); if (!inputFile) { // some compilers (inputFile == 0) cout << "ERROR - Unable to read from " << INPUT_FILE_NAME << "!" << endl; cout << "Check to see if the file is missing or corrupted." << endl; return99; } // Read individual lines of data, extract the desired element and validate cout << "Reading data from " << INPUT_FILE_NAME << endl; do { getline(inputFile, inputLine); if (!inputFile) { // if End of File (EOF) break; } dataLineVector = split(inputLine, ","); dataElement = dataLineVector[AIRPORT_CODE_ELEMENT]; if (dataElement.size() == 3) // TODO { // You now have data in the variable dataElement airPortCodes.push_back(dataElement); // Validate that it is a length of 3 chars - just check size cout << dataElement << endl; // if valid add it to your created vector of airport codes } //COMMENT: check whether the vector's size is equal to 3 } while (true); cout << "All airport code data has been extracted from " << INPUT_FILE_NAME << endl; inputFile.close(); //TODO Display total number of validated airport codes cout << "Total number of validated airport codes: " << airPortCodes.size() << endl; //TODO Check if Sorted -report/display as Sorted or Not Sorted if (is_sorted(airPortCodes.begin(), airPortCodes.end())) { cout << "Airport code vector is sorted" << endl; } else { cout << "Airport code vector is not sorted" << endl; } //TODO Sort Vector sort algorithm sorts the Vector of airPortCodes sort(airPortCodes.begin(), airPortCodes.end()); //TODO Check if Sorted -report/display as Sorted or Not Sorted if (is_sorted(airPortCodes.begin(), airPortCodes.end())) { cout << "Airport code vector is sorted" << endl; } else { cout << "Airport code vector is not sorted" << endl; } return0; } Review Assignment 3 from Week 6. This is the email address validation program. Address any issues or comments made as part of the original grade. This task is to create a modified copy of your program. The original requirement stated " Write a method that will have a C++ string passed to it. The string will be an email address and the method will return a bool to indicate that the email address is valid. " Change this program so that instead of returning a boolean, return a structure that includes the following: 1. A boolean that indicates if the email address is valid. 2. A string that reports what the error is. Set to empty if no error exists. 3. An Error number ( 1 - 4 ) that relates to the error list in the assignment. Set to 0 if no error exists. Display all the values of the structure upon return. Note: If multiple errors exist, only report the first error detected. Add the following line for a bool to display as true or false. std::cout << std::boolalpha; Deliverable is a working CPP program
C++
Review Assignment 3 from Week 6. This is the email address validation program. Address any issues or comments made as part of the original grade.
This task is to create a modified copy of your program. The original requirement stated " Write a method that will have a C++ string passed to it. The string will be an email address and the method will return a bool to indicate that the email address is valid. "
Change this program so that instead of returning a boolean, return a structure that includes the following:
1. A boolean that indicates if the email address is valid.
2. A string that reports what the error is. Set to empty if no error exists.
3. An Error number ( 1 - 4 ) that relates to the error list in the assignment. Set to 0 if no error exists.
Display all the values of the structure upon return.
Note: If multiple errors exist, only report the first error detected. Add the following line for a bool to display as true or false. std::cout << std::boolalpha;Deliverable is a working CPP program.
Trending now
This is a popular solution!
Step by step
Solved in 2 steps