Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Lab 3 Direction: Submit the typed source code or git url. All tasks must be completed. Each team member is required to do at least

Lab 3 Direction: Submit the typed source code or git url. All tasks must be completed. Each team member is required to do at least 1 task. And no group can exceed 3 members

Employee For this lab, you will define the three classes Name, Address and Employee. Your group will have to rewrite the given method so that they perform their descriptions correctly. I. The header file Name.h contains the class Name, which consists of

Private string field named firstName.

Private string field named lastName.

Public default constructor that assigns the empty string to both firstName and lastName.

Public overloaded constructor that takes two strings as parameters named firstName and lastName respectively. If the parameters are valid names (they consist of only letters), they should be assigned to their respective fields (match the names); however, if any parameter is invalid, assign its respective field the empty string.

Public copy constructor that performs a shallow copy.

Public overloaded assignment operator that performs a shallow copy.

Public get method for firstName.

Public get method for lastName.

Public set method for firstName that assigns the parameter to firstName only if it is a valid name.

Public set method for lastName that assigns the parameter to lastName only if it is a valid name.

Public string constant method named ToString() that takes no parameters. It returns a string with the format firstName followed by lastName with a space between them.

Public overloaded ostream operator that the displays a Name object in the same format as ToString().

II. The header file Address.h contains the class Address, which consists of

Private string field named street.

Private string field named city.

Private string field named state.

Private string field named zipcode.

Public default constructor that assigns the empty string to both street and city,NY to state and 11111 to zipcode.

Public overloaded constructor that takes four strings as parameters named street, city, state and zipcode respectively. It assigns street to the street field. It assigns city to the city field only if city is a valid name (consists of only letters); otherwise, it assigns the empty string to the city field. It assigns state to the state field only if state is a valid initial (consists of only two letters); otherwise, it assigns NY to the state field. And it assigns zipcode to the zipcode field only if zipcode is a valid zipcode (consists of exactly five digits); otherwise, it assigns 11111 to the zipcode field.

Public copy constructor that performs a shallow copy.

Public overloaded assignment operator that performs a shallow copy.

Public get method for street.

Public get method for city.

Public get method for state.

Public get method for zipcode.

Public set method for street.

Public set method for city that assigns the parameter to city only if it is a valid name.

Public set method for state that assigns the parameter to state only if it is a valid initial.

Public set method for zipcode that assigns the parameter to zipcode only if it is a valid zipcode.

Public string constant method named ToString() that takes no parameters. It returns a string with the format street on its own line, followed by city comma state space zipcode.

Public overloaded ostream operator that the displays a Name object in the same format as ToString().

III. The header file Employee.h contains the class Employee, which consists of

Private Name field named name.

Private Address field named address.

Private int field named employeeId.

Private double field named salary.

Private int static field named nextId which is initialized to 1.

Public default constructor that assigns the default Name object to name, default Address object to address, nextId to employeeId and 5000 to salary. It also increments nextId by 1.

Public overloaded constructor that takes a Name, Address and a double as parameters named name, address and salary respectively. It assigns name to the name field. It assigns address to the address field. It assigns salary to the salary field only if salary is at least 5000; otherwise, it assigns 5000 to the salary field. And it assigns nextId to employeeId. It also increments nextId by 1.

Public copy constructor that performs a shallow copy.

Public overloaded assignment operator that performs a shallow copy.

Public get method for name.

Public get method for address.

Public get method for employeeId.

Public get method for salary.

Public static get method for nextId.

Public set method for name.

Public set method for address.

Public set method for salary that assigns the parameter to salary only if it is at least 5000.

Public string constant method named ToString() that takes no parameters. It returns a string with the format name space employeeId on their own line, followed by address on its own line, followed salary.

Public overloaded ostream operator that the displays a Name object in the same format as ToString().

in C++ , i tried running the code but getting cause i used header files for each and its not allowing me to use the tostring function in the repository header file, can you please comiple this as one main.cpp file so i can see the mistakes i mad

// THIS IS THE REPOSITORY FILE USED TO TEST WHETHER EVERYTHING HAS PASSED

#ifndef REPOSITORY_H

#define REPOSITORY_H

