Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Employee and ProductionWorker Classes
- Design a class named Employee . The class should keep the following information in
- • Employee name
- • Employee number
- • Hire date
- Write one or more constructors and the appropriate accessor and mutator functions
- for the class.
- Next, write a class named ProductionWorker that is derived from the Employee class.
- The ProductionWorker class should have member variables to hold the following
- information:
- • Shift (an integer)
- • Hourly pay rate (a double )
- The workday is divided into two shifts: day and night. The shift variable will hold an
- integer value representing the shift that the employee works. The day shift is shift 1, and
- the night shift is shift 2. Write one or more constructors and the appropriate accessor
- and mutator functions for the class. Demonstrate the classes by writing a program that
- uses a ProductionWorker object.
- Class for next question
- // Specification file for the Time class
- #ifndef TIME_H
- #define TIME_H
- class Time
- {
- protected:
- int hour;
- int min;
- int sec;
- public:
- // Default constructor
- Time()
- { hour = 0; min = 0; sec = 0; }
- // Constructor
- Time(int h, int m, int s)
- { hour = h; min = m; sec = s; }
- // Accessor functions
- int getHour() const
- { return hour; }
- int getMin() const
- { return min; }
- int getSec() const
- { return sec; }
- };
- #endif
- 4. Time Format
- In Program 15-20 , the file Time.h contains a Time class. Design a class called MilTime
- that is derived from the Time class. The MilTime class should convert time in military
- (24-hour) format to the standard time format used by the Time class. The class should
- have the following member variables:
- milHours : Contains the hour in 24-hour format. For example, 1:00 pm would be
- stored as 1300 hours, and 4:30 pm would be stored as 1630 hours.
- milSeconds : Contains the seconds in standard format.
- The class should have the following member functions:
- Constructor : The constructor should accept arguments for the hour and seconds, in
- military format. The time should then be converted to standard time
- and stored in the hours , min , and sec variables of the Time class.
- setTime : Accepts arguments to be stored in the milHours and milSeconds
- variables. The time should then be converted to standard time and
- stored in the hours , min , and sec variables of the Time class.
- getHour : Returns the hour in military format.
- getStandHr : Returns the hour in standard format.
- Demonstrate the class in a program that asks the user to enter the time in military format.
- The program should then display the time in both military and standard format.
- Input Validation: The MilTime class should not accept hours greater than 2359, or less
- than 0. It should not accept seconds greater than 59 or less than 0.
- 5. Time Clock
- Design a class named TimeClock . The class should be derived from the MilTime class
- you designed in Programming Challenge 4. The class should allow the programmer to
- pass two times to it: starting time and ending time. The class should have a member
- function that returns the amount of time elapsed between the two times. For example,
- if the starting time is 900 hours (9:00 am), and the ending time is 1300 hours (1:00
- pm), the elapsed time is 4 hours.
- Input Validation: The class should not accept hours greater than 2359 or less than 0.
- 1. Date Exceptions
- Modify the Date class you wrote for Programming Challenge 1 of Chapter 13 . The
- class should implement the following exception classes:
- InvalidDay Throw when an invalid day (< 1 or > 31) is passed to the class.
- InvalidMonth Throw when an invalid month (< 1 or > 12) is passed to the class.
- Demonstrate the class in a driver program.
- 2. Time Format Exceptions
- Modify the MilTime class you created for Programming Challenge 4 of Chapter 15 .
- The class should implement the following exceptions:
- BadHour Throw when an invalid hour (< 0 or > 2359) is passed to the class.
- BadSeconds Throw when an invalid number of seconds (< 0 or > 59) is passed
- to the class.
- Demonstrate the class in a driver program.
- 3. Minimum/Maximum Templates
- Write templates for the two functions minimum and maximum . The minimum function
- should accept two arguments and return the value of the argument that is the lesser
- of the two. The maximum function should accept two arguments and return the value
- of the argument that is the greater of the two. Design a simple driver program that
- demonstrates the templates with various data types.
- 4. Absolute Value Template
- Write a function template that accepts an argument and returns its absolute value. The
- absolute value of a number is its value with no sign. For example, the absolute value of
- 5 is 5, and the absolute value of 2 is 2. Test the template in a simple driver program.
- 5. Total Template
- Write a template for a function called total . The function should keep a running
- total of values entered by the user, then return the total. The argument sent into the
- function should be the number of values the function is to read. Test the template in
- a simple driver program that sends values of various types as arguments and displays
- the results.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement