ASDV-Cpp/Assignments/StructuresLab_CalebFontenot/structures.cpp

29 lines
673 B
C++

#include <iostream>
#include <cstring>
#include "structures.h"
//
// Created by caleb on 3/22/24.
//
Employee::Employee() {
std::cout << "constructor called\n";
this->pName = new char[10];
std::strcpy(this->pName, "No Name");
}
Employee::Employee(char * pName, double salary) {
this->pName = new char[strlen(pName) + 1];
strcpy(this->pName, pName);
this->salary = salary;
}
Employee::~Employee() {
std::cout << "destructor called\n";
if (this->pName != nullptr) {
delete[] this->pName;
}
}
std::string Employee::toString() {
std::string s = this->pName;
s += ", ";
s += std::to_string(this-> salary);
return s;
}