Question
Exercise O7 Define a class named Date with three private data members named month (integer), day (integer), and year (integer) as follows: This class has
Exercise O7
Define a class named Date with three private data members named month (integer), day (integer), and year (integer) as follows:
This class has a private member function void checkDate( ) that validates a date as follows:
- The month must be an integer value from 1 to 12. - The day must be an integer value from 1 to 31.
- The year must be an integer value from 1960 to 2011.
Function checkDate( ) calls the library function exit( ) to terminate the program if any of the above conditions is not satisfied.
This class default constructor sets the month data member to 1, the day data member to 1, and the year data member to 1960: The default date is 1/1/1960.
The class constructor with parameters calls function checkDate( ) to check the date after it has set the values for the data members month, day, and year.
The class also has the following public member functions:
void inputDate( ) that reads the values for the data members month, day and year, and then calls function checkDate( ) to check the date.
void outputDate( ) that prints the date in the format: month/day/year.
int getMonth( ), int getDay( ), and int getYear( ).
These functions return the value of the month data member, the value of the day data member, and the value of the year data member respectively.
Place the definition of the class in the header file Date.h, and the definitions of the functions in the source file Date.cpp.
Note: the header files iostream, iomanip, cstdlib, and Date.h must be included in the source file Date.cpp
Exercise O9
Using the class Date that you have defined in exercise O7, write the definition of the class named Employee with the following private data members:
first name - class string (the default first name is the null string )
last name - class string (the default last name is the null string )
ID number - integer (the default ID number is 999999)
birth day - class Date (the default birth day is the default date: 1/1/1960)
date hired - class Date (the default date of hire is 1/1/20011)
base pay - double precision (the default base pay is $0.00) In addition to the constructors, the class has the following public member functions:
void readPInfo( ) that reads the values for the data members first name, last name, ID number, birth day, and date of hire.
void readPayInfo( ) that reads the value for the base pay data member.
void printPInfo( ) that outputs the values of the data members first name, last name, ID number, birth day, and date of hire.
void setBpay( double newBpay ) that sets the value of the base pay to the new value, newBpay.
double getBpay( ) that returns the value of the base pay data member.
double getGpay( ) that returns the value of the gross pay (which is the base pay).
double computeTax( ) that computes the tax deduction on the gross pay and returns it as follows:
If gross pay is greater than or equal to 1000, 20% of the gross pay;
If 800 <= gross pay < 1000, 18% of gross pay If 600 <= gross pay < 800, 15% of gross pay Otherwise, 10 % of the gross pay.
void printPayInfo( ) that outputs the gross pay, tax deduction, and net pay (gross pay - tax deduction).
Place the definition of this class in the header file Employee.h, and the definitions of the member functions in the source file Employee.cpp.
Note:
- the header files string and Date.h must be included in the header file Employee.h and the header file Employee.h must be included in the source file Employee.cpp.
- The header file Employee.h must look like the following:
#ifndef EMPLOYEE_H
#define EMPLOYEE_H
#include
using namespace std;
#include Date.h
Enter the class here
#endif
Exercise O12
Write the definition of the derived class of class Employee (that you have defined in exercise O9) named BonusEmployee as follows:
1. It has one additional private data members named bonus (double precision) with the default value $0.0.
2. In addition to the constructors, it has the public member function: double getBonus( void ) that returns the value of the data member bonus.
3. Member function void readPayInfo( ) is redefined in the class BonusEmploye: it now reads the values for the data members base pay and bonus.
4. Member function double getGpay( ) is redefined in the class BonusEmploye: it now returns the value of the data member base pay plus the value of the data member bonus.
5. Member function double computeTax( ) is redefined in the class BonusEmploye: It now calls the redefined member function getGpay( ) to get the gross pay and then computes the tax deduction in the same way as in exercise O9.
6. Member function void printPayInfo( ) is redefined in the class BonusEmploye: it now prints the values of the data members bonus and base pay, in addition to the gross pay, tax deduction, and net pay.
7. Place the definition of this class in the header file BonusEmploye.h and the definitions of the member functions in the source file BonusEmploye.cpp.
8. Note: the header file Employee.h must be included in the header file BonusEmploye.h
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started