Question

I need help with this program c++ - console aplication The attached file is a list...

I need help with this program c++ - console aplication

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:

        struct Station
        {
            std::string station;
            std::string id;
        };

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. The following types might be helpful.

typedef std::vector<std::string> Strings;
typedef std::vector<Station> Stations;
typedef std::map<std::string,Stations> StationBranchList;
typedef std::map<std::string,Station> StationMap;


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.

Extra Credit

Add to the program another level of output that for each station displays all the stations to which it connects. Sample output is shown following the assignment output.

Sample Output

For example, read this output as: in the City Terminal Zone branch, the station whose ID is 014 named East New York connects to station 013 Nostrand Avenue and station 015 Jamaica.

. . .
City_Terminal_Zone
  012 Atlantic_Terminal
    013 Nostrand_Avenue
  014 East_New_York
    013 Nostrand_Avenue
    015 Jamaica
  010 Forest_Hills
    009 Woodside
    011 Kew_Gardens
  002 Hunterspoint_Avenue
    001 Long_Island_City
    009 Woodside
  015 Jamaica
    001 Long_Island_City
    011 Kew_Gardens
    014 East_New_York
    030 Hollis
    083 St._Albans
    084 Locust_Manor
  011 Kew_Gardens
    010 Forest_Hills
    015 Jamaica
  001 Long_Island_City
    002 Hunterspoint_Avenue
    015 Jamaica
  013 Nostrand_Avenue
    012 Atlantic_Terminal
    014 East_New_York
  008 Penn_Station
    009 Woodside
  009 Woodside
    002 Hunterspoint_Avenue
    008 Penn_Station
    010 Forest_Hills
    017 Mets-Willets_Point
. . .

Below is the text file:-

