Help me rewrite the second constructor so it works properly.

I had to write this for a class and its not working rite. I am having trouble passing the const char through it.

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);


this is what I had to have.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
class Employee
{
public:
  Employee();
  Employee( const char [], int, double );
    
  void printEmp();
  void increaseSalary( double );

  void setIDnum( int );
  void setSalary( double );

  int getIDnum();
  double getSalary();

private:
  char name[25];
  int idNum;
  double salary;
};

and this is what it said the constructor should do.
"The default constructor (the constructor that takes no arguments) for the class should initialize the data members so that name hold "None," idNum holds 1000, and salary holds 0. Use the setIDnum and setSalary methods to initialize the identification number and salary, respectively (this will help to guard against invalid initial values). Use the strcpy function to initialize the name.

The other constructor for the class should initialize the data members using the passed in arguments. It takes 3 arguments: a constant character array with an employee name, an integer employee identification number, and a double that holds the employee salary. Use the setIDnum and setSalary methods to initialize the identification number and salary, respectively (this will help to guard against invalid initial values). Use the strcpy function to initialize the name."
Last edited on
You already have a topic open for this problem, why did you open a new one?

http://www.cplusplus.com/forum/beginner/190665/
so i can add the last little bit to explain what its supposed to do
Topic archived. No new replies allowed.