-
Notifications
You must be signed in to change notification settings - Fork 0
/
RDV.cpp
148 lines (139 loc) · 3.04 KB
/
RDV.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
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include "date.h"
#include "hour.h"
using namespace std;
class RDV
{
public:
RDV(Date d, Hour h, string p, int nb, string *list) : date(d), hour(h), place(p), number_people(nb), list_people(list) {}
Date get_date()
{
return date;
}
Hour get_hour()
{
return hour;
}
string get_place()
{
return place;
}
int get_number_people()
{
return number_people;
}
string* get_list_people()//这里返回的是指向list_people数组的指针
{
return list_people;
}
void set_date(const Date& d)
{
date = d;
}
void set_hour(const Hour& h)
{
hour = h;
}
void set_place(string p)
{
place = p;
}
void set_number(int nb)
{
number_people = nb;
}
void set_list_people(string *list)
{
list_people = list;
}
void set_participant(int i, string name)
{
list_people[i] = name;
}
void print_RDV();
bool verify_compatible_merchant(RDV rdv);
bool verify_compatible_client(RDV rdv);
private:
Date date;
Hour hour;
string place;
int number_people;
string *list_people;
};
bool RDV::verify_compatible_merchant(RDV rdv)//商家当时间相同时冲突,返回false
{
if (this->hour == rdv.hour && this->date == rdv.date)
{
return false;
}
else
{
return true;
}
}
bool RDV::verify_compatible_client(RDV rdv) //顾客当时间相同且参加人员有重叠时冲突(一个人不可能同时在两个地方),返回false
{
if (this->hour == rdv.hour && this->date == rdv.date)
{
if (!no_common(this->list_people, this->number_people, rdv.list_people, rdv.number_people))
{
return false;
}
else
{
return true;
}
}
else
{
return true;
}
}
void RDV::print_RDV()
{
date.print();
hour.print();
cout << "place: " << place << endl;
cout << "number of people: " << number_people << endl;
cout << "list of participants: " << endl;
for (int i = 0; i < number_people; i++)
{
cout << list_people[i] << ", ";
}
}
bool no_common(int* arr1, int len1, int* arr2, int len2)
{
int count = 0;
for (int i = 0; i < len1; i++)
{
for (int j = 0; j < len2; j++)
{
if (arr1[i] == arr2[j])
{
count++;
}
}
}
bool result = (count == 0)? true : false;
return result;
}
bool no_common(string* arr1, int len1, string* arr2, int len2)
{
int count = 0;
for (int i = 0; i < len1; i++)
{
for (int j = 0; j < len2; j++)
{
if (arr1[i] == arr2[j])
{
count++;
}
}
}
bool result = (count == 0)? true : false;
return result;
}
int main()
{
Date date(17, 11, 2021);
Hour hour(22, 46);
}