Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The apex _ code.h file provides the declaration for a Cup struct. This is an abstraction for a drinking cup. It can have different sizes.
The apexcode.h file provides the declaration for a Cup struct. This is an abstraction for a drinking cup. It can have different sizes. We are making the assumption that all drinking cups come in the shape of a truncated right cone you can visualize it in the link below labeled Omni Calculator Make sure you are following the function signatures defined in apexcode.h The Cup struct defines a constructor, feel free to use it or not.
Cup::capacityInMls. This is a and the only member function of Cup and it calculates the volume of our cup in milliliters ml
Formula for calculating the volume of a truncated cone: Omni Calculator Links to an external site.
You can use cmath's definition of MPI to help with the calculations.
You will need to scope the definition in the cpp file correctly, eg Cup::
addFluid. This function is a standalone function. It takes a cup and the amount of fluid to add to it in ml
fluid could be positive or negative.
It should check to see if adding or removing the amount of fluid tofrom the cup is invalid make it overflow or less than
If invalid, the function returns false and does not update AmountOfFluid in the struct.
Otherwise, it adds the ml to the current amount of fluid held in the cup.
HINT: You can use the error checking pattern here too! The more you practice, the better.
HINT: You should reuse capacityInMls.
howFull. Also a standalone function. It computes the how full the cup currently is based on the current value of AmountOfFluid by returning the percentage of the cup that is filled with fluid.
mlPerDollar. The function calculates the milliliters of drink purchased per dollar capacity pricePerDrink In other words, given the price per drink full capacity how many milliliters of this drink can we buy with one dollar?
It has arguments:
The cup
The price per drink, and
An output.
The function checks that the price passed to it is nonnegative. Meaning, or more.
If the user provides a negative price, then the method returns false and output is not updated.
Otherwise, it sets the output to the calculations of milliliters per dollar and returns true.
HINT: You can use the error checking pattern here too! The more you practice, the better.
HINT: this is another place you should be using capacityInMls.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started