Question: Define a class named Fluid with two integer data members, gallons and pints. ( a ) Write a constructor for the class, Each data member

Define a class named Fluid with two integer data members, gallons and pints.
(a) Write a constructor for the class, Each data member defaults to 0.
(b) Write set and get functions for both data members. Your set functions should make sure that gallons is greater than or equal to 0 and pints is greater than 0 and less than 8.
Your set functions should allow cascaded calls. For example: if \( x \) is an object of the class, x.setGallons(5).setPints(3) should be enabled.
(c) Overload the \(>>\) and \(\) operators to input and output a Fluidobject in a format such as 12 ga/4pnt.
(d) Overload the + operator to enable addition of two Fluid objects. Note that pints must remain between 0 and 7.
e.g. Assume that there are two Fluid objects \( a \) and \( b \). a is 4 gallons and 5 pints and \( b \) is 6 gallons and 4 pints. The + operation should return a fluid object with 11 gallons and 1 pint instead of 10 gallons and 9 pints. (There are 8 pints in a gallon.)
(e) Provide a conversion operator function that converts a Fluid object to an integer. eg. If a is 12 gallons and 3 pints, then static_castsint>)(a) will return 12
(discard the pints part).
Write a main function to test the class.
Define a class named Fluid with two integer data

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!