Description: In this homework, you will generate a more complex solution that co
ID: 2247169 • Letter: D
Question
Description: In this homework, you will generate a more complex solution that contains a class structure used to store the location of an employee, and check his location with a location “database”. You have to create 4 classes 1. Point 2. Employee 3. Set 4. Location Class Point : Class Point is very simple and will store coordinates x and y as private int variables. Class Point will have, as a minimum, the following public members. You are allowed to add as many other public and private members as you need for your solution. 1. SetY(int), int GetY() 2. SetX(int), int GetX() 3. Default constructor which initializes x and y to 0 4. At least one initialization constructor that sets x and y as constructor parameters. Class Employee: Class Employee will store employee name as private string data member. This class will be composed of a Point, where the coordinates (i.e. Point) of the Employee will be stored. Class Employee should have, as a minimum, the following public members. You are allowed to add as many other public and private members as you need for your solution. 1. Constructor which sets employee name and the employhee’s coordinates from the received values. 2. GetCoordinates(Point & point) 3. SetCoordinates(Point & point) 4. GetName(string & name) 5. SetName (string & name) Class Set: Class Set will keep track of the numbers that are contained within a set. Values in the set range from 0 to 20, inclusive. The Set will keep track of values in the set using a simple vector. If an element in the vector is true, the number is in the set. If the element of the vector is false, the number is not in the set. Class Set should have, as a minimum, the following public members. You are allowed to add as many other public and private members as you need for your solution. 1. A constructor that initializes the set with a given vector. (I.e. Set::Set(vector & v)) 2. bool IsMember(int x) 3. Set Union(Set & S) // returns a Set the represents the Union of this set and S 4. Set Intersection(Set & S) // returns a Set that represents the Intersection of this set and S 5. Print() // prints the members of this Set Class Location: Class Location will store the coordinates of several large US cities. The Location class will be composed of several Set classes (two for each location). For example, the Location class will know the location of New York City because Location will be composed of a Set that contains the X values for New York, and another Set that contains the Y values for New York. X between 0 to 5 and Y between 0 to 5 = New York City X between 6 to 10 and Y between 6 to 10 = San Francisco X between 11 to 15 and Y between 11 to 15 = Los Angeles X between 16 to 20 and Y between 16 to 20 = Chicago Class Location should have, as a minimum, the following public members. You are allowed to add as many other public and private members as you need for your solution. 1. Default constructor that initializes all the Sets for New York, San Francisco, Los Angeles, and Chicago 2. LOCATION GetLocation(Point &p) a. Where Location is an enum you define, as follows: enum LOCATION(NOT_FOUND, NEWYORK, SANFRANSISCO, LOSANGELES, CHICAGO) You will create 2 programs for this homework, as follows. Therefore, you could create a solution that has two projects. 1. Your first program (SetTest.cpp) will be a simple test driver to test your Set class. You must test each of the public member functions by creating known Sets, then calling the Union and Intersection members to see that you have the correct results. The test driver should print all input and output information to the screen, so that it is clear when your test driver is run that the Sets are working correctly. 2. Your second program (EmployeeLoc.cpp) should prompt the user to enter the name and location for an employee, and the program will print out where that employee is located (EmployeeLoc.cpp) For example if you create an Employee with name “Mark” and x = 4 and y = 3; then it should print “Mark is in New York City” If x = 6 and y = 10 then it should print “Mark is in San Francisco” If x = 8, y = 20 then it should print “Mark’s location not found” If the user enters -1 for x or y it should exit. The output screen should look something like this. Enter Employee Name: Mark Enter X position (-1 to quit): 4 Enter Y position (-1 to quit): 5 Mark is in New York City Enter Employee Name: Erin Enter X position (-1 to quit): 14 Enter Y position (-1 to quit): 15 Erin is in Los Angeles Enter Employee Name: Maria Enter X position (-1 to quit): 4 Enter Y position (-1 to quit): 15 Maria’s location not found You should provide with 10 files, including Point.h, Point.cpp, Employee.h, Employee.cpp, Set.h, Set.cpp, Location.h, Location.cpp, EmployeeLoc.cpp, and SetTest.cpp
Explanation / Answer
Given below are the files needed for the question along with output. Please don't forget to rate the answer if it helped. Thank you very much.
Point.h
#ifndef Point_h
#define Point_h
class Point
{
private:
int X, Y;
public:
Point();
Point(int x, int y);
int GetX() const;
int GetY() const;
void SetX(int x);
void SetY(int y);
};
#endif /* Point_h */
Point.cpp
#include "Point.h"
Point::Point()
{
X = 0;
Y = 4;
}
Point::Point(int x, int y)
{
X = x;
Y = y;
}
int Point::GetX() const
{
return X;
}
int Point::GetY() const
{
return Y;
}
void Point::SetX(int x)
{
X = x;
}
void Point::SetY(int y)
{
Y = y;
}
Employee.h
#ifndef Employee_h
#define Employee_h
#include <iostream>
#include "Point.h"
using namespace std;
class Employee
{
private:
string name;
Point coordinates;
public:
Employee();
Employee(string n, const Point &point);
Point& GetCordinates();
void SetCordinates(const Point &point);
string GetName();
void SetName(const string &name);
};
#endif /* Employee_h */
Employee.cpp
#include "Employee.h"
Employee::Employee()
{
}
Employee::Employee(string n, const Point &coord)
{
}
Point& Employee::GetCordinates()
{
return coordinates;
}
void Employee::SetCordinates(const Point &point)
{
coordinates = point;
}
string Employee::GetName()
{
return name;
}
void Employee::SetName(const string &n)
{
name = n;
}
Set.h
#ifndef Set_h
#define Set_h
#include <vector>
#include <iostream>
using namespace std;
class Set
{
private:
vector<int> values;
public:
Set();
Set(const vector<int> &v);
bool IsMember(int x);
Set Union(Set &s);
Set Intersection(Set &s);
void Print();
void Add(int x);
};
#endif /* Set_h */
Set.cpp
#include "Set.h"
Set::Set()
{
}
Set::Set(const vector<int> &v)
{
values = vector<int>(v);
}
bool Set::IsMember(int x)
{
for(int i = 0 ; i < values.size(); i++)
if(values[i] == x)
return true;
return false;
}
Set Set::Union(Set &s)
{
Set U(s.values);
for(int i = 0; i < values.size(); i++)
if(!s.IsMember(values[i]))
U.Add(values[i]);
return U;
}
Set Set::Intersection(Set &s)
{
vector<int> v;
for(int i = 0; i < values.size(); i++)
{
if(s.IsMember(values[i]))
v.push_back(values[i]);
}
return Set(v);
}
void Set::Print()
{
for(int i = 0; i < values.size(); i++)
cout << values[i] << " " ;
cout << endl;
}
void Set::Add(int x)
{
values.push_back(x);
}
Location.h
#ifndef Location_h
#define Location_h
#include "Set.h"
#include "Point.h"
enum LOCATION {NOT_FOUND, NEWYORK, SANFRANSISCO, LOSANGELES, CHICAGO} ;
class Location
{
private:
Set NewYorkX, NewYorkY; //X and Y coordinates for NewYork
Set SanFranX, SanFranY;//X and Y coordinates for San Francisco
Set LosAngX, LosAngY;//X and Y coordinates for Los Angeles
Set ChicagoX, ChicagoY;//X and Y coordinates for Chicago
public:
Location();
LOCATION GetLocation(const Point &p);
};
#endif /* Location_h */
Location.cpp
#include "Location.h"
Location::Location()
{
NewYorkX = Set(vector<int>({0, 1, 2, 3, 4 ,5}));
NewYorkY = Set(vector<int>({0, 1, 2, 3, 4 ,5}));
SanFranX = Set(vector<int>({6, 7, 8, 9, 10}));
SanFranY = Set(vector<int>({6, 7, 8, 9, 10}));
LosAngX = Set(vector<int>({ 11, 12, 13, 14 ,15}));
LosAngY = Set(vector<int>({ 11, 12, 13, 14 ,15}));
ChicagoX = Set(vector<int>({16, 17, 18, 19, 20}));
ChicagoY = Set(vector<int>({16, 17, 18, 19, 20}));
}
LOCATION Location::GetLocation(const Point &p)
{
if(NewYorkX.IsMember(p.GetX()) && NewYorkY.IsMember(p.GetY()))
return NEWYORK;
if(SanFranX.IsMember(p.GetX()) && SanFranY.IsMember(p.GetY()))
return SANFRANSISCO;
if(LosAngX.IsMember(p.GetX()) && LosAngY.IsMember(p.GetY()))
return LOSANGELES;
if(ChicagoX.IsMember(p.GetX()) && ChicagoY.IsMember(p.GetY()))
return CHICAGO;
return NOT_FOUND;
}
EmployeeLoc.cpp
#include "Employee.h"
#include "Location.h"
#include <iostream>
using namespace std;
int main()
{
Employee emp;
Location loc;
int x, y;
string name;
while(true)
{
cout << "Enter Name: ";
cin >> name;
emp.SetName(name);
cout << "Enter X position (-1 to quit): ";
cin >> x;
if(x == -1)
break;
cout << "Enter Y position (-1 to quit): ";
cin >> y;
if(y == -1)
break;
emp.GetCordinates().SetX(x);
emp.GetCordinates().SetY(y);
switch(loc.GetLocation(emp.GetCordinates()))
{
case NEWYORK:
cout << emp.GetName() << " is in New York City" ;
break;
case SANFRANSISCO:
cout << emp.GetName() << " is in San Francisco" ;
break;
case LOSANGELES:
cout << emp.GetName() << " is in Los Angeles" ;
break;
case CHICAGO:
cout << emp.GetName() << " is in Chicago" ;
break;
case NOT_FOUND:
cout << emp.GetName() << "'s location not found" ;
break;
}
cout << endl << endl;
}
}
SetTest.cpp
#include "Set.h"
#include <iostream>
using namespace std;
int main()
{
vector<int> v1 = {2, 3, 4 , 6};
vector<int> v2 = {1, 3, 4, 7};
Set A(v1), B(v2);
cout << "Set A: ";
A.Print();
cout << "Set B: ";
B.Print();
Set un = A.Union(B), inter = A.Intersection(B);
cout << "Set A union B: ";
un.Print();
cout << "Set A intersection B: ";
inter.Print();
}
output
$ g++ -std=c++11 Set.cpp Point.cpp Location.cpp Employee.cpp EmployeeLoc.cpp
$ ./a.out
Enter Name: Mark
Enter X position (-1 to quit): 4
Enter Y position (-1 to quit): 5
Mark is in New York City
Enter Name: Erin
Enter X position (-1 to quit): 14
Enter Y position (-1 to quit): 15
Erin is in Los Angeles
Enter Name: Maria
Enter X position (-1 to quit): 4
Enter Y position (-1 to quit): 15
Maria's location not found
Enter Name: Maria
Enter X position (-1 to quit): -1
$ g++ -std=c++11 Set.cpp SetTest.cpp
$ ./a.out
Set A: 2 3 4 6
Set B: 1 3 4 7
Set A union B: 1 3 4 7 2 6
Set A intersection B: 3 4