cs102 lab9
http://www.maths.nuigalway.ie/~gettrick/teach/cs102/labs/l9.html
-
For this lab you must submit all source code (python
files), and, if applicable, the result(s) of running the program on (a few)
test cases. This should be sent in via BLACKBOARD (not directly by email).
The source code must
be well presented (indenting, spaces, reasonable variable/function names,
etc.) and must include comments (as a rough guideline - aim to have nearly as
many comments as lines of code). Any questions asked should be answered by
typing the answers into the relevant box on the BLACKBOARD upload form.
-
This material should be uploaded
before
the deadline of 5pm
Friday March 22nd., 2013. You will lose 20% for each day
(or part of day) the lab is late.
-
Plagiarism (the unattributed copying of work from other sources
(internet, fellow students,....)) will not be tolerated. Please see
http://www.nuigalway.ie/engineering/documents/plagiarism_guide_students
_v4.pdf. You risk getting zero for your lab if it is found to be
plagiarized.
We would like to model a mug/cup as a cylindrical vessel with an open top. The mug
will have a fixed total capacity (the volume of a cylinder, C=PI*r**2*h), and at
any given time a certain amount of liquid will be in it (varying from 0 to C) at a certain
temperature. Thus,
the state of the cup at any given time
can be represented by four parameters, its
radius,
height,
current volume of liquid and
the temperature of the liquid.
Write a class in python to represent the mug.
The class should have
-
A constructor (__init__) to create a mug of a certain radius and height. By default set
the volume of liquid in the mug to be zero at the start, and its temperature to be 20 degrees.
-
A method that returns the volume of liquid currently in the mug. (Note: All lengths should
be in centimetres, and volumes in milliliters: 1 cubic centimetre equals 1 milliliter.)
-
A method that returns the capacity of the mug.
-
A method that tells the user "how full" (in percentage terms) the cup is.
-
A method that adds a certain volume (say V1) of liquid at a certain temperature (say
T1). If there is currently some (other) liquid volume V2 in the mug at
temperature T2, you should set the final liquid temperature to be
(V1*T1 + V2*T2)/(V1 + V2).
If the volume of liquid being added does not fit in the cup, you should of course warn the
user (and... let them chose between cancelling the operation or just filling it to capacity).
-
A method that removes ("pours out") a certain volume of liquid from the mug (again... if the
volume requested for removal is greater than the current volume, the user should have the
option of cancelling the operation or emptying all the mug).
-
A "fill to brim" method that fills the mug to its capacity (with the same liquid/temperature
as is currently in the mug). This method must call the method you have written in (5.).
All your methods, the constructor, and the class itself, should have appropriate
docstrings.
You should test your methods well (by calling them from the main program), to make
sure they work as planned.
©
NUI, Galway