Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class transport {
- protected:
- int number_wheels;
- public:
- virtual void input() {
- cout << "Enter number of wheels: ";
- cin >> number_wheels;
- }
- virtual void print() {
- cout << "Number of wheels: " << number_wheels << endl;
- }
- };
- class electric_transport : transport {
- int battery_charge;
- private:
- void input() {
- transport::input();
- cout << "Enter battery charge: ";
- cin >> battery_charge;
- }
- void print() {
- transport::print();
- cout << "Battery charge: " << battery_charge << endl;
- }
- friend istream& operator>> (istream&, electric_transport&);
- friend ostream& operator<< (ostream&, electric_transport&);
- };
- istream& operator>> (istream& in, electric_transport& e_t) {
- cout << "Enter number of wheels: ";
- in >> e_t.number_wheels;
- cout << "Enter battery charge: ";
- in >> e_t.battery_charge;
- return in;
- }
- ostream& operator<< (ostream& out, electric_transport& e_t) {
- out << "Enter number of wheels: " << e_t.number_wheels << endl;
- out << "Enter battery charge: " << e_t.battery_charge << endl;
- return out;
- }
- class railway_transport : transport {
- int number_carriage;
- private:
- void input() {
- transport::input();
- cout << "Enter number of carriage: ";
- cin >> number_carriage;
- }
- void print() {
- transport::print();
- cout << "Number of carriage: " << number_carriage << endl;
- }
- friend istream& operator>> (istream&, railway_transport&);
- friend ostream& operator<< (ostream&, railway_transport&);
- };
- istream& operator>> (istream& in, railway_transport& r_t) {
- cout << "Enter number of wheels: ";
- in >> r_t.number_wheels;
- cout << "Enter number of carriage: ";
- in >> r_t.number_carriage;
- return in;
- }
- ostream& operator<< (ostream& out, railway_transport& r_t) {
- out << "Number of wheels: " << r_t.number_wheels << endl;
- out << "Number of carriage: " << r_t.number_carriage << endl;
- return out;
- }
- int main() {
- transport t;
- t.input();
- cout << endl;
- t.print();
- cout << endl;
- electric_transport e_t;
- cin >> e_t;
- cout << endl << e_t << endl;
- railway_transport r_t;
- cin >> r_t;
- cout << endl << r_t << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment