PPL Assignment
IRM2015006
array_search.cpp
Go to the documentation of this file.
1 #include "array_search.h"
2 #include <iostream>
3 
4 Boy* ArraySearch::linearSearch(std::string name)
5 {
6  for (auto boy : boyslist) {
7  if (boy->name == name)
8  return boy;
9  }
10  return NULL;
11 }
12 
14 {
15  this->boyslist = boyslist;
16 }
17 
18 
19 void ArraySearch::findGirlfriends (std::vector<std::string> namelist, Logger *logger)
20 {
21  for (auto name : namelist) {
22  logger->info("checking for "+name, true);
23  Boy* boy = linearSearch(name);
24  if (boy != NULL) {
25  logger->log("found", boy->name+" boy found in list", true);
26  if (boy->committed) {
27  logger->log("q7:exists", name+" is committed with "+boy->girlfriend->name, true);
28  } else {
29  logger->log("q7:single", name+" is single", true);
30  }
31  } else {
32  logger->log("not found", name, true);
33  }
34  }
35 }
bool committed
Definition: boy.h:32
void info(const std::string msg, bool print=false)
Definition: logger.cpp:18
void findGirlfriends(std::vector< std::string > namelist, Logger *logger) override
ArraySearch(std::vector< Boy * > boylist)
void log(const std::string type, const std::string msg, bool print=false)
Definition: logger.cpp:27
Definition: logger.h:8
Boy * linearSearch(std::string name)
Definition: array_search.cpp:4
std::vector< Boy * > boyslist
Definition: search.h:14
std::string name
Definition: girl.h:24
Definition: boy.h:20
std::string name
Definition: boy.h:24
Girl * girlfriend
Definition: boy.h:30