-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpurchase.cpp
47 lines (37 loc) · 1.1 KB
/
purchase.cpp
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
//
// Created by joaog on 12/21/2020.
//
#include <iostream>
#include <string>
#include <iomanip>
#include "purchase.h"
Purchase::Purchase(string name, int numOfProducts, int availability){
this->name = name;
this->numOfProducts = numOfProducts;
this->availability = availability;
}
string Purchase::getName() const{
return this->name;
}
int Purchase::getNumOfProducts() const{
return this->numOfProducts;
}
int Purchase::getAvailability() const{
return this->availability;
}
bool Purchase::operator<(const Purchase& p2) const {
if( this->numOfProducts < p2.getNumOfProducts() )
return false;
else if(this->numOfProducts > p2.getNumOfProducts())
return true;
else{
return this->availability < p2.getAvailability();
}
}
bool Purchase::operator==(const Purchase &p2) const {
return this->name == p2.getName();
}
ostream& operator<<(ostream& out, Purchase p){
out << setfill(' ') << setw(15) << p.getName() << " |" << setw(10) << p.getNumOfProducts() << " |" << setw(10) << p.getAvailability() << endl;
return out;
}