Answer:
See explaination
Explanation:
#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;
obj3=obj2-obj;
cout<<"'obj3=obj2-obj'=> Day:"<<obj3.getDay()<<"##Hour:"<<obj3.getHour()<<"\n";
obj3=obj+obj2;
cout<<"'obj3=obj+obj2'=> Day:"<<obj3.getDay()<<"##Hour:"<<obj3.getHour()<<"\n";
obj4=obj3++;
cout<<"'obj4=obj3++' => Day:"<<obj4.getDay()<<"##Hour:"<<obj4.getHour()<<"\n";
obj4=++obj3;
cout<<"'obj4=++obj3' => Day:"<<obj4.getDay()<<"##Hour:"<<obj4.getHour()<<"\n";
obj4=obj3--;
cout<<"'obj4=obj3--' => Day:"<<obj4.getDay()<<"##Hour:"<<obj4.getHour()<<"\n";
obj4=--obj3;
cout<<"'obj4=--obj3' => Day:"<<obj4.getDay()<<"##Hour:"<<obj4.getHour()<<"\n";
};