Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.13 KB | None | 0 0
  1. 1. Employee and ProductionWorker Classes
  2. Design a class named Employee . The class should keep the following information in
  3. • Employee name
  4. • Employee number
  5. • Hire date
  6. Write one or more constructors and the appropriate accessor and mutator functions
  7. for the class.
  8. Next, write a class named ProductionWorker that is derived from the Employee class.
  9. The ProductionWorker class should have member variables to hold the following
  10. information:
  11. • Shift (an integer)
  12. • Hourly pay rate (a double )
  13. The workday is divided into two shifts: day and night. The shift variable will hold an
  14. integer value representing the shift that the employee works. The day shift is shift 1, and
  15. the night shift is shift 2. Write one or more constructors and the appropriate accessor
  16. and mutator functions for the class. Demonstrate the classes by writing a program that
  17. uses a ProductionWorker object.
  18.  
  19.  
  20. Class for next question
  21.  
  22. // Specification file for the Time class
  23. #ifndef TIME_H
  24. #define TIME_H
  25.  
  26. class Time
  27. {
  28. protected:
  29. int hour;
  30. int min;
  31. int sec;
  32. public:
  33. // Default constructor
  34. Time()
  35. { hour = 0; min = 0; sec = 0; }
  36.  
  37. // Constructor
  38. Time(int h, int m, int s)
  39. { hour = h; min = m; sec = s; }
  40.  
  41. // Accessor functions
  42. int getHour() const
  43. { return hour; }
  44.  
  45. int getMin() const
  46. { return min; }
  47.  
  48. int getSec() const
  49. { return sec; }
  50. };
  51. #endif
  52.  
  53.  
  54. 4. Time Format
  55. In Program 15-20 , the file Time.h contains a Time class. Design a class called MilTime
  56. that is derived from the Time class. The MilTime class should convert time in military
  57. (24-hour) format to the standard time format used by the Time class. The class should
  58. have the following member variables:
  59. milHours : Contains the hour in 24-hour format. For example, 1:00 pm would be
  60. stored as 1300 hours, and 4:30 pm would be stored as 1630 hours.
  61. milSeconds : Contains the seconds in standard format.
  62. The class should have the following member functions:
  63. Constructor : The constructor should accept arguments for the hour and seconds, in
  64. military format. The time should then be converted to standard time
  65. and stored in the hours , min , and sec variables of the Time class.
  66. setTime : Accepts arguments to be stored in the milHours and milSeconds
  67. variables. The time should then be converted to standard time and
  68. stored in the hours , min , and sec variables of the Time class.
  69. getHour : Returns the hour in military format.
  70. getStandHr : Returns the hour in standard format.
  71. Demonstrate the class in a program that asks the user to enter the time in military format.
  72. The program should then display the time in both military and standard format.
  73. Input Validation: The MilTime class should not accept hours greater than 2359, or less
  74. than 0. It should not accept seconds greater than 59 or less than 0.
  75.  
  76.  
  77. 5. Time Clock
  78. Design a class named TimeClock . The class should be derived from the MilTime class
  79. you designed in Programming Challenge 4. The class should allow the programmer to
  80. pass two times to it: starting time and ending time. The class should have a member
  81. function that returns the amount of time elapsed between the two times. For example,
  82. if the starting time is 900 hours (9:00 am), and the ending time is 1300 hours (1:00
  83. pm), the elapsed time is 4 hours.
  84. Input Validation: The class should not accept hours greater than 2359 or less than 0.
  85.  
  86.  
  87.  
  88.  
  89.  
  90. 1. Date Exceptions
  91. Modify the Date class you wrote for Programming Challenge 1 of Chapter 13 . The
  92. class should implement the following exception classes:
  93. InvalidDay Throw when an invalid day (< 1 or > 31) is passed to the class.
  94. InvalidMonth Throw when an invalid month (< 1 or > 12) is passed to the class.
  95. Demonstrate the class in a driver program.
  96.  
  97.  
  98. 2. Time Format Exceptions
  99. Modify the MilTime class you created for Programming Challenge 4 of Chapter 15 .
  100. The class should implement the following exceptions:
  101. BadHour Throw when an invalid hour (< 0 or > 2359) is passed to the class.
  102. BadSeconds Throw when an invalid number of seconds (< 0 or > 59) is passed
  103. to the class.
  104. Demonstrate the class in a driver program.
  105.  
  106.  
  107. 3. Minimum/Maximum Templates
  108. Write templates for the two functions minimum and maximum . The minimum function
  109. should accept two arguments and return the value of the argument that is the lesser
  110. of the two. The maximum function should accept two arguments and return the value
  111. of the argument that is the greater of the two. Design a simple driver program that
  112. demonstrates the templates with various data types.
  113.  
  114.  
  115. 4. Absolute Value Template
  116. Write a function template that accepts an argument and returns its absolute value. The
  117. absolute value of a number is its value with no sign. For example, the absolute value of
  118. 5 is 5, and the absolute value of 2 is 2. Test the template in a simple driver program.
  119.  
  120.  
  121. 5. Total Template
  122. Write a template for a function called total . The function should keep a running
  123. total of values entered by the user, then return the total. The argument sent into the
  124. function should be the number of values the function is to read. Test the template in
  125. a simple driver program that sends values of various types as arguments and displays
  126. the results.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement