simple circle class program help

Hi can someone please aid me in figuring out how I could change the color in square 1 from blue to black?
void circle::chgColor (string colS)
{
color=colS;



}
int main()
{
square 1(8,"blue",1,3);
s1.getArea();
cout<<"The first square radius is: "<<s1.Radius()<<endl;
cout<<"the color "<<s1.Color()<<endl;
cout<<"the space "<<s1.getspace()<<endl;
squaew s2;
cout<<s2.getspace()<<endl;
cout<<"The second square is: "<<s2.Radius()<<endl;
cout<<"color "<<s2.Color()<<endl;
cout<<"space "<<s2.getspace()<<endl;
Last edited on
I already created the chgColor function

Good. Then changing c1's color from "blue" to "black" would be just a matter of calling that function with "black" as the parameter.

EDIT: OP has been changed :s
Last edited on
First off, you create an object of square ( 1 ). Then refer to it as s1.

But, to change a colour, using an already made function for that, you'd do what you've already done!

1
2
3
4
5
    //Create a blue square
    square mySquare(8,"blue",1,3);

    //change it to black
    mySquare.chgColor( "black " );


You need to pass it a string, like in the function definition
void circle::chgColor (string colS);
Last edited on
Topic archived. No new replies allowed.