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

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

C++ Program

#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>

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.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Header Files
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education