Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- class Helicopter
- {
- friend std::ostream& operator<<(std::ostream&, const Helicopter&);
- public:
- Helicopter() {}
- Helicopter(int width, int height, int length, int windows = 0)
- : _width(width), _height(height), _length(length), _windows(windows) {}
- int width() const { return _width; }
- int height() const { return _height; }
- int length() const { return _length; }
- int windows() const { return _windows; }
- int square() const { return _width * _length; }
- private:
- int _width;
- int _height;
- int _length;
- int _windows;
- };
- class Airport
- {
- friend std::ostream& operator<<(std::ostream&, const Airport&);
- public:
- Airport(int level) : _level(level) {}
- Helicopter* add_helicopter(Helicopter* helicopter)
- {
- _helicopter.push_back(helicopter);
- return _helicopter.back();
- }
- Helicopter* add_helicopter(int width, int height, int length)
- {
- _helicopter.push_back(new Helicopter(width, height, length));
- return _helicopter.back();
- }
- void remove_helicopter(Helicopter *room)
- {
- remove_if(_helicopter.begin(), _helicopter.end(),
- [&room](Helicopter *it){ return room == it; });
- }
- int helicopter_count() const { return _helicopter.size(); }
- private:
- int _level;
- vector<Helicopter*> _helicopter;
- };
- ostream& operator<<(ostream& out, const Helicopter& helicopter)
- {
- return out << "Scale's"
- << " width: " << helicopter.width()
- << " height: " << helicopter.height()
- << " length: " << helicopter.length();
- }
- ostream& operator<<(ostream& out, const Airport& airport)
- {
- out << "Helicopter level " << airport._level << endl;
- out << "Contains cabin: " << endl;
- for_each(airport._helicopter.begin(), airport._helicopter.end(),
- [&out](Helicopter *it)
- {
- out << *it << endl;
- });
- return out;
- }
- int main()
- {
- vector<Helicopter*> other_helicopter;
- other_helicopter.push_back(new Helicopter(10, 10, 10));
- Airport airport(2);
- Helicopter *helicopter = airport.add_helicopter(new Helicopter(20, 20, 20));
- other_helicopter.push_back(helicopter);
- airport.add_helicopter(other_helicopter[0]);
- cout << "My new helicopter is " << airport << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement