home_task_03_company_1592131053.pdf (113.3 КБ)
Есть вот такое задание, вообще не понимаю как реализовать класс Company, c сотрудниками вроде разобрался. Есть вот такой код
header
#pragma once
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
class Employee
{
char* name;
char* position;
int dept;
public:
Employee(const char* n, const char* p, int d);
Employee();
Employee(const Employee& obj);
Employee(Employee&& obj)noexcept;
~Employee();
int getDepartment()const;
const char* getName()const;
const char* getPosition()const;
void setDepartment(int val);
void setName(const char* val);
void setPosition(const char* val);
void Show()const;
Employee& operator=(const Employee& obj);
Employee& operator=(Employee&& obj)noexcept;
};
cpp
#include "Employee.h"
Employee::Employee(const char* n, const char* p, int d)
{
dept = d;
name = _strdup(n);
position = _strdup(p);
}
Employee::Employee():Employee("Noname","Noposition",0)
{
}
Employee::Employee(const Employee& obj) : Employee(obj.name, obj.position, obj.dept)
{
}
Employee::Employee(Employee&& obj) noexcept
{
dept = obj.dept;
name = obj.name;
obj.name = nullptr;
position = obj.position;
obj.position = nullptr;
}
Employee::~Employee()
{
delete[]name;
delete[]position;
}
int Employee::getDepartment() const
{
return dept;
}
const char* Employee::getName() const
{
return name;
}
const char* Employee::getPosition() const
{
return position;
}
void Employee::setDepartment(int val)
{
dept = val;
}
void Employee::setName(const char* val)
{
delete[]name;
name = _strdup(val);
}
void Employee::setPosition(const char* val)
{
delete[]position;
position = _strdup(val);
}
void Employee::Show() const
{
cout << "Name: " << name << ", Position: " << position << ", Department: " << dept << endl;
}
Employee& Employee::operator=(const Employee& obj)
{
if (this == &obj)
return *this;
delete[]name;
delete[]position;
name = _strdup(obj.name);
position = _strdup(obj.position);
dept = obj.dept;
return *this;
}
Employee& Employee::operator=(Employee&& obj) noexcept
{
if (this == &obj)
return *this;
delete[]name;
delete[]position;
dept = obj.dept;
name = obj.name;
obj.name = nullptr;
position = obj.position;
obj.position = nullptr;
return *this;
}