-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreview.h
91 lines (81 loc) · 1.92 KB
/
review.h
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
#ifndef REVIEW_H
#define REVIEW_H
#include <string>
#include <iostream>
#include <sstream>
#include <string>
#include <string>
#include <QString>
/**
* Models a review for the product identified by prodName
*/
struct Review
{
Review() : prodName(""),username(""), rating(0), date(""), reviewText(""){ }
Review(std::string& prod,
std::string& username_,
int& rate,
std::string& d,
std::string& review_text) :
prodName(prod),
username(username_),
rating(rate),
date(d),
reviewText(review_text){}
void dump(std::ostream& os){
os<<prodName<<std::endl<<rating<<" "<<username<<" "<<date<<" "<<reviewText<<std::endl;
}
QString displayString(){
QString info = "Rating: " + QString::fromStdString(std::to_string(rating)) + "\n" +
" Date: " + QString::fromStdString(date) + "\n " + QString::fromStdString(reviewText);
return info;
}
bool operator<(const Review rhs) const{
char temp;
int this_year;
int rhs_year;
int this_month;
int rhs_month;
int this_day;
int rhs_day;
std::stringstream ss;
ss << this->date;
ss >> this_year; // yyyy-mm-dd
ss >> temp; // -mm-dd
ss >> this_month; //mm-dd
ss >> temp; // -dd
ss >> this_day; // dd
std::stringstream rhs_ss;
rhs_ss << rhs.date;
rhs_ss >> rhs_year;
rhs_ss >> temp;
rhs_ss >> rhs_month;
rhs_ss >> temp;
rhs_ss >> rhs_day;
if(this_year < rhs_year){
return 1;
}
else if(this_year > rhs_year){
return 0;
}
else if(rhs_year == this_year){
if(this_month < rhs_month)
return 1;
else if(this_month > rhs_month)
return 0;
else if (this_month == rhs_month){
if(this_day < rhs_day)
return 1;
else
return 0;
}
}
return 0;//never reached
}
std::string prodName;
std::string username;
int rating;
std::string date;
std::string reviewText;
};
#endif