-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.cpp
67 lines (53 loc) · 1.03 KB
/
product.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <sstream>
#include <iomanip>
#include "product.h"
using namespace std;
Product::Product(const std::string category, const std::string name, double price, int qty) :
name_(name),
price_(price),
qty_(qty),
category_(category),
rate_sum(0),
total_reviews(0)
{}
Product::~Product()
{
}
double Product::getPrice() const
{
return price_;
}
std::string Product::getName() const
{
return name_;
}
void Product::subtractQty(int num)
{
qty_ -= num;
}
int Product::getQty() const
{
return qty_;
}
/**
* default implementation...can be overriden in a future
* assignment
*/
bool Product::isMatch(std::vector<std::string>& searchTerms) const
{
return false;
}
void Product::dump(std::ostream& os) const
{
os << category_ << "\n" << name_ << "\n" << price_ << "\n" << qty_ << endl;
}
double Product::getAverage()const{
if(total_reviews == 0)
return 0;
else
return rate_sum/total_reviews;
}
void Product::addrating(double const temp){
rate_sum = rate_sum + temp;
total_reviews = total_reviews + 1;
}