Question

C++ Create NumDays Class to store a value that represents number of hours worked and number...

C++

  • Create NumDays Class to store a value that represents number of hours worked and number of days worked. Must ensure that the two representations are always consistent.
  • Create a TimeOff Class to track an employee’s sick leave and vacation time. It should consist of the following members: maxSickDays, sickTaken, maxVacation, and vacTaken. These members should be of type NumDays. An employee, after one year of service, receives at the beginning of the year 160 hrs(20 days) of vacation time that must be taken in that year. Also received is 40 hrs(5 days) of sick leave available to be take in that year.
  • Create a TimeOff Report that starts with starts with a Time Bank that has 160 hrs of Vacation Time and 40 hrs of available Sick Leave.  

Create a scenario to use vacation and sick leave to demonstrate ALL class methods.

C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include <iostream>
using namespace std;
class NumDays
{
private:
   double hours;
   double days;
public:
   NumDays() {
       days = 0;
       hours = 0;
   }
   NumDays(double hou) {
       hours = hou;
       days = hou / 8;
   }
   // setter function
   void setHours(int hou)
   {
       hours = hou;
       days = hou / 8.0; // 8 working hours
   }
   // getter function
   double getHours() {
       return hours;
   }
   void setDays(double day) {
       days = day;
       if (hours >= 8)
       {
           days =days+ 1;
       }
   }
   double getDays() {  
       return days;
   }
};
class TimeOff {
private:

   NumDays maxSickDays;
   NumDays sickTaken;
   NumDays maxVacation;
   NumDays vacTaken;
public:
   string name;
   TimeOff(string n) {
  
   }
   void setMaxSickHours(double h)
   {
       maxSickDays.setHours(h);
   }
   void setSickTakenHours(double h) {

       sickTaken.setHours(h);

   }
   void setMaxVacationHours(double h) {
       if (h > 160) // hours cannot be more than 160
       {
           maxVacation.setHours(160);
       }
       else
       {
           maxVacation.setHours(h);
       }
   }
   void setVacationTakenHours(double h) {
       vacTaken.setHours(vacTaken.getHours() - h);
       vacTaken.setHours(h);
   }
   void setMaxSickDays(double d) {
       maxSickDays.setDays(d);
   }

   string getName() {
       return name;
   }
   double getMaxSick() {
       return maxSickDays.getHours();
   }
   double getSickTaken() {
       return sickTaken.getHours();
   }
   double getMaxVacation() {
       return maxVacation.getHours();
   }
   double getVacationTaken() {
       return vacTaken.getHours();
   }
   double getMaxSickDays() {
       return maxSickDays.getDays();
   }
   double getSickTakenDays() {
       return sickTaken.getDays();
   }
   double getMaxVacationDays() {
       return maxVacation.getDays();
   }
   double getVacationTakenDays() {
       return vacTaken.getDays();
   }

};
int main()
{
   TimeOff Employee("DANIEL");
   Employee.setMaxVacationHours(160);
   Employee.setMaxSickHours(40);
   cout<<":::::::::::::::: RECORD :::::::::::::::::::::"<<endl;
   cout << "Available vacation: " << Employee.getMaxVacation() << " hours\n";
   cout << "Available vacation: " << Employee.getMaxVacationDays() << " days\n";
   cout << "\nTake Five days of Vacation: " << endl;
  

   cout << "Available Sick : " << Employee.getMaxSick() << " hours\n";
   cout << "Available Sick: " << Employee.getMaxSickDays() << " days\n";

  
   double d;
   cout << "Enter how many vactions you want to use (Enter hours): ";
   cin >> d;
   Employee.setMaxVacationHours(Employee.getMaxVacation()-d);
   cout << "Your Available vacation: " << Employee.getMaxVacation() << " hours\n";
   cout << "Your Available vacation: " << Employee.getMaxVacationDays() << " days\n";

   double s;
   cout << "Enter how many sick leaves you want to use (Enter hours): ";
   cin >> s;
   Employee.setMaxSickHours(Employee.getMaxSick() - d);
   cout << "Your Available vacation: " << Employee.getMaxSick() << " hours\n";
   cout << "Your Available vacation: " << Employee.getMaxSickDays() << " days\n";
return 0;
}

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW
PLEASE GIVE A THUMBS UP

