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 would you compare and contrast the impact of the printing press with the impact of the internet?
Ilia_Sergeevich [38]
<span>The impact of the printing press with the impact of the internet is that </span>internet is an easy access compared with the printing press. Changes affect society, there are more ways to access info today through the internet.  internet spreads information faster and can be shared quickly.  
4 0
2 years ago
Does anyone know how to write this right? This is for a coding class and I’m super confused on it.
vovangra [49]

Answer:

This is using c++ syntax, you might need to make slight adjustment for other languages.

First activity:

string firstSnack = "chips";

string secondSnack = "pizza";

string thirdSnack = "apples";

string bestSnack =  firstSnack;

bestSnack = secondSnack;

Second activity:

double apple = 0.5;

double banana = 0.75;

double orange = 1.43;

double total = apple + banana + orange;

Explanation:

When first declaring a variable, you want to specify the type (such as int, double, string, bool, etc.) and then the name. You can set the variable value in the declaration, or you can set it to a value later in the program by not having the equals sign and whatever comes next.

4 0
2 years ago
Expressions provide an easy way to perform operations on data values to produce other data values. True False
Papessa [141]

Expressions provide an easy way to perform operations on data values to produce other data values, True.

<h3>What is an Expression? </h3>

An expression is a combination of one or more operands (Constant, Variable, Array element, Function), operators(Multiplication,Division, Subtraction etc) to be interpreted by a programming language following rules of precedence or association to produce other data values.

Three kinds of expressions includes:

  • An arithmetic expression

  • A character expression

  • A logical or relational expression

Therefore, it is true that Expressions provide an easy way to perform operations on data values to produce other data values.

6 0
2 years ago
Which is better? iPhone 11 Pro Max or Samsung Galaxy Note 20 Ultra 5G and why?
Allisa [31]

Answer:

Samsung note 20 or iPhone but i think Samsung

Explanation:

8 0
3 years ago
Read 2 more answers
What are source data entry devices​
matrenka [14]

Answer:

<u><em>Source data entry devices are used for audio input, video input and to enter the source document directly to the computer. Source data entry devices do not require data to be typed-in, keyed-in or pointed to a particular location.</em></u>

Explanation:

7 0
2 years ago
Other questions:
  • What is the difference between a learner’s license and an operator’s license?
    5·1 answer
  • Which of the following is the BEST example of a strong password. Question 8 options: brian12kate5 chEwbAccAp!zza w3st! 123abccba
    10·2 answers
  • Consider two sets S1 and S2 of size 3 and 2 each.
    13·1 answer
  • Pressing the e key while in edit mode will exit the interaction mode<br><br> true<br><br> false
    7·1 answer
  • Provide the definition for each of the following structures and unions:
    8·1 answer
  • ON QUIZ PLEASE HELP
    13·1 answer
  • Katy and her associates are approached by an aged tai chi expert to create a website for him. From her participation in an onlin
    9·1 answer
  • Create a program that simulates a race between several vehicles. Design and implement an inheritance hierarchy that includes Veh
    11·1 answer
  • Please answer that and i'll gave you branlliest
    15·1 answer
  • How many dlcs in total were in each black ops game (including dlc weapons) answer for 25 whole points
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!