Assignment 4, due Thursday February 17 at noon.

You must submit your program electronically via gsubmit on csa.

Under no circumstances will late assignments be accepted.

The code you submit must conform with the programming guidelines.


Program Description

Write and submit one file called cup.cpp.

In this file, implement all member functions of the following class:

class Cup
{
public:
    Cup();
    Cup(double cup_radius, double cup_height);
    bool add_liquid(double vol);
    bool remove_liquid(double vol);
    double get_radius() const;
    double get_height() const;
    double volume() const;
    double percent_full() const;
    void operator>>(Cup &b);
private:
    double radius;
    double height;
    double volume_of_liquid;
};

In this assignment, use the class definition header file: cup.h.

The class represents a cylindrical cup that can be filled with liquid. You implement the following member functions:

  1. Cup() -- default constructor.  Use default radius = 1, height = 1.
  2. Cup(double cup_radius, double cup_height) -- constructor with values for radius and height. If illegal value(s) are specified, then use default values radius = 1, height = 1.
  3. bool add_liquid(double vol) -- if vol > 0 and there is enough space available in the cup, then add the vol of liquid to the cup and return true.  Otherwise, do not add liquid and return false.
  4. bool remove_liquid(double vol) -- if the requested volume of liquid is positive, and it is contained in the cup, then subtract vol from the cup and return true. Otherwise, do not subtract vol and return false.
  5. double get_radius() const, double get_height() const-- return cup radius and height respectively.
  6. double volume() const -- returns cup total volume PI*height*radius*radius.
  7. double percent_full() const-- returns percentage of cup volume occupied by liquid.  The value returned should be in the range 0.0 to 1.0.   For instance if the cup is half full, then this function returns the value 0.5.
  8. void operator>>(Cup& b) -- transfers as much liquid to cup b as will fit in its remaining volume.
Hints: In both constructors, initialize volume_of_liquid = 0.  

Notes: You are responsible for testing your own code.  As in previous assignments, we will compile your cup.cpp and link it with our standard test program. Your function should have no side-effects (other than those specified above).  Your function must compile without warnings on CSA using the g++ compiler, with flags -Wall -ansi

Grading Criteria

Refer to the grading criteria file: p4.criteria


Academic Honesty and Collaboration

Cooperation is recommended in understanding various concepts and system features. But the actual solution of the assignments, the programming and debugging must be your individual work, except for what you specifically credit to other sources. (Your grade will be based on your own contribution.) For example, copying without attribution any part of someone else's program is plagiarism, even if you modify it and even if the source is a textbook. The University takes acts of cheating and plagiarism very seriously: first time violators are routinely suspended for a semester.