issues with passing a variable to my employee constructor]
I cant figure out how to do it right but i cant pass my name through the second employee construtor when i call it in int main()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <cstring>
using namespace std;
class Employee
{
public:
Employee()
{
char person[]="None";
strcpy (name, person);
idNum=1000;
salary=0;
};
Employee(const char *x, int id, double sal)
{
strcpy (name, *x);
idNum=id;
salary=sal;
};
void printEmp()
{
cout<<"Employee: ";
for (int x=0;x<26;x++)
{
cout<<name[x];
}
cout<<"ID: "<<idNum;
cout<<"Salary: "<<salary;
};
void increaseSalary( double more)
{
if (more>0)
{
salary=salary+more;
}
else
{
cout<<"Error: the salary cannot be increased";
}
};
void setIDnum( int newIDnum)
{
if (newIDnum<1000||newIDnum>9999999)
{
cout<<"Error: the new identification number is invalid. It will be ste to 1000";
idNum=1000;
}
else
{
idNum=newIDnum;
}
};
void setSalary( double newSalary)
{
if(newSalary<=0)
{
cout<<"Error: the passed in salary is invalid. The salary will be set to 0.00";
salary=0.00;
}
else
{
salary=newSalary;
}
};
int getIDnum()
{
return idNum;
};
double getSalary()
{
return salary;
};
private:
char name[25];
int idNum;
double salary;
};
int main()
{
Employee e1= Employee( "Matthew Lyon", 1704663, 678367732.40);
|
«issues»
you get a compile error, then post it verbatim.
Also, one thread is enough.
By the way
1 2 3 4 5 6 7 8
|
//char name[25];
void printEmp()
{
cout<<"Employee: ";
for (int x=0;x<26;x++) //shooting at your foot
{
cout<<name[x];
}
|
Topic archived. No new replies allowed.