Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class Airplane {
- private:
- std::string type;
- int passengers;
- public:
- Airplane(const std::string& t, int p) : type(t), passengers(p) {}
- // Перегруженный оператор ==
- bool operator==(const Airplane& other) const {
- return type == other.type;
- }
- // Перегруженный оператор ++
- Airplane& operator++() {
- ++passengers;
- return *this;
- }
- // Перегруженный оператор --
- Airplane& operator--() {
- if (passengers > 0) {
- --passengers;
- }
- return *this;
- }
- // Перегруженный оператор >
- bool operator>(const Airplane& other) const {
- return passengers > other.passengers;
- }
- // Геттер для количества пассажиров
- int getPassengers() const {
- return passengers;
- }
- };
- int main() {
- Airplane a1("Boeing 747", 300);
- Airplane a2("Airbus A380", 500);
- Airplane a3("Boeing 747", 400);
- // Проверка на равенство типов самолетов (операция ==)
- if (a1 == a2) {
- std::cout << "a1 and a2 are of the same type." << std::endl;
- } else {
- std::cout << "a1 and a2 are of different types." << std::endl;
- }
- if (a1 == a3) {
- std::cout << "a1 and a3 are of the same type." << std::endl;
- } else {
- std::cout << "a1 and a3 are of different types." << std::endl;
- }
- // Увеличение и уменьшение пассажиров в салоне самолета (операции ++ и --)
- ++a1; // Увеличение пассажиров на 1
- --a2; // Уменьшение пассажиров на 1
- std::cout << "New number of passengers in a1: " << a1.getPassengers() << std::endl;
- std::cout << "New number of passengers in a2: " << a2.getPassengers() << std::endl;
- // Сравнение двух самолетов по максимально возможному количеству пассажиров на борту (операция >)
- if (a1 > a2) {
- std::cout << "a1 can accommodate more passengers than a2." << std::endl;
- } else {
- std::cout << "a1 cannot accommodate more passengers than a2." << std::endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement