Using a State Member
The Vector class stores both the rectangular coordinates and the polar coordinates for a vector. It uses a member called mode
to control which form the constructor, the reset()
method, and the overloaded operator<<()
function use, with the enumerations RECT
representing the rectangular mode (the default) and POL
the polar mode. Such a member is termed a state member because it describes the state an object is in. To see what this means, look at the code for the constructor:
Vector::Vector(double n1, double n2, Mode form){ mode = form; if (form == RECT) { x = n1; y = n2; set_mag(); set_ang(); } else if (form == POL) { mag = n1; ang = n2 / Rad_to_deg; set_x(); ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.