Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++. Design a class called DaysWorked. The class's purpose is to store a value mHours that could be evaluated in terms of days of work.

C++.

Design a class called DaysWorked. The class's purpose is to store a value mHours that could be evaluated in terms of days of work. For example: - 8 hours are actually 1 day of work - 12 hours are 1.5 days of work - 18 hours are 2.25 days of work The class should have a default constructor, and an overloaded constructor that accepts a number of hours. The class should also have the following overloaded operators: - + The addition operator: When two DaysWorked objects are added together, this operator should return a new object that has mHours equal to the sum of the two objects mHours. - - The subtraction operator: When two DaysWorked objects are subtracted, this operator should return a new object that has mHours equal to the difference between the two objects mHours. - ++ Prefix and postfix increment operators: These operators should increment the number of hours in the object. When incremented, the number of days of work should be recomputed. - -- Prefix and postfix decrement operators: These operators should decrease the number of hours in the object. When decremented, the number of days of work should be recomputed. - << cout stream insertion operator: This operator should display to the screen all objects data in a clear fashion. - >> cin stream extraction operator: This operator should prompt the user to enter all the object's data in a clear fashion. - == equality comparison operator: This operator should return true if both objects have equal mHours member variables - [] subscript operator: This operator should return days if subscript is 0, hours if subscript is 1, and error out a message otherwise.

The below driver program should display the following output:

int main() {

DaysWorked lObjOne; DaysWorked lObjTwo; cin >> lObjOne; cin >> lObjTwo; DaysWorked lObjThree = lObjOne + lObjTwo; cout << endl << "lObjThree = lObjOne + lObjTwo: " << endl; cout << lObjThree; DaysWorked lObjFour(10); lObjOne = lObjThree - lObjFour; cout << endl << "lObjOne = lObjThree - lObjFour: " << endl; cout << lObjOne; cout << "lObjOne[0]: " << lObjOne[0] << endl; cout << "lObjOne[1]: " << lObjOne[1] << endl; cout << "lObjFour = lObjOne++: " << endl; lObjFour = lObjOne++; cout << lObjOne; cout << lObjFour; cout << "lObjFour = ++lObjOne: " << endl; lObjFour = ++lObjOne; cout << lObjOne; cout << lObjFour; cout << "lObjFour = lObjOne--: " << endl; lObjFour = lObjOne--; cout << lObjOne; cout << lObjFour; cout << "lObjFour = --lObjOne: " << endl; lObjFour = --lObjOne; cout << lObjOne; cout << lObjFour; if (lObjFour == lObjOne) cout << "lObjFour is equal to lObjOne" << endl; else cout << "lObjFour is NOT equal to lObjOne" << endl; system("PAUSE"); return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 22nd International Conference Dexa 2011 Toulouse France August/September 2011 Proceedings Part 1 Lncs 6860

Authors: Abdelkader Hameurlain ,Stephen W. Liddle ,Klaus-Dieter Schewe ,Xiaofang Zhou

2011th Edition

3642230873, 978-3642230875

More Books

Students also viewed these Databases questions

Question

Assess the impact of aging on memory.

Answered: 1 week ago

Question

1. Explain the 2nd world war. 2. Who is the father of history?

Answered: 1 week ago