ID Station Branch Connections Longitude Latitude LocSource
044 Albertson Oyster_Bay 043;045 -73.6416938 40.7719442 osm
137 Amagansett Montauk 136;138 -72.1325 40.98 wik
115 Amityville Babylon 114;116 -73.420472 40.680263 wik
012 Atlantic_Terminal City_Terminal_Zone 013 -73.977234 40.684226 wik
021 Auburndale Port_Washington 020;022 -73.7905 40.76139 wik
118 Babylon Babylon 117 -73.32421 40.700614 wik
107 Baldwin Babylon 106;108 -73.6070244 40.6566815 osm
119 Bay_Shore Montauk 120 -73.2529293 40.7249927 osm
022 Bayside Port_Washington 021;023 -73.771804 40.763105 wik
033 Bellerose Hempstead 031;034 -73.7166 40.7221 wik
110 Bellmore Babylon 109;111 -73.5275587 40.6690438 osm
126 Bellport Montauk 124;127 -72.9434861 40.773796 osm
032 Belmont Belmont 031 -73.728299 40.713655 wik
068 Bethpage Ronkonkoma 056;069 -73.4838686 40.7433164 osm
073 Brentwood Ronkonkoma 072;074 -73.2444232 40.7806188 osm
135 Bridgehampton Montauk 134;136 -72.309646 40.939163 wik
020 Broadway Port_Washington 019;021 -73.801383 40.761626 wik
054 Carle_Place Port_Jefferson 042;055 -73.6037551 40.7491654 osm
096 Cedarhurst Far_Rockaway 095;097 -73.725967 40.6223259 osm
074 Central_Islip Ronkonkoma 073;075 -73.193714 40.7920485 osm
101 Cent_Avenue Babylon 100;102 -73.663915 40.648272 wik
059 Cold_Spring_Harbor Port_Jefferson 058;060 -73.4510006 40.8357074 osm
116 Copiague Babylon 115;117 -73.399 40.681 wik
038 Country_Life_Press Hempstead 037;039 -73.6295272 40.721346 osm
072 Deer_Park Ronkonkoma 071;073 -73.293577 40.76948 wik
023 Douglaston Port_Washington 022;024 -73.7496 40.768 wik
136 East_Hampton Montauk 135;137 -72.1934611 40.9649361 wik
014 East_New_York City_Terminal_Zone 013;015 -73.905925 40.676053 wik
102 East_Rockaway Babylon 101;103 -73.657067 40.640938 wik
043 East_Williston Oyster_Bay 042;044 -73.6394351 40.7561231 osm
099 Far_Rockaway Far_Rockaway 098 -73.7506886 40.6090612 osm
069 Farmingdale Ronkonkoma 068;070 -73.441724 40.735827 osm
034 Floral_Park Hempstead 033;035;040 -73.706398 40.724622 wik
018 Flushing_Main_Street Port_Washington 017;019 -73.831086 40.757989 wik
010 Forest_Hills City_Terminal_Zone 009;011 -73.844883 40.719483 wik
108 Freeport Babylon 107;109 -73.5826737 40.6573384 osm
037 Garden_City Hempstead 036;038 -73.64007 40.723136 wik
093 Gibson Far_Rockaway 087;094 -73.7018373 40.6492363 osm
050 Glen_Cove Oyster_Bay 049;051 -73.6168977 40.865256 osm
047 Glen_Head Oyster_Bay 046;048 -73.6261345 40.8321721 osm
049 Glen_Street Oyster_Bay 048;050 -73.6210927 40.8580182 osm
025 Great_Neck Port_Washington 024;026 -73.725986 40.787235 osm
121 Great_River Montauk 120;122 -73.169729 40.7404969 osm
061 Greenlawn Port_Jefferson 060;062 -73.362712 40.8686822 osm
082 Greenport Ronkonkoma 081 -72.36361 41.09972 wik
046 Greenvale Oyster_Bay 045;047 -73.6269237 40.8155891 osm
132 Hampton_Bays Montauk 130;134 -72.524566 40.876464 wik
039 Hempstead Hempstead 038 -73.625307 40.713102 wik
091 Hempstead_Gardens West_Hempstead 090;092 -73.64611 40.69472 wik
094 Hewlett Far_Rockaway 093;095 -73.705019 40.6368335 osm
056 Hicksville Port_Jefferson 055;058;068 -73.5291403 40.7669006 osm
030 Hollis Hempstead 015;031 -73.7666 40.7102 wik
002 Hunterspoint_Avenue City_Terminal_Zone 001;009 -73.94722 40.74222 wik
060 Huntington Port_Jefferson 059;061 -73.4093319 40.8530432 osm
098 Inwood Far_Rockaway 097;099 -73.744545 40.6121748 osm
104 Island_Park Babylon 103;105 -73.655388 40.600433 wik
120 Islip Montauk 119;121 -73.209 40.736 wik
015 Jamaica City_Terminal_Zone 001;011;014;030;083;084 -73.808727 40.699511 wik
011 Kew_Gardens City_Terminal_Zone 010;015 -73.83066 40.7096 wik
063 Kings_Park Port_Jefferson 062;064 -73.255553 40.8837036 osm
090 Lakeview West_Hempstead 089;091 -73.65222 40.68556 wik
085 Laurelton Far_Rockaway 084;086 -73.7518 40.66853 wik
097 Lawrence Far_Rockaway 096;098 -73.7369102 40.6151794 osm
117 Lindenhurst Babylon 116;118 -73.369242 40.688243 wik
024 Little_Neck Port_Washington 023;025 -73.740744 40.775 wik
084 Locust_Manor Far_Rockaway 015;085 -73.764897 40.675022 wik
051 Locust_Valley Oyster_Bay 050;053 -73.5982576 40.8745042 osm
105 Long_Beach Babylon 104 -73.664854 40.589368 wik
001 Long_Island_City City_Terminal_Zone 002;015 -73.95694 40.74139 wik
100 Lynbrook Babylon 087;101;106 -73.6758 40.65603 wik
089 Malverne West_Hempstead 088;090 -73.66861 40.67556 wik
026 Manhasset Port_Washington 025;027 -73.69997 40.796684 osm
113 Massapequa Babylon 112;114 -73.469052 40.676901 wik
114 Massapequa_Park Babylon 113;115 -73.45474 40.677851 wik
127 Mastic_Shirley Montauk 126;129 -72.8646362 40.7989636 osm
080 Mattituck Ronkonkoma 079;081 -72.536009 40.991761 wik
077 Medford Ronkonkoma 075;078 -72.999197 40.8173606 osm
041 Merillon_Avenue Port_Jefferson 040;042 -73.6624844 40.7351509 osm
109 Merrick Babylon 108;110 -73.5504764 40.6637585 osm
017 Mets-Willets_Point Port_Washington 009;018 -73.843725 40.752516 wik
042 Mineola Port_Jefferson 041;043;054 -73.6416829 40.740124 osm
138 Montauk Montauk 137 -71.954452 41.046793 wik
019 Murray_Hill Port_Washington 018;020 -73.814446 40.762703 wik
036 Nassau_Boulevard Hempstead 035;037 -73.662751 40.722933 wik
040 New_Hyde_Park Port_Jefferson 034;041 -73.6810069 40.7307201 osm
062 Northport Port_Jefferson 061;063 -73.3283605 40.8806476 osm
013 Nostrand_Avenue City_Terminal_Zone 012;014 -73.94940 40.67845 wik
122 Oakdale Montauk 121;123 -73.1324042 40.7433981 osm
103 Oceanside Babylon 102;104 -73.654613 40.634986 wik
053 Oyster_Bay Oyster_Bay 051 -73.533895 40.8753239 osm
124 Patchogue Montauk 123;126 -73.0157675 40.7618544 osm
008 Penn_Station City_Terminal_Zone 009 -73.993899 40.750638 wik
070 Pinelawn Ronkonkoma 069;071 -73.399572 40.745339 wik
027 Plandome Port_Washington 026;028 -73.695216 40.810687 osm
067 Port_Jefferson Port_Jefferson 066 -73.0536917 40.9347194 wik
028 Port_Washington Port_Washington 027 -73.68733 40.829349 wik
031 Queens_Village Hempstead 030;032;033 -73.73638 40.717469 wik
079 Riverhead Ronkonkoma 078;080 -72.6669 40.919763 wik
106 Rockville_Cent Babylon 100;107 -73.6470348 40.6582644 osm
075 Ronkonkoma Ronkonkoma 074;077 -73.1061532 40.8081176 osm
086 Rosedale Far_Rockaway 085;087 -73.7356 40.6659 wik
045 Roslyn Oyster_Bay 044;046 -73.6432762 40.790789 osm
123 Sayville Montauk 122;124 -73.0861111 40.7403668 osm
048 Sea_Cliff Oyster_Bay 047;049 -73.6254057 40.8524189 osm
112 Seaford Babylon 111;113 -73.486454 40.67573 wik
064 Smithtown Port_Jefferson 063;065 -73.1985104 40.856385 osm
134 Southampton Montauk 132;135 -72.3897602 40.8948831 osm
081 Southold Ronkonkoma 080;082 -72.427859 41.066295 wik
129 Speonk Montauk 127;130 -72.704853 40.821224 wik
083 St._Albans West_Hempstead 015;087 -73.765426 40.691052 wik
065 St._James Port_Jefferson 064;066 -73.1590454 40.8824834 osm
035 Stewart_Manor Hempstead 034;036 -73.68114 40.723006 wik
066 Stony_Brook Port_Jefferson 065;067 -73.1285139 40.9202750 wik
058 Syosset Port_Jefferson 056;059 -73.5006403 40.8247493 osm
087 Valley_Stream Far_Rockaway 083;086;088;093;100 -73.704679 40.661483 wik
111 Wantagh Babylon 110;112 -73.509021 40.6730377 osm
092 West_Hempstead West_Hempstead 091 -73.64167 40.70194 wik
055 Westbury Port_Jefferson 054;056 -73.5858684 40.7534275 osm
130 Westhampton Montauk 129;132 -72.650973 40.830191 wik
088 Westwood West_Hempstead 087;089 -73.681417 40.668278 wik
095 Woodmere Far_Rockaway 094;096 -73.713904 40.631182 osm
009 Woodside City_Terminal_Zone 002;008;010;017 -73.903201 40.746072 wik
071 Wyandanch Ronkonkoma 070;072 -73.35781 40.754889 wik
078 Yaphank Ronkonkoma 077;079 -72.9158461 40.8256168 osm

