Write a C++ program to define a class Metro with the following specifications :
Metro No
Metro Name
No of Seats
Starting point
Destination
Write a menu driven program by using appropriate manipulators to
a. Accept details of n metros.
b. Display all metro details.
c. Display details of metro from specified starting and ending destination by user.
So This Is the Question That I Am Trying to Solve and I Have Written the following code for it:
Hi, noobcoder9867.
Your English isn’t a problem – my English is poor as well –, but it seems you’re not giving us your original code. I can’t believe you can compile a code like:
And there’re similar syntax errors in your first post too.
This make pointlessly hard to help you, but I think I can spot at least one issue:
1 2 3 4 5 6 7 8 9 10 11
class Metro
{
int mno,No_of_Seats;
char mname[20],Starting_point[20],Destination[20];
// ...
};
void metrosearch(Metro m[],int n)
{
// ...
if((strcmp(a,m[i].Starting_point)==0) && (strcmp(b,m[i].Destination)==0))
Starting_point and Destination are class Metro private properties.
You can’t access them directly from outside their class.
Once you’ve made metrosearch() a standalone function, you should also provide methods to access those variables.
Write a menu driven program by using appropriate manipulators to
Even if there’s no a standard definition of manipulators (*), I think your teacher is asking about the getters and setters methods.
For what I can see, there are no ‘manipulators’ in in you class — and I’m totally fine with that, because you don’t need them.
But it sounds as if your teacher wants them, doesn’t it?
If you tried to access your private members from a standalone function, you would be forced to add them.
Is it possible that’s what your teacher wants?
Please consider: your Metro class doesn’t need to be aware of a C-style array of Metros, like an int variable doesn’t need to know it is contained in a int myarr[].
class Metro
{
// ...
constchar * getStartingPoint() const; // define this method
constchar * getDestination() const; // define this method
// ...
};
// Return an int as position for the C-style Metro array in main():
int findMetroInCArray(const Metro * const lines, int size)
{
char start[20]
, dest[20];
std::cout << "Enter starting station: ";
std::cin >> start;
std::cout << "Enter destination: ";
std::cin >> dest;
for (int i {}; i <= size; ++i) {
// compare your private properties to 'start' and 'dest'
// by getters here
}