i Hope i did this right

I am writing my code in c++. i am not sure if i did this right :

Write a complete class implementation (no main function necessary) according to the following requirements.
--The class is called “Worker”.
--It has 3 private members: name (char type), age (integer type), salary(double type).
--It has two constructors: one has no arguments and it initializes name with 'C', age with 20, and salary with 100.00; the other takes two arguments (char char1, int var_age) and it initializes name with char1’s value, age with var_age’s value, and salary with 200.00.
--The class also has a member function access which outputs name’s value, age’s value, and salary’s value to screen.
--The class has a friend function overloading operator == so that it will return true when comparing two objects of the same class Worker. For example, if wk1 and wk2 are two objects of class Worker and their 3 private members are same, (wk1= =wk2) will return true.

here is what i done so far:
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
#include <iostream>
#include <string>
using std::string;
#ifndef WORKER_H
#define WORKER_H
using namespace std;
class Worker
{
public:
 
         Worker();
         Worker(char, int);
         friend bool operator==( Wrk&1, Wrk&2);
         char getName();
         int  getAge();
         double getSalary();
         
private:
        char Name;
        int Age;
        double Salary;
};

Worker::Worker()
{
        Name = 'C';
        Age = 20;
        Salary = 100.00;

}

 Worker::Worker()
{
}

  Worker::Worker(char char1, int var_age)
{

        Name = char1;
        Age = var_age;
        Salary = 200.00;
        
}

bool operator==( Wrk&1, Wrk&2)
{

	if(( x.getName() == y.getName()) &&  ( x.getAge() == y.getAge()) &&
           ( x.getSalary() == y.getSalary() ) )
        return true;
        return false;
}



char Worker::getName()
{
	return Name;
}

int Worker::getAge()
{
	return Age;
}
double Worker::getSalary()
{
	return Salary;
}

corrections:

1. Worker::Worker()
{
}
this should be a destructor and looks like:

Worker::~Worker()
{
}

declare it in the class also.

2. friend bool operator==( Wrk&1, Wrk&2); this should be like this:
friend bool operator==( Worker& Wrk1, Worker& Wrk2);

similarly see the definition of this. and that function replace x and y with Wrk1 and Wrk2 as x and y are nothing.

3. no need of this: using std::string;

4. rest looks fine.
2. should be
1
2
3
friend bool operator==( const Worker& w1, const Worker& w2 ) {
   // ...
}


(constness is important when dealing with references)

Topic archived. No new replies allowed.