I apologize if the title seems a bit to vague, could't think of title that would work with the problem at hand.
I'm currently creating a Railway system as part of my assignment, one of the requirements is to allow staff members to set opening and closing hours of railway.
Throughout the program I ask the staff to select a railway, wheather its for adding new stations,deleting new station or anything else, in this case its for setting operation hours. So I created a function that would constantly call for the selection instead of rewriting it several times. (code below)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
#include "stdafx.h"
#include "Railway.h"
#include "Staff.h"
using namespace std;
Railway::Railway()
{
cout << "Please select one of the following options.\n";
cout << "1) Selangor Railway \n2) Malacca Railway \n3) Negeri Sembilan Railway \n4) Exit";
int chooseRailway;
cin >> chooseRailway;
switch (chooseRailway)
{
case 1:
SelangorRailway();
break;
case 2:
MalaccaRailway();
break;
case 3:
NegeriSembilanRailway();
break;
default:
//TODO ExitSystem
break;
}
}
void Railway::SelangorRailway()
{
cout << "You have selected \"Selangor Railway.\"\n";
}
void Railway::MalaccaRailway()
{
cout << "You have selected \"Malacca Railway.\"\n";
}
void Railway::NegeriSembilanRailway()
{
cout << "You have select \"Negeri Sembilan Railway.\"\n";
}
|
I would like to somehow link it to another cpp file I have. (code below)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
void Staff::ManageOperationHours()
{
cout << "You have selected \"Manage Operation Hours.\"\n\n";
Railway();
cout << "Input operation hours.\n\n";
ofstream OutputFile;
OutputFile.open("OperationHours.txt");
string OpeningHours, ClosingHourse;
cout << "Enter the Opening Time of the Station: ";
cin >> OpeningHours;
OutputFile << OpeningHours << endl;
cout << "Enter the Closing Time of the Station: ";
cin >> ClosingHourse;
OutputFile << ClosingHourse << endl;
OutputFile.close();
cout << "Succesfully Registered!\n";
}
|
In order to create something like the code below (code below does not work, its simply used to give idea as to what I am trying to achieve).
if(SelangorRailway == chosen)
{
// execute the code above, into its own txt file selangr.txt
}
else if (MalaccaRailway == chosen)
{
// execute the code above, into its own txt file selangr.txt
}
else if (NegeriSembilanRailway == chosen)
{
// execute the code above, into its own txt file selangr.txt
}
Ultimately, I would like to use the same code but I dont think that will be possible seeing that the different railways will have different txt files.