I’m trying to create a member function that allows an user to set member array variables.
I’ve been looking everywhere but I can’t find the problem in my code,
#include <string>
#include <iostream>
using namespace std;
class Employee
{
protected:
string name;
char ssn[11];
char id[5];
char hired[8];
public:
Employee(char ssn, char id, char hired); //Constructor
Employee(string name);
~Employee(); //Destructor
void setName(string n) { n = name; }
void setSSN(char i) { ssn = i; }
};
int main()
{
return 0;
}
Let’s have a look at your
setSSNfunction:SNN, which most likely means social security number, doesn’t consist of just one digit but 11, right? Then why would
setSSNtake as input only one character (digit) by(char i)? SosetSSNfunction should rather take a string of characters containing SSN of the employee and that string should be of the same flavor as thessnmember variable of yourEmployeeclass in order to let you assign one string variable by another in the body ofsetSSNfunction. If you are already familiar with thestringclass of the C++ standard library, you should probably use that class for all your string storage and manipulation.