Design a class called NumDays The classs purpose is to store

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 havethe following:

member variables

hours (float)

days (float)

a default contructor

a constructor that accepts a number of hours (float)

calculate the days based on the hours

a copy constructor

while not completely necessary because of memberwise assignment, I want you to have the practice of creating one

accessors for both variables

mutators for both variables

Define all overloaded operators in the source fileaddition operator (+)

should return the sum of the two objects’ hours members

subtraction operator (-)

should return the difference of the two objects’ hours members

prefix and postfix increment operators (++)

should increment the number of hours stored in the object by one

when incremented, the number of days should be automatically recalculated

less than operator (<)

return true or false based on whether or not the current object has fewer hours than the parameter object

greater than operator (>)

return true or false based on whether or not the current object has fewer hours than the parameter object

Create a driver function to test the class. The driver function should do the following:

Create 2 NumDays objects

one object is created by the overloaded constructor

one object is created by the copy contructor

Make sure each object has a different number of hours

Print out:

the addition of the two objects

the subtraction of the two objects

the prefix increment of one of the objects

the postfix incrementation of the other object

the result of object1 < object2

the result of object1 > object2

the days of each object1 and object2

I have no clue how to do the the objects. this is what I have so far and still don\'t know if it is right at all

#include <iostream>
#include <cstring>
#include <cmath>
#include <iomanip>

using namespace std;

class NumDays
{
   private:
       float hours;
       float days;

   public:      
       NumDays();
       //constructors
       NumDays()
       {
           hours = 0;
           days = 0;

       }
       NumDays(float h)
       {
           hours = h;
           days = h / 8;
       }
       void setHours(float h) //holds number of hours
       {
           hours=h;
           days = h / 8;
       }
       float getHours() const
       {
           return hours;
       }
       void setDays(float d)
       {
           days = d;
           hours = d / 8;
       }
       float getDays() const
       {
           return days;
       }
       NumDays operator + (NumDays &d) //overloads increment
       {
           NumDays total;
           total.setHours(this->getHours() + d.getHours());
           return total;
       }
       NumDays operator - (NumDays &d)
       {
           NumDays total;
           total.setHours(this->getHours() - d.getHours());
           return total;
       }
       NumDays &operator ++()
       {
           this->setHours(this->getHours() + 1);
           return *this;
       }
       const NumDays operator ++ (int)
       {
           NumDays total = *this;
           this->setHours(this->getHours() + 1);
           return total;
       }
       if (hours > days)
  
};

can you please help with it all

Solution

Your coding try was good, and I\'ve provided the code for the above situation.

------------------------------------------------------------------------------------------------------------------------------------------------------------------

-------------------------------------------------------------------------------------------------------------------------------------------------------------------------

NumDays.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

main.cpp

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

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
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
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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site