virtual inheritance

some of the output for this program is missing, after everything the name address, Date, etc The Pay is the most important,It is supposed to out put everything and I did something very wrong. any ideas? I will submit the code too.


Hourly Employee class
Enter name:bob
Enter Address:1234 any
Enter phone no:Enter day:
6
Enter month:
9
Enter year:
2010
Enter day:
6
Enter month:
9
Enter year:
2000
Enter number of hours:
40
Enter hourly pay rate:
15.00
ID:Name:Address:Phone:HireDate:
Birth Date:
9/6/20009/6/2010PAY:
Salaried employee class
Enter name:
This is the code I wrote:

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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include <iostream >
using namespace std;
// Member function definitions for Date class.
class Date
{
    public:
    Date(){} // default constructor
    void setDate();
    void print() const; // print date in month/day/year format
    
    private:
    int month; // 1-12
    int day; // 1-31 based on month
    int year; // any year
    // utility function to test proper day for month and year
    int checkDay( int ) const;
};
void Date::setDate()
{
    int mn,dy,yr;
    cout<<"Enter day:\n";
    cin>>dy;
    cout<<"Enter month:\n";
    cin>>mn;
    cout<<"Enter year:\n";
    cin>>yr;
        if ( mn > 0 && mn <= 12 ) // validate the month
            month = mn;
        else {
            month = 1;
            cout << "Month\n " << mn << " invalid. Set to month 1.\n";
}
    year = yr >= 1900 && yr <= 2100 ? yr : 1990;
    day = checkDay( dy ); // validate the day
}

// Utility function to confirm proper day value
// based on month and year.
int Date::checkDay( int testDay ) const
{
    int daysPerMonth[ 13 ] = { 0, 31, 28, 31, 30, 31, 30,
    31, 31, 30, 31, 30, 31 };
    
    if ( testDay > 0 && testDay <= daysPerMonth[ month ] )
        return testDay;
    
    if ( month == 2 && // February: Check for possible leap year
        testDay == 29 &&
        ( year % 400 == 0 || (year % 4 == 0 && year % 100 != 0 ) ) )
    
        return testDay;
        cout << "Day " << testDay << " invalid. Set to day 1.\n";

    return 1; // leave object in consistent state if bad value
}

// Print Date object in form month/day/year
void Date::print() const
{ 
    cout << month << '/' << day << '/' << year; }

class Employee
{
    private:
    int ID;

    public:
    char name[80];
    char address[80];
    char phone[80];
    Date birthDate;
    Date hireDate;
    Employee(int id);
    int GetID();
    virtual double getMonthsPay() = 0;
};


Employee::Employee(int id)
{
    ID=id;
    cout<<"Enter name:";
    cin>>name;
    fflush(stdin);
    cout<<"Enter Address:";
    cin>>address;
    cout<<"Enter phone no:";
    cin>>phone;
    birthDate.setDate();
    hireDate.setDate();
}
int Employee::GetID()
{
    return ID;
}



class SalariedEmployee : public Employee
{
    public:
    double salary;
    double getMonthsPay();
        SalariedEmployee(int id);
};
SalariedEmployee::SalariedEmployee(int id):Employee(id)
{
    if(id!=0){
        cout<<"Enter salary:\n";
        cin>>salary;}
    

}
double SalariedEmployee::getMonthsPay()
{
    return salary;
}



class HourlyEmployee : public Employee
{
    public:
    double hours;
    double hourlyRate;
    double getMonthsPay();
        HourlyEmployee(int id);
};
HourlyEmployee::HourlyEmployee(int id):Employee(id)
{
    cout<<"Enter number of hours:\n";
    cin>>hours;
    cout<<"Enter hourly pay rate:\n";
    cin>>hourlyRate;
}
    double HourlyEmployee::getMonthsPay()
{
    return hours*hourlyRate;
}

    /* All outsourced employees have an ID code of zero
    and are paid a flat salary rate of $20/month. */
class OutsourcedEmployee : public SalariedEmployee
{
    public:
    double getMonthsPay();
        OutsourcedEmployee();
};
OutsourcedEmployee::OutsourcedEmployee():SalariedEmployee(0){}
    double OutsourcedEmployee::getMonthsPay()
{
    return 20;
}



void main()
{
    //Hourly Employee class
    cout<<"Hourly Employee class\n"; //creating object
    
    HourlyEmployee emp1(23);

    //outputting employee datails
    cout<<"ID:"<<"Name:"<<"Address:"
        <<"Phone:\n"<< "HireDate:\n"<< "Birth Date:\n";

    emp1.hireDate.print();
    emp1.birthDate.print();
    emp1.GetID();
        
        cout<<"PAY:\n"; //Salaried employee class


        cout<<"Salaried employee class\n"; //creating object

    SalariedEmployee emp2(143);

    cout<<"ID:"<<"Name:"<<"Address:"<<"Phone:"<<"HireDate:\n";

    emp2.hireDate.print();

        cout<<"PAY:\n"; //Outsourced Employee class

    OutsourcedEmployee emp3;

        cout<<"ID:"<<"Name:"<<"Address:"<<"Phone:"<<"HireDate:\n";

    emp3.hireDate.print();

        cout<<"PAY:\n"; //pause system for a while

        //system("pause");

}//end main 
Topic archived. No new replies allowed.