5752105 [rkeene@sledge /home/rkeene/personal/school/comp-sci-ii/lab1]$ cat -n employee.cpp
 1 //                      employee.cpp


 2 //


 3 // Employee class hierarchy using inheritance


 4 // The Employee is the base class for subclasses manager, scientist,


 5 // and laborer, and laborer is the base class for a subclass foreman.


 6 

 7 // Taken from LaFore, Robert. 1996. "C++ Interactive Course",


 8 // Corte Madera, CA:  The Waite Group, Inc. p. 398-402. 


 9 //


10 #include "employee.h"


11 

12 void 

13 Employee::getData()

14 {

15     cout << "Enter last name:";

16     cin >> name;

17     cout << "Enter number: ";

18     cin >> number;

19     cin.ignore(80,'\n');

20 }

21 

22 void  

23 Employee::putData()

24 {

25     cout << "Name = " << name << endl;

26     cout << "Number = " << number << endl;

27 }

28 

29 void 

30 Manager::getData ()

31 {

32     Employee::getData();

33     cout << "Enter title: ";

34     cin >> title;

35     cout << "Enter golf club dues: ";

36     cin >> dues;

37     cin.ignore(80,'\n');

38 }

39 

40 void 

41 Manager::putData()

42 {

43     Employee::putData();

44     cout << "Title = " << title << endl;

45     cout << "Golf club dues = " << dues << endl;

46 }

47 

48 

49 void 

50 Scientist::getData ()

51 {

52     Employee::getData();

53     cout << "Enter number of publications: ";

54     cin >> numberPubs;

55     cin.ignore(80,'\n');

56 }

57 

58 void 

59 Scientist::putData()

60 {

61     Employee::putData();

62     cout << "Number of publications = " << numberPubs << endl;

63 }

64 

65 void 

66 Laborer::getData ()

67 {

68     Employee::getData();

69     cout << "Enter number of hours worked this week:";

70     cin >> numberHours;

71     cin.ignore(80,'\n');

72 }

73 

74 void

75 Laborer::putData()

76 {

77     Employee::putData();

78     cout << "Number of hours worked this week = " << numberHours << endl;

79 }

80 

81 void 

82 Foreman::getData ()

83 {

84     Laborer::getData();

85     cout << "Enter quotas as a percentage: ";

86     cin >> quotas;

87     cin.ignore(80,'\n');

88 }

89 

90 void 

91 Foreman::putData()

92 {

93     Laborer::putData();

94     cout << "Quotas: " << quotas << "%" << endl;

95 }
5752106 [rkeene@sledge /home/rkeene/personal/school/comp-sci-ii/lab1]$

Click here to go back to the directory listing.
Click here to download this file.
last modified: 2002-08-29 03:27:33