Thank you in advance

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>

#include<string>

#include<vector>

#include<map>

#include <algorithm>

#include<fstream>

using namespace std;

struct Station

{

    string station;

    string id;

    string Branch;

}s[10];

class Mapping

{

public:

    string line;

    string Connections[10],LocSource[10];

    double Longitude[10], Latitude[10] ;

    vector<Station> Stations;

    std::map<std::string,Station> StationBranchList;

    std::map<std::string,Station> StationMap;

    void readfile()

    {

        vector<string> copy(20);

        ifstream in_File;

        in_File.open("input.txt");

        getline(in_File,line);

        int i=0;

     

        while(!in_File.eof())

        {

            in_File>>s[i].id>>s[i].station>>s[i].Branch>>Connections[i]>>Longitude[i]>>Latitude[i]>>LocSource[i];

        

            copy[i]=s[i].Branch;

            Stations.push_back(Station());

            Stations[i].station=s[i].station;

            i=i+1;

        }

        for(int k=0;k<Stations.size();k++)

        {

            StationBranchList[Stations[k].station].Branch=s[k].Branch;

            StationMap[Stations[k].station].id=s[k].id;

        }

        distinct(copy);

     

        for(int x=1;x<copy.size();x++)

        {

            cout<<"\nBranch Name: "<<copy[x];

            for(int y=0;y<Stations.size();y++)

            {

                if(StationBranchList[Stations[y].station].Branch==copy[x])

                cout <<"\n"<<StationMap[Stations[y].station].id<<"\t"<<Stations[y].station;

            }

        }

        in_File.close();

    }

    void distinct(vector<string>& vectorList)

    {

        sort(begin(vectorList), end(vectorList));

        auto end_unique = unique(begin(vectorList), end(vectorList));

        vectorList.erase(end_unique, end(vectorList));

    }

};

int main()

{

    Mapping mp;

    mp.readfile();

    return 0;

}

-------------------------------------------------------------------------

Output

Branch Name Babylon 115 101 118 107 Branch Nane: City Terminal Zone 012 Branch Name: Montauk 137 Branch Nane: OysterBay 044 0

Add a comment
Know the answer?
Add Answer to:
I need help with this program c++ - console aplication The attached file is a list...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3.) Having a reliable forecast of national economic growth can be important in making investment decisions....

    3.) Having a reliable forecast of national economic growth can be important in making investment decisions. The columns Month, Actualgrowth, Forecast1, Forecast2 and Forecast3 in the associated SPSS file contain actual economic figures over a 24-month period as well as the forecasted growth figures using three separate forecasting techniques. Which of the three forecasting techniques seems to be the best? Month | Actual Growth | Forecast 1 | Forecast 2 | Forecast 3 1   .023   .008   .018   .017 2   .011  ...

  • Question 2 (8 pts): Will this C++ program compile, and if not why? 001 nclude estring>...

    Question 2 (8 pts): Will this C++ program compile, and if not why? 001 nclude estring> 002 include ccmath> 003 004 uning namespace std 005 006 007 templatesclass T> 008 T operator+ (const Telassa% t1, const Telassct 009 010 templatecclass T> 011 class Tolass( t2); 012 friend T operatort (const TelasseTs t1, const Telasscs t2) 014 Telass (const T& value) :m_value (value)t 015 T NumericValue) constt 016 017 018 private: 019 T value: 020 } ; 021 02 template<class T>...

  • In a pilot study with 20 subjects evaluating the use of a new drug to lower...

    In a pilot study with 20 subjects evaluating the use of a new drug to lower resting heart rates (HR) of patients, the following data was recorded: Subject # Resting HR 001 72 002 88 003 71 004 87 005 64 006 77 007 79 008 59 009 77 010 68 011 78 012 89 013 91 014 81 015 85 016 75 017 69 018 75 019 77 020 81 Given that the average resting HR of the general...

  • this should be a code for C++ the source code file so the program will operate...

    this should be a code for C++ the source code file so the program will operate as described below. These are the software requirements for the project. When the program runs, it shall display the text as shown on lines 1-11 in the example below. Next, it shall display a prompt message asking the user to enter his or her yearly salary. Next, it shall shall read the user's salary from the keyboard (in the example below, user input is...

  • CAN BE DONE IN ANY LANGUAGE UID Values will be from 000 to 100: 001 002...

    CAN BE DONE IN ANY LANGUAGE UID Values will be from 000 to 100: 001 002 003 004 005 006 007 008 009 010 011 012 013 014 015 016 017 018 019 020 021 022 023 024 025 026 027 028 029 030 031 032 033 034 035 036 037 038 039 040 041 042 043 044 045 046 047 048 049 050 051 052 053 054 055 056 057 058 059 060 061 062 063 064 065 066...

  • Extended Learning Exercise. You have been asked to prepare a quick estimate of the construction cost...

    Extended Learning Exercise. You have been asked to prepare a quick estimate of the construction cost for a coal-fired electricity generating plant and facilities. A work breakdown structure (levels one through three) is shown in the table below EE! Click the icon to view the work breakdown structure Click the icon to view the available information What is your estimated 2019 cost for building the coal-fired generating facility? Summarize your calculations in a cost estimating worksheet, and state the assumptions...

  • Write MySQL query statements for the questions below including the output that proves the accuracy of...

    Write MySQL query statements for the questions below including the output that proves the accuracy of your solution. Your answers should be stored in a text file that captures your interaction with MySQL. 1. Find the movieID, title, year and DVDPrice of all movies where the DVD-Price is equal to the discountPrice. 2. Find the actorID, lastName, firstName, middleName, and suffix of all actors whose middleName is not NULL. 3. Suppose you remember a movie quote as “Play it again,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT