Click here to Skip to main content
15,898,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Disclaimer this is part of my homework for university. However, I've been trying to solve this problem for the past 9 days and cant seem to be getting anywhere.

The system function as stated below, Staff can 1) Add station (no limitation to how many can be added, station info consists of 4 strings and 1 int that have to be added) 2) View Stations (simply read the station txt file above) 3) Edit stations

The issue I'm currently facing is editing the stations. I would like to do so through the command prompt, I am not sure how exactly this will be accomplished.

void Staff::ManageSelangorRailway()
{
    int select;
    cout << "Please select one of the following options: \n\n";
    cout << "1) Add Station 2) Edit/Delete Station 3) View Station 4) Return";
    cin >> select;

    switch (select)
    {
    case 1:
    {
            vector <StationInfo> getStationInfo;
        ofstream out("SelangorStations.txt", ofstream::out | ofstream::app);
        char accept = 'y';
        char reject = 'n';
        while (tolower(accept) == 'y')
        {
            StationInfo stationInfo = GetStationInfo();
            getStationInfo.push_back(stationInfo);
            cout << endl;
            out << stationInfo;

            cout << "Would you like to add another station ? (y/n): ";

            if (cin >> accept)
            {
                out.close();
                Staff::Staff();
            }
            else if (cin >> reject)
            {
                Staff();
            }
        }
        break;
    }
    case 2:
    {

    }
    case 3:
    {
        ifstream file("SelangorStations.txt");
        string content;

        while (file >> content) 
        {
            cout << content << ' ';
        }
    }
    default:
        break;
    }
}



No moue movements or clicks. As that would require external knowledge of widget and libraries I've attempted to assign each station added into the vector a unique ID (so far haven't got it working). I'd appreciate it if you or anyone else could actually write out the code to be able to read and replace the stations, at this point I don't mind dropping the unique ID per station idea.

At this point would anyone mind writing out the code. I'm burnt out and would love nothing more then to understand it by actually looking at the code.

What I have tried:

I have tried following several tutorial from YouTube and found similar stack overflow question that addressed this topic. However, it seems that no matter what I do, it just does not seem to work. I have deleted all of my failed attempts (code that did not work). If requested I will share the link that I have used as a point of reference.
Posted
Updated 28-Apr-18 23:35pm

1 solution

You need to read the data into some sort of list or vector of strings perhaps. You can then ask the user to select an item that they wish to edit. Find the item in your list and print its details. Then ask the user to enter the updates, and replace the old item in the list with the updated data. At the end of the program write the updated list to a new text file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900