Answered step by step
Verified Expert Solution
Link Copied!

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 apex_code.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 apex_code.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 M_PI to help with the calculations.
You will need to scope the definition in the .cpp file correctly, e.g. 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 to/from the cup is invalid (make it overflow or less than 0).
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 3 arguments:
The cup
The price per drink, and
An output.
The function checks that the price passed to it is non-negative. Meaning, 0 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.
image text in transcribed

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

Students also viewed these Databases questions

Question

What is a web crawler? What is it used for? How does it work?

Answered: 1 week ago

Question

Why? What will be my payoff?

Answered: 1 week ago