Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

C++ ONLY The attached file is a list of all the Long Island Railroad stations. E

ID: 3833485 • Letter: C

Question

C++ ONLY

The attached file is a list of all the Long Island Railroad stations. Each station is described on one line with six space-delimited fields. Each station has a unique 3-character numeric ID, a station name, a branch to which it belongs, a list of the IDs of other stations to which it connects, the station's longitude and latitude, and a final field describing the source of the information.

Write a program to read in the station data and store it by branch. After reading and saving the data, display the station names and ID's by branch as shown below.

The following structure can be used to store the station data:

A class can be used instead. Use a map to store an entry for each branch. One approach to the data structure design would save the Stations of a branch, the values of the map, as vectors of Stations.

If we have a declaration such as map<...> lirr; so that lirr is a map of branch names, which are strings, to vectors of Stations, assuming the structure Station defined above, then to add a station (the variable sta) to the vector of stations associated with a branch, use the statement

lirr[branch].push_back(sta);

.push_back() makes a copy of its argument and adds it to the end of the vector.

here is the attached file:

https://farmingdale.open.suny.edu/bbcswebdav/pid-422633-dt-content-rid-2055290_1/xid-2055290_1

Explanation / Answer

#include<bits/stdc++.h>

using namespace std;

struct Station
{
   string station;
   string id;
};


int main()
{
   ifstream ifile("file.txt");

   string a,b,c,d;
   map<string, vector<Station> >mp;
   while(ifile>>a>>b>>c>>d>>d>>d>>d)
   {
       if(mp.find(c) == mp.end())
           mp[c] = vector<Station>();
      
       Station x;
       x.station = b;
       x.id = a;
       mp[c].push_back(x);
   }

   for(auto it:mp)
   {
       cout<<it.first<<endl;
       for(int i=0;i<it.second.size();i++)
       {
           cout<<" "<<it.second[i].id<<" "<<it.second[i].station<<endl;
       }
   }
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote