-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLuvBird.cpp
374 lines (324 loc) · 11.6 KB
/
LuvBird.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
// I decided to make the debugging display a part of the menu so that I could check if changes were updating accordingly if any were made to the profile
// Video: https://youtu.be/Kx7dMosFsR0
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
//Data structure and variables
struct Member{
string name;
int age;
int diff;
int gender;
int hobby[4];
string contact;
};
//Function prototypes
void intro();
void userInfo(string hobbySelection[], string &name, int &age, int &genderS, int hobbyS[], int HOBBY);
void getInfo(Member x[], int USERS, int HOBBY);
int checkProfile(string hobbySelection[], string &name, int &age, int &genderS, int hobbyS[], int HOBBY);
string yesNoHobby(int x);
string gender(int x);
int memberDisplay(Member x[], int USERS, int HOBBY, string hobbySelection[], int hobbyS[], string &name, int &age, int &genderS);
int criterionCheck(Member x[], int USERS, int HOBBY, int &age, int &genderS, int hobbyS[], int criterionCount[], string hobbySelection[]);
bool isValid(int x, int min, int max);
int main(int argc, const char * argv[]) {
//Declare main variables
const int USERS=5;
const int HOBBY=4;
string hobbySelection[4]={"Play Videogames", "Read a Book", "Play a Sport", "Go Hiking"};
string name;
int age=0;
int genderS=0;
int hobbyS[HOBBY];
int menuS, profile=0;
int criterionCount[5];
int min=1, max=4;
int back=0;
int next=0;
Member info[USERS];
//Gets information from the members from .txt document
getInfo(info, USERS, HOBBY);
//Introduction message
intro();
//Gets user profile information
userInfo(hobbySelection, name, age, genderS, hobbyS, HOBBY);
//Resets back to the main menu unless program is exited, a match is made, or the user doesn't select from the top 2 matches
do{
//Loop allows for re-display of menu
do{
cout << "\n1. Display My Profile\n";
cout << "2. Find My Match\n";
cout << "3. Debug\n";
cout << "4. Quit\n";
cin >> menuS;
} while(!isValid(menuS, min, max));
switch (menuS){
//Allows user to go back to profile and make any changes
case 1:
profile = checkProfile(hobbySelection, name, age, genderS, hobbyS, HOBBY);
switch(profile){
case 1:
cout << "\nReturning to Main Menu...\n";
break;
case 2:
userInfo(hobbySelection, name, age, genderS, hobbyS, HOBBY);
break;
}
break;
//Determines top 2 matches for user and allows user to choose which of the top two to choose and receives their respective contact information (email)
case 2:
next = criterionCheck(info, USERS, HOBBY, age, genderS, hobbyS, criterionCount, hobbySelection);
if (next==1){
cout << "Thank you for matching with us today!\n";
} else if (next==2){
cout << "Unfortunately, we have no more matches for you. Try again next time!\n";
}
break;
//Displays user and member information for debugging purposes
case 3:
back=memberDisplay(info, USERS, HOBBY, hobbySelection, hobbyS, name, age, genderS);
switch(back){
case 1:
cout << "\nHeading back to the main menu...\n";
break;
case 2:
cout << "\nEnding program...\n";
break;
}
break;
//Ends switch statement and program
case 4:
cout << "\nEnding program...\n";
break;
}
} while(menuS!=4 && menuS!=2 && back!=2);
//Program end message display
cout << "\nThank you so much " << name << " for coming to LuvBird!\nWe hope to see you again!\n";
return 0;
}
//Welcome message display
void intro(){
cout << "Welcome to LuvBird, where matters of the heart matter most!" << endl;
cout << "This matchmaking program will help you find and connect with singles from ages 20 to 50 looking for love as well!" << endl;
cout << "\nTell us about yourself!\n";
}
//Gets user information and allows changes later on
void userInfo(string hobbySelection[], string &name, int &age, int &genderS, int hobbyS[], int HOBBY){
int repeat, min=1, max=2;
do{
cout << "\nPlease enter your name: ";
getline(cin, name);
cout << "Age: ";
cin >> age;
do{
cout << "Who would you be most interested in dating?\n";
cout << "1. Male" << endl;
cout << "2. Female" << endl;
cin >> genderS;
} while(!isValid(genderS, min, max));
for (int i=0; i<HOBBY; i++){
do{
cout << "Would you enjoy participating in the following activity: " << hobbySelection[i] << "?" << endl;
cout << "1. Yes\n";
cout << "2. No\n";
cin >> hobbyS[i];
} while(!isValid(hobbyS[i], min, max));
}
//Allows for changes to be made to the user profile
repeat = checkProfile(hobbySelection, name, age, genderS, hobbyS, HOBBY);
} while (repeat!=1);
cout << "Generating your perfect match...\n";
cout << "Press any key to continue...";
system("read");
}
//Gets member information from txt file and stores in data structure arrays
void getInfo(Member x[], int USERS, int HOBBY){
fstream infile;
infile.open("matches.txt");
for (int i=0; i<USERS; i++){
getline(infile, x[i].name);
infile >> x[i].age;
infile >> x[i].gender;
for (int j=0; j<HOBBY; j++){
infile >> x[i].hobby[j];
}
infile.get();
getline(infile, x[i].contact);
}
infile.close();
}
//Allows user to make and save profile changes
int checkProfile(string hobbySelection[], string &name, int &age, int &genderS, int hobbyS[], int HOBBY){
int confirm, min=1, max=2;
cout << "\nIs the following information correct?\n\n";
cout << "Name: " << name << endl;
cout << "Age: " << age << endl;
cout << "Gender Preference: " << gender(genderS) << endl;
for (int i=0; i<HOBBY; i++){
cout << "Likes to " << hobbySelection[i] << ": " << yesNoHobby(hobbyS[i]) << endl;
}
do{
cout << "\n1. The information above is correct.\n";
cout << "2. Edit my profile.\n";
cin >> confirm;
} while(!isValid(confirm, min, max));
cin.ignore();
return confirm;
}
//Determines yes/no given an integer input
string yesNoHobby(int x){
if (x==1){
return "Yes";
} else {
return "No";
}
}
//Determines gender given an integer input
string gender(int x){
if (x==1){
return "Male";
} else {
return "Female";
}
}
//Display user and memeber profile information to be used for debugging
int memberDisplay(Member x[], int USERS, int HOBBY, string hobbySelection[], int hobbyS[], string &name, int &age, int &genderS){
int back, min=1, max=2;
cout << "\nName: " << name << endl;
cout << "Age: " << age << endl;
cout << "Gender Preference: " << gender(genderS) << endl;
for (int i=0; i<HOBBY; i++){
cout << "Likes to " << hobbySelection[i] << ": " << yesNoHobby(hobbyS[i]) << endl;
}
//Table headers
cout << setw(15) << left;
cout << setw(10) << "\nName";
cout << setw(14) << right << "Age";
cout << setw(17) << "Gender";
for (int i=0; i<HOBBY; i++){
cout << setw(20) << hobbySelection[i];
}
cout << setw(20) << "Contact";
cout << endl;
//Display info for each member in txt file in a table
for (int i=0; i<USERS; i++){
cout << setw(15) << left;
cout << setw(20) << x[i].name;
cout << setw(15) << x[i].age;
cout << setw(15) << gender(x[i].gender);
for (int j=0; j<HOBBY; j++){
cout << setw(20) << yesNoHobby(x[i].hobby[j]);
}
cout << setw(15) << x[i].contact;
cout << endl;
}
do{
cout << "\n1. Return to Main Menu";
cout << "\n2. Quit\n";
cin >> back;
} while(!isValid(back, min, max));
return back;
}
//Determines 1st and 2nd best match based on # of similar characteristics
int criterionCheck(Member x[], int USER, int HOBBY, int &age, int &genderS, int hobbyS[], int criterionCount[], string hobbySelection[]){
int count, high=0, choice1=0, choice2=0, indexC=0, next, min=1, max=2, diff1=0, diff2=0, ageDiff=100, indexD=0;
//Find age difference
for (int i=0; i<USER; i++){
x[i].diff = abs(age-x[i].age);
}
//Lowest age difference
for (int i=0; i<USER; i++){
if (x[i].diff<ageDiff){
ageDiff=x[i].diff;
diff1=i;
indexD=i;
}
}
x[indexD].diff=100;
ageDiff=100;
//Find 2nd lowest age difference
for (int i=0; i<USER; i++){
if (x[i].diff<ageDiff){
ageDiff=x[i].diff;
diff2=i;
}
}
//Add points for each similar item and lower age gap
for (int i=0; i<USER; i++){
count=0;
if (x[i].diff==x[diff1].diff){
count++;
}
if (genderS==x[i].gender){
count++;
}
for (int j=0; j<HOBBY; j++){
if (hobbyS[i]==x[i].hobby[j]){
count++;
}
}
criterionCount[i] = count;
}
//Find most compatible
for (int i=0; i<USER; i++){
if (criterionCount[i]>high){
high=criterionCount[i];
choice1=i;
indexC=i;
}
}
criterionCount[indexC]=0;
high=0;
criterionCount[diff1]++;
//Find 2nd most compatible
for (int i=0; i<USER; i++){
if (criterionCount[i]>high){
high=criterionCount[i];
choice2=i;
}
}
cout << "\n\nHere is your top match: "; //Display top match
cout << "\nName: " << x[choice1].name;
cout << "\nAge: " << x[choice1].age;
cout << "\nGender: " << gender(x[choice1].gender);
for (int i=0; i<HOBBY; i++){
cout << "\nEnjoys to" << hobbySelection[i] << ": " << yesNoHobby(x[choice1].hobby[i]);
}
do{
cout << "\n\n1. I Accept the Match";
cout << "\n2. Next Best Match\n\n";
cin >> next;
} while(!isValid(next, min, max));
if (next==1){
cout << x[choice1].contact << endl << endl;
} else{
cout << "\nHere is your next top match: "; //Display next top match
cout << "\n\nName: " << x[choice2].name;
cout << "\nAge: " << x[choice2].age;
cout << "\nGender: " << gender(x[choice2].gender);
for (int i=0; i<HOBBY; i++){
cout << "\nEnjoys to " << hobbySelection[i] << ": " << yesNoHobby(x[choice2].hobby[i]);
}
do{
cout << "\n\nDo you accept the match?";
cout << "\n1. Yes\n";
cout << "2. No\n\n";
cin >> next;
} while(!isValid(next, min, max));
if (next==1){
cout << x[choice2].contact << endl << endl;
}
}
return next;
}
//Checks if entered integer input is valid
bool isValid(int x, int min, int max){
if (x<min || x>max){
cout << "\nInvalid Input. Please try again.\n";
return false;
} else{
return true;
}
}