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

////// I need help with this program . it has to be done in c++ and strictly fol

ID: 3720013 • Letter: #

Question

////// I need help with this program . it has to be done in c++ and strictly follow the instractions./////

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:

• The addition operator +. The number of hours in the sum of two objects is the

sum of the number of hours in the individual objects.

• The subtraction operator - . The number of hours in the difference of two objects X

and Y is the number of hours in X minus the number of hours in Y.

• Prefix and postfix increment operators ++. The number of hours in an object is

incremented by 1.

• Prefix and postfix decrement operators --. The number of hours in an object is

decremented by 1.

Explanation / Answer

Hi,

Please find my working code.

//Thanks for coming
#include <iostream>
using namespace std;
class NumDays{
int hours;
float day;
public:

NumDays()
{
   hours=0;
   day=0.0;
};

NumDays(int h)
{
   hours=h;
   day=float(h/8.0);
};

int getHour()
{
   return hours;
}

float getDay()
{
   return day;
}

NumDays operator +(NumDays obj)
{
   int h=getHour()+obj.getHour();
   NumDays temp(h);
   return temp;
}

NumDays operator -(NumDays obj)
{
   int h=getHour()-obj.getHour();
   NumDays temp(h);
   return temp;
}

const NumDays& operator++() //prefix
{
       ++hours;
       day=float(hours/8.0);
       return *this;
}
const NumDays& operator--() //prefix
{
       --hours;
       day=float(hours/8.0);
       return *this;
}


const NumDays operator++(int) //postfix
{
   NumDays temp(*this);
       ++hours;
      day=float(hours/8.0);
       return temp;
}
const NumDays operator--(int) //postfix
{
   NumDays temp(*this);
       --hours;
      day=float(hours/8.0);
       return temp;
}

};


int main()
{
NumDays obj(2),obj2(10),obj3,obj4;
cout<<"obj:=>Day:"<<obj.getDay()<<"##Hour:"<<obj.getHour()<<" ";
cout<<"obj2:=>Day:"<<obj2.getDay()<<"##Hour:"<<obj2.getHour()<<" ";
obj3=obj2-obj;
cout<<"'obj3=obj2-obj'=> Day:"<<obj3.getDay()<<"##Hour:"<<obj3.getHour()<<" ";
obj3=obj+obj2;
cout<<"'obj3=obj+obj2'=> Day:"<<obj3.getDay()<<"##Hour:"<<obj3.getHour()<<" ";
obj4=obj3++;
cout<<"'obj4=obj3++' => Day:"<<obj4.getDay()<<"##Hour:"<<obj4.getHour()<<" ";
obj4=++obj3;
cout<<"'obj4=++obj3' => Day:"<<obj4.getDay()<<"##Hour:"<<obj4.getHour()<<" ";
obj4=obj3--;
cout<<"'obj4=obj3--' => Day:"<<obj4.getDay()<<"##Hour:"<<obj4.getHour()<<" ";
obj4=--obj3;
cout<<"'obj4=--obj3' => Day:"<<obj4.getDay()<<"##Hour:"<<obj4.getHour()<<" ";

};