Class 3
Class 3
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:
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.
2. TeamLeader Class
In a particular factory, a team leader is an hourly paid production worker who leads a small team. In
addition to hourly pay, team leaders earn a fixed monthly bonus. Team leaders are required to attend a
minimum number of hours of training per year. Design a TeamLeader class that extends the
ProductionWorker class you designed in Problem 1. The TeamLeader class should have member
variables for the monthly bonus amount, the required number of training hours, and the number of
training hours that the team leader has attended. Write one or more constructors and the appropriate
accessor and mutator functions for the class. Demonstrate the class by writing a program that uses a
TeamLeader object.
3. Time Format
Design a class called MilTime that is derived from the Time class below. 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.
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
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.
Contents of Time.h
// 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; }
4. Time Clock
Design a class named TimeClock. The class should be derived from the MilTime class you designed in
Problem 3. 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.
- lastName
- firstName
- address
- city
- state
- zip
- phone
Write the appropriate accessor and mutator functions for these member variables. Next, design a class
named CustomerData, which is derived from the PersonData class. The CustomerData class should
have the following member variables:
- customerNumber
- mailingList
The customerNumber variable will be used to hold a unique integer for each customer. The
mailingList variable should be a bool. It will be set to true if the customer wishes to be on a mailing
list, or false if the customer does not wish to be on a mailing list. Write appropriate accessor and mutator
functions for these member variables. Demonstrate an object of the CustomerData class in a simple
program.
6. PreferredCustomer Class
A retail store has a preferred customer plan where customers may earn discounts on all their purchases.
The amount of a customer’s discount is determined by the amount of the customer’s cumulative
purchases in the store.
- When a preferred customer spends $500, he or she gets a 5% discount on all future purchases.
- When a preferred customer spends $1,000, he or she gets a 6% discount on all future purchases.
- When a preferred customer spends $1,500, he or she gets a 7% discount on all future purchases.
- When a preferred customer spends $2,000 or more, he or she gets a 10% discount on all future
purchases.
Design a class named PreferredCustomer, which is derived from the CustomerData class you created
in Problem 5. The PreferredCustomer class should have the following member variables:
- purchasesAmount (a double )
- discountLevel (a double )
The purchasesAmount variable holds the total of a customer’s purchases to date. The discountLevel
variable should be set to the correct discount percentage, according to the store’s preferred customer
plan. Write appropriate member functions for this class and demonstrate it in a simple program.
Input Validation: Do not accept negative values for any sales figures.
Design a CargoShip class that is derived from the Ship class. The CargoShip class should have the
following members:
Demonstrate the classes in a program that has an array of Ship pointers. The array elements should be
initialized with the addresses of dynamically allocated Ship, CruiseShip, and CargoShip objects. The
program should then step through the array, calling each object’s print function.
Define a pure abstract base class called BasicShape. The BasicShape class should have the following
members:
getArea. This function should return the value in the member variable area.
Next, define a class named Circle. It should be derived from the BasicShape class. It should have the
following members:
centerX, a long integer used to hold the x coordinate of the circle’s center.
centerY, a long integer used to hold the y coordinate of the circle’s center.
constructor—accepts values for centerX, centerY, and radius. Should call the overridden
calcArea function described below.
calcArea—calculates the area of the circle (area = 3.14159 * radius * radius) and stores the
result in the inherited member area.
Next, define a class named Rectangle. It should be derived from the BasicShape class. It should have
the following members:
constructor—accepts values for width and length. Should call the overridden calcArea function
described below.
calcArea—calculates the area of the rectangle (area = length * width) and stores the result in
the inherited member area.
After you have created these classes, create a driver program that defines a Circle object and a
Rectangle object. Demonstrate that each object properly calculates and reports its area.