Problem
Create a C++ class for an abstract data type color with a public enumeration type colorType that has the color values (black, blue, green, cyan, red, magenta, brown, lightgray, nocolor) The abstract data type should have an attribute for storing a single value of type colortype and member functions for reading (readColor) and writing (writeColor) a color value as well as setting and accessing it. The function readColor should read a color as a string and store the corresponding color value in the value attribute of a type color object. The function writeColor should display as a string the value stored in the value attribute of a type color object.
class color
{
enum colorType { black, blue, green, cyan, red, magenta, brown, lightgray, nocolor };
colorType c;
int n;
void readColor()
{
cout<<"Enter the color code";
cout<<"\n 0 for"<<" black"<<"\n 1 for"<<" blue"<<"\n 2 for"<<" green"<<"\n 3 for"<<" cyan"<<"\n 4 for"<<" red"<<"\n 5 for"<<" magenta"<<"\n 6 for"<<" brown"<<"\n 7 for"<<" lightgray"<<"\n 8 for"<<" nocolor";
cin>>n;
}
void writeColor(int a)
{
switch(a)
{
case black : cout<<"the color is black";
break;
case blue : cout<<"the color is blue";
break;
case green : cout<<"the color is green";
break;
case cyan : cout<<"the color is cyan";
break;
case red : cout<<"the color is red";
break;
case magenta : cout<<"the color is magenta";
break;
case brown : cout<<"the color is brown";
break;
case lightgray : cout<<"the color is lightgray";
break;
case nocolor : cout<<"the color is nocolor";
break;
}
}
}

New Topic/Question
Reply



MultiQuote





|