#include "Name.h"

#include "Address.h"

#include "Employee.h"

using namespace lab3;

bool NameTest()

{

Name n1, n2("John","Doe"), n3("Gh0st","Walker"), n4(n2);

std::stringstream out;

if(n1.GetFirstName() != "" && n1.GetLastName() != "")

return false;

if(n2.GetFirstName() != "John" && n2.GetLastName() != "Doe")

return false;

if(n3.GetFirstName() == "Gh0st")

return false;

if(n4.GetFirstName() != n2.GetFirstName() && n4.GetLastName() != n2.GetLastName())

return false;

n3 = n2;

if(n3.GetFirstName() != n2.GetFirstName() && n3.GetLastName() != n2.GetLastName())

return false;

n1.SetFirstName("Peter");

n1.SetFirstName("P3ter");

n1.SetLastName("Parker");

n1.SetLastName("P@rk3r");

if(n1.GetFirstName() != "Peter" && n1.GetLastName() != "Parker")

return false;

if(n1.ToString() != "Peter Parker")

return false;

out << n1;

if(n1.ToString() != out.str())

return false;

return true;

}

bool AddressTest()

{

Address n1, n2("1638 Bedford Ave","Brooklyn","NY","11225"),

n3("1150 Carroll St","Br0nx","New Jersey","A1323"), n4(n2);

std::stringstream out;

if(n1.GetStreet() != "" && n1.GetCity() != "" && n1.GetState() != "NY"

&& n1.GetZipcode() != "11111")

return false;

if(n2.GetStreet() != "1638 Bedford Ave" && n2.GetCity() != "Brooklyn"

&& n2.GetState() != "NY" && n2.GetZipcode() != "11225")

return false;

if(n3.GetCity() == "Br0nx" && n3.GetState() == "New Jersey"

&& n3.GetZipcode() == "A1323")

return false;

if(n4.GetStreet() != n2.GetStreet() && n4.GetCity() != n2.GetCity()

&& n4.GetState() != n2.GetState() && n4.GetZipcode() != n2.GetZipcode())

return false;

n3 = n2;

if(n3.GetStreet() != n2.GetStreet() && n3.GetCity() != n2.GetCity()

&& n3.GetState() != n2.GetState() && n3.GetZipcode() != n2.GetZipcode())

return false;

n1.SetStreet("1600 West St");

n1.SetCity("Bronkdale");

n1.SetCity("Br0nkD@ale");

n1.SetState("NJ");

n1.SetState("New Jersey");

n1.SetZipcode("10021");

n1.SetZipcode("33239-2442");

if(n1.GetStreet() != "1600 West St" && n1.GetCity() != "Bronkdale"

&& n1.GetState() != "NJ" && n1.GetZipcode() != "10021")

return false;

if(n1.ToString() != "1600 West St Bronkdale,NJ 10021")

return false;

out << n1;

if(n1.ToString() != out.str())

return false;

return true;

}

bool equalName(Name n1,Name n2)

{

bool result = (n1.GetFirstName() == n2.GetFirstName());

result = result && (n1.GetLastName() == n2.GetLastName());

return result;

}

bool equalAddress(Address n1,Address n2)

{

bool result = (n1.GetStreet() == n2.GetStreet());

result = result && (n1.GetCity() == n2.GetCity());

result = result && (n1.GetState() == n2.GetState());

result = result && (n1.GetZipcode() == n2.GetZipcode());

return result;

}

bool EmployeeTest()

{

Name v1("John","Doe"), v2("Mary","Jones");

Address a1("3 Elm St","New York","NY","66600"), a2("22 East Ave","Bronx","NY","11332");

Employee n1, n2(v1,a1,12000),n3(v1,a1,1000), n4(n2);

std::stringstream out;

if(Employee::GetNextId() < 4)

return false;

if(!equalName(n1.GetName(),Name()) && !equalAddress(n1.GetAddress(),Address()) && n1.GetSalary() != 6000)

return false;

if(!equalName(n2.GetName(),v1) && !equalAddress(n2.GetAddress(),a1) && n2.GetSalary() != 12000)

return false;

if(n3.GetSalary() == 1000)

return false;

if(!equalName(n4.GetName(),n2.GetName()) && !equalAddress(n4.GetAddress(),n2.GetAddress())

&& n4.GetEmployeeId() != n2.GetEmployeeId() && n4.GetSalary() != n2.GetSalary())

return false;

n3 = n2;

if(!equalName(n3.GetName(),n2.GetName()) && !equalAddress(n3.GetAddress(),n2.GetAddress())

&& n3.GetEmployeeId() != n2.GetEmployeeId() && n3.GetSalary() != n2.GetSalary())

return false;

n1.SetName(v2);

n1.SetAddress(a2);

n1.SetSalary(53000);

n1.SetSalary(4000);

}

