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
zhannawk [14.2K]
3 years ago
7

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:
stepladder [879]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
In a relational database, the three basic operations used to develop useful sets of data are:_________.
olga_2 [115]

In a relational database, the three basic operations used to develop useful sets of data are:

\sf\purple{a.\: Select, \:project,\: and\: join. }

\large\mathfrak{{\pmb{\underline{\orange{Mystique35 }}{\orange{❦}}}}}

6 0
3 years ago
A _______ is a computer running software that allows it to share resources over a network. it may share programs or data. select
prohojiy [21]
A _______ is a computer running software that allows it to share resources over a network. it may share programs or data.

C. Server
5 0
3 years ago
(ACCESS 2016)
galben [10]

Explanation:

rowCount() returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement executed by the corresponding PDOStatement object.

7 0
3 years ago
Read 2 more answers
How can an instance variable be used in a class? Explain your answer. (java)
melamori03 [73]

Answer:

Instantiate the object and access the variable using object reference.

Explanation:

In order to use/access an instance variable in a class, the class needs to be instantiated.For example:

class Demo{

    //Instance variable declaration

    int testvar=0;

    public static void main(String args[]){

          //Class instantiation

          Demo d = new Demo();  

          // The instance variable is accessed using the object reference

          d.testvar = 1;

    }

}

In case the instance variable in private then it can be accessed using its corresponding getter/setter methods.

7 0
3 years ago
Technological improvements have allowed people to inhabit a wider variety of places more easily. Please select the best answer f
muminat

The statement ‘Technological improvements have allowed people to inhabit a wider variety of places more easily’ is true. Technology has made our lives easier and faster. You can just buy a land or house from the developer to obtain a place you want.

9 0
3 years ago
Read 2 more answers
Other questions:
  • Write a program whose input is two integers and whose output is the two integers swapped. Place the values in an array, where x
    12·1 answer
  • (PLS HELP 99 POINTS) In a paragraph of no less than 125 words, explain the three aspects involved in gaining a true appreciation
    14·2 answers
  • For homework, we have to figure out what's in the picture. It's " too close to tell " but I can't figure out what it is. Any ide
    11·1 answer
  • In a flow chart, both the decision structure and the repetition structure use the diamond symbol to represent the condition that
    9·1 answer
  • Three broad categories of cryptographic algorithms are commonly used to create PRNGs: symmetric block ciphers, asymmetric cipher
    8·1 answer
  • 16. A
    15·1 answer
  • After reviewing device security you learn that a malicious user in an airport
    14·1 answer
  • A program is
    7·1 answer
  • To connect several computers together, one generally needs to be running a(n) ____ operating system
    6·1 answer
  • Write two eaxmple of operating system​
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!