Using Classes

I am having trouble constructing one of my header files in my program. I'll provide the rest of the code so you can see what I am ultimately trying to do. I'll put documentation to show what I want each class/function to accomplish.
Thank you.

// one of my header files
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
#include <string>

using namespace std;

/**
   A basic employee class that is used in many examples
   in the book "Computing Concepts with C++ Essentials"
*/
class Employee
{
public:
   /**
      Constructs an employee with empty name and no salary.
   */
   Employee();
   /**
      Constructs an employee with a given name and salary.
      @param employee_name the employee name
      @param initial_salary the initial salary
   */
   Employee(string employee_name, double initial_salary);
   /**
      Sets the salary of this employee.
      @param new_salary the new salary value
   */
   void set_salary(double new_salary);
   /**
      Gets the salary of this employee.
      @return the current salary
   */
   double get_salary() const;
   /**
      Gets the name of this employee.
      @return the employee name
   */
   string get_name() const;
private:
   string name;
   double salary;
};

#endif 


// the other header file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#ifndef PROGRAMMER_H
#define PROGRAMMER_H

#include <string>
#include "ccc_empl.h"

using namespace std;

class Programmer : public Employee
{
public:
   Programmer(string name, double salary);
   string get_name() const;
};

#endif 


// main program
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

#include "programmer.h"

int main()
{  
   Programmer harry("Hacker, Harry", 45000.00);

   double new_salary = harry.get_salary() + 3000;
   harry.set_salary(new_salary);

   cout << "Name: " << harry.get_name() << "\n";
   cout << "Salary: " << harry.get_salary() << "\n";

   return 0;
}
You have to have functions for the class.
Topic archived. No new replies allowed.