Add a comment
Know the answer?
Add Answer to:
C++ Create NumDays Class to store a value that represents number of hours worked and number...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Using C++, this assignment uses two classes which utilize the concept of aggregation. One class will...

    Using C++, this assignment uses two classes which utilize the concept of aggregation. One class will be called TimeOff. This class makes use of another class called NumDays. Then you will create a driver (main) that will handle the personnel records for a company and generate a report. TimeOff class will keep track of an employee’s sick leave, vacation, and unpaid time off. It will have appropriate constructors and member functions for storing and retrieving data in any of the...

  • Design a class called NumDays. The class’ purpose is to store a value that represents a...

    Design a class called NumDays. The class’ purpose is to store a value that represents a number of work hours and convert it to a number of days. For example, 8 hours would be converted to 1 day, 12 hours would be converted to 1.5 days, and 18 hours would be converted to 2.25 days. The class should have a constructor that accepts a number of hours, as well as member functions for storing and retrieving the hours and days....

  • Design a class named NumDays, to store a value that represents a number of hours and...

    Design a class named NumDays, to store a value that represents a number of hours and convert it to a number of days. For example, 24 hours would be converted to 1 day, 36 hours would be converted to 1.5 days, and 54 hours would be converted to 2.25 days. This class has two private member variables with data type double: one is named as hours; another is named as days. This class has a constructor that accepts a value...

  • Create a date class with attributes of month, day, and year. Create an employee class for...

    Create a date class with attributes of month, day, and year. Create an employee class for storing information related to employee information for the CS1C Corporation. This class should contain the employee’s name, employee’s Id, phone number, age, gender, job title, salary, and hire date. You should write a series of member functions that change the employee’s name, employee’s Id, phone number, age, job title, salary, and hire date. You should use your date class (composition) when accessing hire date....

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variable...

    Visual C# C# Visual Studio 2017 You are to create a class object called “Employee” which included eight private variables - firstN - lastN - idNum -wage: holds how much the person makes per hour -weekHrsWkd: holds how many total hours the person worked each week. - regHrsAmt: initialize to a fixed amount of 40 using constructor. - regPay - otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods: -...

  • Create a class hierarchy to be used in a university setting. The classes are as follows:...

    Create a class hierarchy to be used in a university setting. The classes are as follows: The base class is Person. The class should have 3 data members: personID (integer), firstName(string), and lastName(string). The class should also have a static data member called nextID which is used to assign an ID number to each object created (personID). All data members must be private. Create the following member functions: o Accessor functions to allow access to first name and last name...

  • Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main()...

    Create a Java file named Ch6Asg.java that contains a public class named Ch6Asg containing a main() method. Within the same file, create another class named Employee, and do not declare it public. Create a field for each of the following pieces of information: employee name, employee number, hourly pay rate, and overtime rate. Create accessor and mutator methods for each field. The mutator method for the hourly pay rate should require the value to be greater than zero. If it...

  • In C++, Create a class, ShoppingCart. Each ShoppingCart contains a count of the number of items...

    In C++, Create a class, ShoppingCart. Each ShoppingCart contains a count of the number of items in each of three categories, produce, meats, others. You will populate the counts of items in each category with the rand() function. Produce with a range of 1 -10, meats with a range of 0 - 3 and other with a range of 1 - 30. You will used the Queue or Dequeue templates from the STL to generate a queue of 10 ShoppingCarts....

  • C++ Define the class HotelRoom. The class has the following private data members: the room number...

    C++ Define the class HotelRoom. The class has the following private data members: the room number (an integer) and daily rate (a double). Include a default constructor as well as a constructor with two parameters to initialize the room number and the room’s daily rate. The class should have get/set functions for all its private data members [3pts]. The constructors and the set functions must throw an invalid_argument exception if either one of the parameter values are negative. The exception...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT