Answer to Question #221914 in C++ for Bkj

Question #221914
Define a class named ‘Train’ representing following members: Data members :- - Train Number - Train Name - Destination - Journey Date - Capacity Member functions: - Initialise members - Input Train data - Display data Write a C++ program to test the train class.
1
Expert's answer
2021-07-31T07:43:49-0400



#include <iostream>using namespace std;class Train { private: int number, cap; string destination, name, date; public: Train(){}Train(int nu, int c, string d, string n, string da){ number =nu; cap = c; destination = d; name = n; date = da; }int trainNumber(){ cout<<"Enter train number\n"; cin>> number; return number;}int trainCapacity(){ cout<<"Enter train capacity\n"; cin>> cap; return cap; }string trainDestination(){ cout<<"Enter train destination\n"; cin>>destination; return destination;}string trainName(){cout<<"Enter train name\n";cin>>name;return name; }string trainDate(){ cout<<"The journey date\n "; cin>> date; return date; } void display(){ cout<<"Train number\t"<<trainNumber()<<endl; cout<<"Train capacity\t"<<trainCapacity()<<endl; cout<<"Train Destination\t"<<trainDestination()<<endl; cout<<"Train name\t"<<trainName()<<endl; cout << "Train journey date\t" << train destination<<endl; }};int main(){Train t;string name = t.trainName();string Destination = t.trainDestination();string date = t.trainDate();int number = t.trainNumber();int cap = t.trainCapacity(); Train t1(number,cap, Destination, name,date);t1.display(); return 0;}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS