|
ex3-9.cpp - File: ex3-9 - enums and classes |
// File: ex3-9.cpp - enums and classes
#include <iostream>
using namespace std;
enum size {small, medium, large};
class thing
{
public:
enum color {red, white, blue};
enum {FALSE, TRUE }; // anonymous enum
void setBigness(size=small);
void setHue(color=red);
size getBigness() const;
color getHue() const;
int amIBlue() const
{ if (hue == blue) return TRUE; else return FALSE; }
private:
size bigness;
color hue;
};
void thing::setBigness(size s)
{
bigness = s;
}
void thing::setHue(color c)
{
hue = c;
}
size thing::getBigness() const {
return bigness;
}
thing::color thing::getHue() const {
return hue;
}
thing::color nonMember(const thing&); // function prototype
int main() {
size S = large;
thing::color C = thing::white;
thing Big_red_thing;
Big_red_thing.setBigness(S);
Big_red_thing.setBigness(medium);
Big_red_thing.setHue();
cout << "I am"
<< (Big_red_thing.amIBlue() ? " " : " not ")
<< "blue\n";
thing Little_blue_thing;
Little_blue_thing.setBigness();
// Little_blue_thing.setHue(blue);
Little_blue_thing.setHue(thing::blue);
cout << "I am"
<< (Little_blue_thing.amIBlue() ? " " : " not ")
<< "blue\n";
Little_blue_thing.setHue(C);
cout << "I am"
<< (Little_blue_thing.amIBlue() ? " " : " not ")
<< "blue\n";
nonMember(Big_red_thing);
return 0;
}
thing::color nonMember(const thing& T) {
return T.getHue();
}
CIS27: Programming in C++ Instructor: Joe Bentley