Your Perfect Assignment is Just a Click Away

We Write Custom Academic Papers

100% Original, Plagiarism Free, Customized to your instructions!


COSC 1437 Tarrant County College Populating a Vector Airport Code

COSC 1437 Tarrant County College Populating a Vector Airport Code


While we are still focused on collections such as Arrays and Vectors, it is important to also consider how data is loaded into these structures. I will admit that other languages can make this task much easier.  Let’s work with some real world examples.

The Files referred to below are in the item named “This week’s Assignment Resources” in this module.

I have included an industry standard file called airports.dat. It lists the major commercial airports in the world in a comma delimited format. Your assignment is to read this data and populate a vector with the 3 character airport code that is in the 5th ( 4th indexed) delimited position of the file. Review Chapter 5 – Reading Data from a File.  If that airport code value happens to be empty or does not have a length of 3 characters, do not include it in your vector. Also, if you cannot read or find the file, you should exit the program.

Feel free to open the airports.dat file and see how it is structured.

Task 1: I have included a file called LoadAirports.cpp for this assignment. Modify this program to do the steps required for this assignment. Put your name in the heading comments and complete the //TODOs,

Read the attached file (AddingFileInVS.txt) on how I need you to open and plant the data file for your programs.

Task 2. Once you have this, sort the vector using built-in sort method. This method is not yet covered in your book.  See (Links to an external site.) for an example.  Basically the syntax is:

          sort (yourVectorName.begin(), yourVectorName.end());

 Task 3, Write a method that will validate that the vector is actually sorted. It should simply COUT that “Collection is sorted” or “Collection is NOT sorted”. Call this method before you sort the array and also after you sort the array.

 Task 4, In main(), create a loop and prompt for values to search for. 

Be aware that unlike Arrays which are always passed by reference to a method, Vectors are passed by value by default. You must use the & indicator or return a vector to absorb changes to a vector made in a method.

The steps done or invoked from main() are below. You should display what step you are on as the program proceeds. Note that steps 1 – 2b are provided for you in the LoadAirports.cpp program.

1. Open the File – Exit if error during open

2. Loop until end of file

   a.Read a line from the file.

   b. Pass the line to the split method

 c. Obtain and validate specified data and place valid data into your new airportCode vector.

3. Display the number of elements in the vector that contains the airport codes.

4. Check and report if vector is sorted or not sorted

5. Sort Vector

6. Check and report if vector is sorted or not sorted.

7. Create a loop in main() to prompt to find valid Airport codes. Expect only uppercase input. Display “Found” or “Not found”.  Use “X” to exit your loop. Display “Done” when complete.

Enter an Airport Code:oooo
Not found
Enter an Airport Code:DFW
Enter an Airport Code:X

The Deliverable is your CPP file.

5pts Extra Credit: Use the available find method for the vector search. See C++ find 

here is the code for the file LoadAirports.cpp

#define VERSION 1.02

#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

      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()) {
       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()) {
       if (subend == s.end()) {
       substart = subend + delim.size();
   return result;
Main Body of Work
int main() {
   // Declare variables
   vector < string > dataLineVector;
   int lineCount = 0;

   //TODO Create a vector of airport codes here
   // …

   const string INPUT_FILE_NAME = “airports.dat”;
   const int AIRPORT_CODE_ELEMENT = 4;

   string inputLine, dataElement;
   // Open data file
   cout << “Opening data file: ” << INPUT_FILE_NAME << endl;
   ifstream inputFile;;

   if ( {

       cout << “ERROR – Unable to read from ” << INPUT_FILE_NAME << “!” << endl;
       cout << “Check to see if the file is missing or corrupted.” << endl;
       return 99;

   // 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)

       dataLineVector = split(inputLine, “,”);
       dataElement = dataLineVector[AIRPORT_CODE_ELEMENT];

       // TODO
       // You now have data in the variable named dataElement
       // Validate that it is a length of 3 chars
       // if valid add it to your created vector of airport codes

   } while (true);

   cout << “All airport code data has been extracted from ” << INPUT_FILE_NAME << endl;
   cout << lineCount << ” lines processed.” << endl;

   //TODO  Display total number of validated airport codes
   //TODO Check if Sorted -report/display as Sorted or Not Sorted
   //TODO Sort Vector
   //TODO Check if Sorted -report/display as Sorted or Not Sorted

   //TODO Create a Loop to Search for Airport code. Report if Found or Not found. Use ‘X’ to exit.


   return 0;

Order Solution Now

Our Service Charter

1. Professional & Expert Writers: Fox Writers only hires the best. Our writers are specially selected and recruited, after which they undergo further training to perfect their skills for specialization purposes. Moreover, our writers are holders of masters and Ph.D. degrees. They have impressive academic records, besides being native English speakers.

2. Top Quality Papers: Our customers are always guaranteed of papers that exceed their expectations. All our writers have +5 years of experience. This implies that all papers are written by individuals who are experts in their fields. In addition, the quality team reviews all the papers before sending them to the customers.

3. Plagiarism-Free Papers: All papers provided by Fox Writers are written from scratch. Appropriate referencing and citation of key information are followed. Plagiarism checkers are used by the Quality assurance team and our editors just to double-check that there are no instances of plagiarism.

4. Timely Delivery: Time wasted is equivalent to a failed dedication and commitment. Fox Writers is known for timely delivery of any pending customer orders. Customers are well informed of the progress of their papers to ensure they keep track of what the writer is providing before the final draft is sent for grading.

5. Affordable Prices: Our prices are fairly structured to fit in all groups. Any customer willing to place their assignments with us can do so at very affordable prices. In addition, our customers enjoy regular discounts and bonuses.

6. 24/7 Customer Support: At Fox Writers, we have put in place a team of experts who answer to all customer inquiries promptly. The best part is the ever-availability of the team. Customers can make inquiries anytime.