Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ FORMAT Design a class called NumDays. The class’s purpose is to store a v

ID: 3730476 • Letter: I

Question

In C++ FORMAT

Design a class called NumDays. The class’s 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. The class should also have the following overloaded operators:

+ Addition operator. When two NumDays objects are added together, the overloaded + operator should return the sum of the two objects’ hours members.

- Subtraction operator. When one NumDays object is subtracted from another, the overloaded operator should return the difference of the two objects’hours members.

++ Prex and postx increment operators. These operators should increment the

number of hours stored in the object. When incremented, the number of days

should be automatically recalculated.

-- Prex and postx decrement operators. These operators should decrement the

number of hours stored in the object. When decremented, the number of days

should be automatically recalculated.

Sample Output:

Enter number of hours for the first Employee: 20

Number of days is 2.5

Enter number of hours for the second Employe: 18

Number of days is 2.25

The sum is 4.75 days or 38 hours.

The difference is 0.25 days or 2 hours.

Enter number of hours for an Employee: 24

One more hour is 25 hours or 3.125 days.

Explanation / Answer

#include <iostream>

using namespace std;
#include<iostream>
class NumDays
{
  
public:
float fun(int hours)
{
float days=hours/8;

return days;
}


};
int main()
{
int h1,h2,n1,n2,h3;
cout << "Enter number of hours for first employee:";
cin >> h1;
NumDays nd1;
nd1.fun(h1);
cout << "Number of days is:" << n1;
cout << "Enter number of hours for second employee:";
cin >> h2;
NumDays nd2;
n2=nd2.fun(h2);
cout << "Number of days is:" << n2;
cout << " ";
cout << " The Sum is" << n1+n2 << "days or" << h1+h2 << "hours";
cout << " The difference is" << ((n1>n2)?n1-n2:n2-n1) << "days or" << ((h1>h2)?h1-h2:h2-h1) << "hours";
cout << " ";
cout << "Enter number of hours for an Employee:";
cin >> h3;
cout << "One more hour is" << ++h3 << "hours or" << nd1.fun(h3) << "days";
return 0;
}