Assignment Due Tonight So Close Help!

Guys, I have an assignment due by EST 11:59PM tonight. I'm so close. I posted my code below and the assignment. I'm using DEV C++. Please show me what I'm doing wrong??? I've been working at this for hours and I can't get it to work... Code is below followed by assignment.

Write a program that has base class EMPLOYEE with pure virtual function COMPENSATION, and derived classes SALARIED_EMPLOYEE and HOURLY_EMPLOYEE. For salaried , function should pay salary for up to 40 hrs and time +1/2 for hours over 40. For hourly function should pay a number of number of dollars per hour.


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
 #include <iostream>
#include <cstdlib>

using namespace std;

class Employee
{
public:
  double hour = 56 , salary = 45;

    void virtual compensation () = 0; 
};

class Salaried_employee: public Employee {
public:
     void compensation ()
    {
        double pay;
        if ( hour > 40)
            hour += hour * 1.5;
        pay = salary * hour;
        cout << "Employee salary is " << pay<<endl;
            }
    
};

class Hourly_Employee: public Employee
{
public:

    void compensation () {
     double pay;
        pay = salary * hour;
        cout << "Employee hourly rate is " << pay<<endl;
    }
    
};

int main()
{
    Salaried_employee* sal = new Salaried_employee();
    Hourly_Employee* hour = new Hourly_Employee();
    
    
    hour -> compensation();
    cout << endl;
    sal -> compensation();
    cout << endl;
    
    
    
    
    
    
    return 0;
}
No need to create objects on the heap for this.

1
2
3
4
5
6
7
8
9
10
int main()
{
    Salaried_employee sal;
    Hourly_Employee hour;
        
    hour.compensation();
    cout << endl;
    sal.compensation();
    cout << endl;
}


What does your code do that you think it shouldn't, or not do that you think it should?
Last edited on
Topic archived. No new replies allowed.