Programming and Graphics

(Kiana) #1

168 Introduction to C++ Programming and Graphics


void print() const;
void shift(double string);
private:
double x;
string color;
string setcolor(float);
};

The algebra class implementation is:


//--- CLASS IMPLEMENTATION

algebra::algebra() // default constructor
{
x=0.0;
color = "white";
}

//---

algebra::algebra(double valuex) // parametered constructor
{
x=valuex;
color = setcolor(x);
}

//---

string algebra::setcolor(float x) // set the color:
{
string color;
if(x>eps)
color="black";
else if(x<-eps)
color="red";
else
color="white";
return color;
}

//---

double algebra::get(string& color) const
{
chroma=color;
return x;
}

//---
Free download pdf