Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class tractor {
- private:
- string brand,
- fuel_type,
- engine_power;
- double price;
- public:
- tractor() {
- brand = "ERROR";
- fuel_type = "ERROR";
- engine_power = -1;
- price = -1;
- }
- tractor(string _brand, string _fuel_type, double _engine_power, double _price) {
- brand = _brand;
- fuel_type = _fuel_type;
- engine_power = _engine_power;
- price = _price;
- }
- tractor(const tractor& t) {
- brand = t.brand;
- fuel_type = t.fuel_type;
- engine_power = t.engine_power;
- price = t.price;
- }
- void input() {
- cout << endl;
- cout << "Enter brand: ";
- getline(cin, brand);
- cout << "Enter type of fuel: ";
- cin >> fuel_type;
- cin.ignore(37578, '\n');
- cout << "Enter engine power(kW): ";
- cin >> engine_power;
- engine_power += "kW";
- cin.ignore(37578, '\n');
- cout << "Enter price($): ";
- cin >> price;
- cin.ignore(37578, '\n');
- }
- void print() {
- cout << endl;
- cout << "Brand: " << brand << endl;
- cout << "Type of fuel: " << fuel_type << endl;
- cout << "Engine power: " << engine_power << endl;
- cout << "Price: " << price << '$' << endl;
- }
- bool operator== (const tractor& t) {
- if (price == t.price)
- return 1;
- return 0;
- }
- bool operator!= (const tractor& t) {
- if (price != t.price)
- return 1;
- return 0;
- }
- bool operator> (const tractor& t) {
- if (price > t.price)
- return 1;
- return 0;
- }
- bool operator< (const tractor& t) {
- if (price < t.price)
- return 1;
- return 0;
- }
- tractor operator+ (const tractor& t) {
- tractor res;
- res.brand = brand + " & " + t.brand;
- res.fuel_type = fuel_type + " & " + t.fuel_type;
- res.engine_power = engine_power + " & " + t.engine_power;
- res.price = price + t.price;
- return res;
- }
- };
- int main() {
- tractor belarus;
- belarus.input();
- tractor MT;
- MT.input();
- cout << endl;
- cout << "operator== for belarus and MT returned " << (belarus == MT) << endl;
- cout << "operator!= for belarus and MT returned " << (belarus != MT) << endl;
- cout << "operator< for belarus and MT returned " << (belarus < MT) << endl;
- cout << "operator> for belarus and MT returned " << (belarus > MT) << endl;
- tractor MTandBelarus = MT + belarus;
- MTandBelarus.print();
- return 0;
- }
Add Comment
Please, Sign In to add comment