bool Tester()

{

bool(*func[3])() = { &NameTest, &AddressTest, &EmployeeTest}, result = true, hold;

std::string functions[3] = { "Name", "Address", "Employee"};

for (int i = 0; i < 3; i += 1)

{

std::cout << functions[i] << " Test ";

hold = func[i]();

std::cout << ((hold) ? ("has passed. ") : ("has failed. "));

if (!hold)

{

result = false;

}

std::cout << std::boolalpha;

std::cout << func[i]() << " " << " ";

}

std::cout << " ";

return result;

}

#endif

// THIS IS THE ARCHIVE.H HEADER FILE

#ifndef ARCHIVE_H

#define ARCHIVE_H

#include

#include

#include

#include

#include

#include

#include

namespace lab3

{

class Name;

class Address;

class Employee;

bool validName(std::string str)

{

for(int i = 0;i < str.length();i+=1)

{

if(!isalpha(str[i]))

return false;

}

return true;

}

bool validInitials(std::string str)

{

if(str.length() != 2)

return false;

return (isalpha(str[0]) && isalpha(str[1]));

}

bool validZipcode(std::string str)

{

if(str.length() != 5)

return false;

for(int i = 0;i < 5;i += 1)

{

if(!isdigit(str[i]))

return false;

}

return true;

}

}

#endif

// THIS IS MY ATTEMPTED NAME.h FILE

//Team:

//Author: Joel Turbi, Christopher Williams, Luis Casado

//Creation: 11/14/2017

#ifndef NAME_H

#define NAME_H

#include "Archive.h"

namespace lab3

{

class Name

{

private:

std::string firstName;

std::string lastName;

public:

Name()

{

firstName = "";

lastName = "";

}

Name(std::string firstName,std::string lastName)

{

for(int i = 0;i < firstName.length();i+=1)

{

if(!isalpha(firstName[i]))

{

this->firstName = "";

}

else

this->firstName = firstName;

}

for(int i = 0;i < lastName.length();i+=1)

{

if(!isalpha(lastName[i]))

{

this->lastName = "";

}

else

this->lastName = lastName;

}

}

// Copy constructor

Name(const Name& other)

{

firstName = other.firstName;

lastName = other.lastName;

}

// Assignment operator

Name& operator=(const Name& rhs)

{

if(this != &rhs)

{

this->firstName = rhs.firstName;

this->lastName = rhs.lastName;

}

return *this;

}

// Destructor

~Name() {}

std::string& GetFirstName()

{

return firstName;

}

std::string& GetLastName()

{

return lastName;

}

void SetFirstName(const std::string& first)

{

firstName = first;

}

void SetLastName(const std::string& last)

{

lastName = last;

}

std::string ToString() const

{

std::stringstream out;

out << firstName << " " << lastName << " ";

return out.str();

}

friend std::ostream& operator<<(std::ostream& out,const Name& obj)

{

out << obj.ToString();

return out;

}

};

}

#endif

//THIS IS MY ATTEMPTED EMPLOYEE.H file

//Team:

//Author:

//Creation:

#ifndef EMPLOYEE_H

#define EMPLOYEE_H

#include "Archive.h"

#include"Name.h"

#include"Address.h"

namespace lab3

