1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sauron [17]
4 years ago
13

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. Part 2: Design a class named TimeOff. The purpose of the class is to track an employee’s sick leave, vacation, and unpaid time off. It should have, as members,
Computers and Technology
2 answers:
pickupchik [31]4 years ago
7 0

Answer:

Check the explanation

Explanation:

#include <iostream>

#include <string>

using namespace std;

//class declaration

class NumDays{

private:

   double hours;

   double days;

public:

   //constructor

   NumDays(double h = 0){

       hours = h;

       days = h/(8.00);

   }

   //getter functions

   double getHours(){

       return hours;

   }

   double getDays(){

       return days;

   }

   //setter functions

   void setHours(double h){

       hours = h;

       days = h/(8.00);

   }

   void setDays(double d){

       days = d;

       hours = d*(8.00);

   }

   //overload + operator

   double operator+ (const NumDays &right){

       return hours+right.hours;

   }

   //overload - operator

   double operator- (const NumDays &right){

       //check if subtraction will give negative value

       if(hours < right.hours){

           cout << "ERROR! Cannot subtract! Now terminating!\n";

           exit(0);

       }

       return hours-right.hours;

   }

   //overload prefix ++ operator

   NumDays operator++(){

       //pre-increment hours member

       ++hours;

       //update days member

       days = hours/(8.00);

       //return modified calling object

       return *this;

   }

   //overload postfix ++ operator

   NumDays operator++(int){

       //post-increment hours member

       hours++;

       //update days member

       days = hours/(8.00);

       //return modified calling object

       return *this;

   }

   //overload prefix -- operator

   NumDays operator--(){

       //pre-decrement hours member

       --hours;

       //update days member

       days = hours/(8.00);

       //return modified calling object

       return *this;

   }

   //overload postfix -- operator

   NumDays operator--(int){

       //post-decrement hours member

       hours--;

       //update days member

       days = hours/(8.00);

       //return modified calling object

       return *this;

   }

};

int main()

{

   //create first object

   cout << "Creating object with 12 hours...\n";

   NumDays obj1(12);

   cout << obj1.getHours() << " hours = " <<obj1.getDays() << " days.\n";

   //create second object

   cout << "\nCreating object with 18 hours...\n";

   NumDays obj2(18);

   cout << obj2.getHours() << " hours = " <<obj2.getDays() << " days.\n";

   //test overloaded + operator

   cout << endl << "Adding hours... " << obj1 + obj2 << " hours.\n";

   //test overloaded - operator

   cout << endl << "Subtracting hours... " << obj2 - obj1 << " hours.\n\n";

   //test overloaded ++ operators

   cout << "Pre- and post-incrementing first object...\n";

   ++obj1;

   cout << obj1.getHours() << " hours = " <<obj1.getDays() << " days.\n";

   obj1++;

   cout << obj1.getHours() << " hours = " <<obj1.getDays() << " days.\n";

   //test overloaded -- operators

   cout << "\nPre- and post-decrementing second object...\n";

   --obj2;

   cout << obj2.getHours() << " hours = " <<obj2.getDays() << " days.\n";

   obj2--;

   cout << obj2.getHours() << " hours = " <<obj2.getDays() << " days.\n";

   return 0;

}

Mashcka [7]4 years ago
5 0

Answer:

Sew explaination foe code

Explanation:

Code below:

#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";

};

You might be interested in
Netflix suggestions ?
hjlf

Answer:Lost in space

Explanation:It is a great space movie do not watch if your scared

3 0
3 years ago
Read 2 more answers
Select the correct answer.
Mekhanik [1.2K]
The best answer is A
5 0
3 years ago
Read 2 more answers
Which of these can expose a computer to a virus? Check all that apply.
Rina8888 [55]

Answer:

downloads, websites, emails?

4 0
3 years ago
Read 2 more answers
While all pages use HTML code, not all pages are written in
creativ13 [48]
Is this a question?

*Answer: not much information to answer with*
7 0
3 years ago
Read 2 more answers
Discuss the relationship amongst the following basic file elements: • Field. • Record. • File. • Database. • Directory.​
Gwar [14]

Answer:

describe two events from the life of the prophet that illustrate the way he treated non muslims3+15-75+375.

Explanation:

53+15-75+3756,1803+15-75+375describe two events from the life of the prophet that illustrate the way he treated non muslims

4 0
2 years ago
Other questions:
  • 1. What is the difference between a learner’s license and an operator’s license?
    10·1 answer
  • Alejandra is using a flash drive that a friend gave to her to copy some financial records from the company database so she can c
    12·1 answer
  • Your website is currently at position 5 in organic search. On a monthly basis you currently get on average 5,432 clicks and 32 c
    7·1 answer
  • Help with this chart please
    9·1 answer
  • ____ testing is a straightforward testing technique that looks for vulnerabilities in a program or protocol by feeding random in
    6·1 answer
  • 80. A .......... is used to read or write data.<br>A. CD B. VDU C. ROM D. RAM​
    6·1 answer
  • Help me guys plssssss​
    10·1 answer
  • Which of the following is NOT an example of soft skill?
    10·2 answers
  • What command in cisco IOS allows the user to see the routing table
    5·1 answer
  • The owner creator of a folder/file object has complete access to the object even when no user or group is assigned any access to
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!