Question
I need help with this code program in C++ by TONIGHT! Please help, have part one done could you check that and help with other
I need help with this code program in C++ by TONIGHT! Please help, have part one done could you check that and help with other parts please.
needs to g++(compile 3 cpp files like g++ prog6.cpp timeoff.cpp numdays.cpp);
Part1 : Answer
/umdays.h header file
#include
#include
#include
using namespace std;
class NumDays
{
private:
int hours;
double days;
public:
NumDays();
NumDays(int hours);
void setHours(int);
void setDays(int);
int getHours() const;
double getDays() const;
NumDays operator - (const NumDays &) const;
NumDays operator++();
NumDays operator++(int);
friend ostream& operator
friend istream& operator >> (istream &in,const NumDays & tempdays);
};
/umdays.cpp cpp program file.
NumDays :: NumDays()
{
hours = 0;
days =0.0;
}
NumDays :: NumDays(int lhours)
{
hours = lhours;
days =(double)lhours/8;
}
void NumDays :: setHours(int lhours)
{
hours =lhours;
}
void NumDays ::setDays(int ldays)
{
days=(double)ldays;
}
int NumDays ::getHours() const
{
return hours;
}
double NumDays :: getDays() const
{
return days;
}
NumDays NumDays :: operator - (const NumDays& secondobj) const
{
NumDays obj;
obj.days = days - secondobj.days;
return obj;
}
NumDays NumDays :: operator++()
{
NumDays obj;
obj.hours = ++hours;
obj.days = (double)obj.hours/8;
return obj;
}
NumDays NumDays :: operator++(int)
{
NumDays obj;
obj.hours = hours++;
obj.days = (double)obj.hours/8;
return obj;
}
ostream& operator
{
out
return out;
}
istream& operator >> (istream &in,const NumDays & tempdays)
{
cout
in >> tempdays.days ;
//tempdays.hours = tempdays.Days * 8;
return in;
}
Mandatory Instructions This program will ulize two classes, NumDays and TimeOff These classes will then be used in client source ile. Part I: NumDavs Class Create a class called NimDay which will represent mmber of work hours and automatically convert the hours to mumber of days. For example, 8 hours would be automatically converted to 1 day, 12 bours would be converted to 1.5 days, and 18 hours would be converted to 2 Type the class declaration with data members and member fiunction prototypes into a file named numdays.h. Place all member function deinitions in a file named numdays.cpp Private data menbers: hours nt day (double) Public member functions: Default constructor -sets hours, days to zero Overloaded constructor accepts hours as parameter, automatically calculate mumber of equivalent days Mutators (setters) and accessors (getters) to set and get the hours and days values // Mutators void setHours (int) void setDays (int); // Accessors int getHours() const; double getDays() const . An overloaded operator that subtracts two objects (opentor-implemented as a member function) Ad overloaded operator (prefix and postfix version) to increment mumber of hours stored in an object. The days should be automatically NumDays operator-(const NumDays &) NumDays operator+O; NumDays int); . An Hours: h (where h is the hours operator that displays a NmDays object in the form Days: d (where d is the days private data member) -" folowed by te data member). See example below. This overload must be implemented as a non-member function. Days 20 . An overloaded operator that accepts values for a NumDays object entered as a doubie value of days (e.g, 5.25) and stores the days and hours amounts comectiy in the NiumDays object's data members (assumme 8 hours is one day). Input of 2.25 days would be stored as 18 hours. /I implemented as non-member functions friend ostrean& operatorStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started