{

class Employee

{

private:

Name name;

Address address;

int employeeId;

double salary;

static int nextId;

public:

Employee()

{

name = name;

address = address;

nextId = employeeId;

salary = 5000;

nextId +=1;

}

Employee(const Name& name,const Address& address,double salary)

{

this->name = name;

this->address = address;

if(salary>=5000)

{

this->salary = salary;

}

else

{

this->salary = 5000;

}

employeeId = nextId;

nextId +=1;

}

Employee(const Employee& other)

{

name = other.name;

address = other.address;

salary = other.salary;

nextId = other.nextId;

employeeId = other.employeeId;

}

Employee& operator=(const Employee& rhs)

{

if(this != &rhs)

{

this->name = rhs.name;

this->address = rhs.address;

this->salary = rhs.salary;

this->nextId = rhs.nextId;

this->employeeId = rhs.employeeId;

}

return *this;

}

~Employee(){}

int GetEmployeeId()

{

return employeeId;

}

Name& GetName()

{

return name;

}

Address& GetAddress()

{

return address;

}

static int GetNextId()

{

return nextId;

}

double GetSalary()

{

return salary;

}

void SetName(const Name& nam)

{

name = nam;

}

void SetAddress(const Address& add)

{

address = add;

}

void SetSalary(double sal)

{

salary = sal;

}

std::string ToString() const

{

std::stringstream out;

out << name << " " << employeeId << " " << address << " "

<< salary << " ";

return out.str();

}

friend std::ostream& operator<<(std::ostream& out,const Employee& obj)

{

out << obj.ToString();

return out;

}

};

int Employee::nextId = 1;

}

#endif

and this is my attempted ADDRESS.H file

//Team:

//Author:

//Creation:

#ifndef ADDRESS_H

#define ADDRESS_H

#include "Archive.h"

namespace lab3

{

class Address

{

private:

std::string street;

std::string city;

std::string state;

std::string zipcode;

public:

Address()

{

street = "";

city = "";

state = "NY";

zipcode = "11111";

}

Address(std::string street,std::string city,std::string state ,std::string zipcode)

{

this->street = street;

for(int i = 0;i < city.length();i+=1)

{

if(!isalpha(city[i]))

{

this->city = "";

}

else

this->city = city;

}

if(state.length() != 2)

{

state = "NY";

}

else

{

this->state = state;

}

if(zipcode.length() != 5)

{

zipcode = "11111";

}

else

{

this->zipcode = zipcode;

}

}

Address(const Address& other)

{

street = other.street;

city = other.city;

state = other.state;

zipcode = other.zipcode;

}

Address& operator=(const Address& rhs)

{

if(this != &rhs)

{

this->street = rhs.street;

this->city = rhs.city;

this->state = rhs.state;

this->zipcode = rhs.zipcode;

}

return *this;

}

~Address(){}

std::string& GetStreet()

{

return street;

}

std::string& GetCity()

{

return city;

}

std::string& GetState()

{

return state;

}

std::string& GetZipcode()

{

return zipcode;

}

void SetStreet(const std::string& st)

{

street = st;

}

void SetCity(const std::string& ct)

{

city = ct;

}

void SetState(const std::string& sta)

{

state = sta;

}

void SetZipcode(const std::string& zip)

{

zipcode = zip;

}

std::string ToString() const

{

std::stringstream out;

out << street << " " << city << " , " << state << " " << zipcode << " ";

return out.str();

}

friend std::ostream& operator<<(std::ostream& out,const Address& obj)

{

out << obj.ToString();

return out;

}

};

}

#endif

.this is the main.cpp

//Lab 3: Employee

//Team:

//Members:

//Creation:

#include "Repository.h"

#include

using namespace std;

int main()

{

if(Tester())

{

cout << "You have successfully completed Lab 3. ";

}

return 0;

}

. NOW When i ran these i get all failed and also an error with the std function

//

pository.h: In function bool EmployeeTest(): Repository.h:146:39: error: to_string is not a member of std std::string result = "Mary Jones " + std::to_string(n1.GetEmployeeId()) + " ^ In file included from Main.cpp:5:0: Repository.h: In function bool EmployeeTest(): Repository.h:146:39: error: to_string is not a member of std std::string result = "Mary Jones " + std::to_string(n1.GetEmployeeId()) + " ^ makefile:2: recipe for target 'main' failed make: *** [main] Error 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

=+2. How reliable is this existing information?

Answered: 1 week ago