-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicle.hpp
97 lines (73 loc) · 1.98 KB
/
vehicle.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#ifndef CMPE126LAB_VEHICLE_H
#define CMPE126LAB_VEHICLE_H
#include <string>
#include <iostream>
using namespace std;
class Vehicle{
private:
string brand;
string model;
float mpg;
int price;
string bodyType;
string fuelType;
public:
const string &getBrand() const;
const string &getModel() const;
float getMpg() const;
int getPrice() const;
const string &getBodyType() const;
const string &getFuelType() const;
bool operator <(const Vehicle &obj);
bool operator >(const Vehicle &obj);
bool operator ==(const Vehicle& obj);
friend istream& operator>>(istream& in, Vehicle &obj);
friend ostream & operator <<(ostream& out, const Vehicle obj);
bool operator <=(const Vehicle &ob);
};
istream &operator >>(istream &in, Vehicle &obj) {
in >> obj.brand >> obj.model >> obj.mpg >> obj.price >> obj.bodyType >> obj.fuelType;
// std::getline(in,obj.brand,' ');
// std::getline(in,obj.model,' ');
// in >> obj.mpg >> obj.price;
// std::getline(in,obj.bodyType,' ');
// std::getline(in,obj.fuelType,' ');
return in;
}
ostream &operator <<(ostream &out, const Vehicle obj) {
out << obj.brand << " " << obj.model << " " << obj.mpg << " " << obj.price << " " << obj.bodyType << " "
<< obj.fuelType << endl;
return out;
}
bool Vehicle::operator<(const Vehicle &obj) {
return price < obj.price;
}
bool Vehicle::operator>(const Vehicle &obj) {
return price > obj.price;
}
bool Vehicle::operator<=(const Vehicle &ob) {
return brand <= ob.brand;
}
bool Vehicle::operator==(const Vehicle &obj)
{
return price == obj.price;
}
const string &Vehicle::getBrand() const {
return brand;
}
const string &Vehicle::getModel() const {
return model;
}
float Vehicle::getMpg() const {
return mpg;
}
int Vehicle::getPrice() const {
return price;
}
const string &Vehicle::getBodyType() const {
return bodyType;
}
const string &Vehicle::getFuelType() const {
return fuelType;
}
#endif