0
#include <iostream>
#include <string>
using namespace std;
#pragma warning(disable: 4996)

class Computer
{
    string nazwanie;
    int model;
    int price;

public:
    friend bool operator> (const Computer& d1, const Computer& d2);
    friend bool operator<= (const Computer& d1, const Computer& d2);

    friend bool operator< (const Computer& d1, const Computer& d2);
    friend bool operator>= (const Computer& d1, const Computer& d2);
    Computer()
    {
        nazwanie;
        model = 0;
        price = 0;
    }

    Computer(string nazwanie, int model, int price)
    {
        this->nazwanie = nazwanie;
        this->model = model;
        this->price = price;
      
    }

    ~Computer()
    {
      
    }

    void vivod()
    {
        cout <<"Name of computer: "<< nazwanie<< ".Model number:"<< model << ".Price in $ : " << price << endl;
    }
};
bool operator> (const Computer& d1, const Computer& d2)
{
    return d1.price > d2.price;
}

bool operator>= (const Computer& d1, const Computer& d2)
{
    return d1.price >= d2.price;
}

bool operator< (const Computer& d1, const Computer& d2)
{
    return d1.price < d2.price;
}

bool operator<= (const Computer& d1, const Computer& d2)
{
    return d1.price <= d2.price;
}
int main()
{
    Computer p1("Dell", 349, 1024);
    Computer p2("Asus", 1231, 2000);
    Computer p2("Samsung", 1080, 1500);

    p1.vivod();
    p2.vivod();
    if (p1 < p2)
        cout << "Asus is more expensive then Dell"<<endl;



    return 0;
}

1 ответ 1

0

Для сортировки достаточно вызвать функцию std::sort().

Деструктор этому классу не нужен.

2

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.