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
AveGali [126]
3 years ago
12

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.
++ prefix and postfix increment operators. These operators should increment the number of hours stored in that object. When incremented, the number of days should automatically be recalculated.
-- Prefix and postfix decrement operators. These operators should decrement the number of hours stored in that object. When decremented, the number of days should automatically be recalculated.
Computers and Technology
1 answer:
Afina-wow [57]3 years ago
3 0

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

};

You might be interested in
How do open online courses help with independent learning? (1 point)
Dominik [7]

I personally have online courses, A. seems like a fitting choice in my opinion. I hope this helps.

4 0
3 years ago
Read 2 more answers
It is an island country; it fought against us in World War II; it is known for sushi.
aivan3 [116]

Answer:

The country is Japan

5 0
3 years ago
Read 2 more answers
(PLEASE HELP)
Harman [31]

Answer:ummm ok

Explanation:

4 0
2 years ago
How do you resolve conflicts in your life??
amm1812

Answer:

What problems?

Explanation:

6 0
2 years ago
What are four differences between tablets and smartphones?
Oksi-84 [34.3K]

Answer:

1. tablets are less portable than smartphones

2. smartphones are considered necessities and tablets are considered luxuries

3. smartphones are personal devices; tablets are usually shared

4. Tablets have larger screens for more extensive use of applications as opposed to the smaller, less versatile mobile phone screens.

8 0
2 years ago
Read 2 more answers
Other questions:
  • why is there a need of properly interpreting teacher's/manufacturer's specifications before operating any food processing equipm
    9·1 answer
  • Which statements accurately describe the Bookmark feature in the Audio/Video control bar? Check all that apply.
    13·1 answer
  • Please someone helpp
    12·2 answers
  • Match the component to its function. resistor inductor capacitor battery transistor This component stores a temporary charge. ar
    7·2 answers
  • Does this mechanism increase or decrease speed? Why?
    9·1 answer
  • Although your project has been accepted by the customer, the contract with the system vendor specifies that it will support the
    13·1 answer
  • use the internet to research the SYSTEM account. Why is it nessesary to include this account with full control on a directory
    13·1 answer
  • A university with remote campuses, which all use different service providers, loses Internet connectivity across all locations.
    12·1 answer
  • Random.choice will choose a number between 1 and 100. True False​
    6·1 answer
  • Create a program that prompts the user for a positive integer then prints a right-aligned pyramid using that number using the st
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!