// Write the function definitions for each of the function members of the Color
ID: 3762944 • Letter: #
Question
// Write the function definitions for each of the function members of the Color class.
//--------------------------------------------------------------------------------------------------------------
// CTOR: Color::Color()
//
// DESCRIPTION:
// Initializes the color to black by initializing mRed, mGreen, and mBlue to 0, 0, and 0.
//
// PSEUDOCODE:
// Call init() passing 0, 0, 0 as the arguments.
//--------------------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------------------
// CTOR: Color::Color()
//
// DESCRIPTION:
// Initializes the color initializing mRed, mGreen, and mBlue to pInitRed, pInitGreen, and pInitBlue.
//
// PSEUDOCODE:
// Call init() passing pInitRed, pInitGreen, and pInitBlue as the arguments.
//--------------------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: getBlue()
//
// DESCRIPTION:
// Accessor function for the mBlue data member.
//
// PSEUDOCODE:
// Return mBlue
//--------------------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: getGreen()
//
// DESCRIPTION:
// Accessor function for the mGreen data member.
//
// PSEUDOCODE:
// Return mGreen
//--------------------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: getRed()
//
// DESCRIPTION:
// Accessor function for the mRed data member.
//
// PSEUDOCODE:
// Return mRed
//--------------------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: setBlue()
//
// DESCRIPTION:
// Mutator function for the mBlue data member.
//
// PSEUDOCODE:
// mBlue <- pNewBlue
//--------------------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: setGreen()
//
// DESCRIPTION:
// Mutator function for the mGreen data member.
//
// PSEUDOCODE:
// mGreen <- pNewGreen
//--------------------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: setRed()
//
// DESCRIPTION:
// Mutator function for the mRed data member.
//
// PSEUDOCODE:
// mRed <- pNewRed
//--------------------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: toString()
//
// DESCRIPTION:
// Returns a string representation of this Color in the form "(mRed, mGreen, mBlue)". For example, if mRed = 12,
// mGreen = 100, and mBlue = 212, then this function would return the string "(12, 100, 212)".
//
// PSEUDOCODE:
// Define a stringstream object named sout
// Send to sout "(" getRed() ", " getGreen() ", " getBlue() ")"
// Return sout.str()
//--------------------------------------------------------------------------------------------------------------
???
//--------------------------------------------------------------------------------------------------------------
// FUNCTION: init()
//
// DESCRIPTION:
// Initializes the data members to the parameters by calling the mutator functions.
//
// PSEUDOCODE:
// setRed(pInitRed)
// setGreen(pInitGreen)
// setBlue(pInitBlue)
//--------------------------------------------------------------------------------------------------------------
???
Explanation / Answer
public partial class frmColorPicker
{
private int mRed;
private int mGreen;
private int mBlue;
}
private void frmColorPicker_Load(object sender, System.EventArgs e)
{
mRed = 0;
mGreen = 0;
mBlue = 0;
pnlColor.BackColor = System.Drawing.Color.FromArgb(mRed, mGreen, mBlue);
txtWebColor.Text = GetWebColor();
txtRGB.Text = "RGB(" + mRed + ", " + mGreen + ", " + mBlue + ")";
}
private void tbarRed_Scroll(System.Object sender, System.EventArgs e)
{
txtRed.Text = tbarRed.Value.ToString();
mRed = tbarRed.Value;
pnlColor.BackColor = System.Drawing.Color.FromArgb(mRed, mGreen, mBlue);
txtWebColor.Text = GetWebColor();
txtRGB.Text = "RGB(" + mRed + ", " + mGreen + ", " + mBlue + ")";
}
private void txtRed_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if (char.IsNumber(e.KeyChar) || e.KeyChar == ControlChars.Back)
{
}
else
{
e.KeyChar = System.Convert.ToChar(0);
}
}
private void txtRed_TextChanged(object sender, System.EventArgs e)
{
try
{
if (Convert.ToInt32(txtRed.Text) >= 0 && Convert.ToInt32(txtRed.Text) <= 255)
{
tbarRed.Value = Convert.ToInt32(txtRed.Text);
mRed = tbarRed.Value;
pnlColor.BackColor = System.Drawing.Color.FromArgb(mRed, mGreen, mBlue);
txtWebColor.Text = GetWebColor();
txtRGB.Text = "RGB(" + mRed + ", " + mGreen + ", " + mBlue + ")";
}
else
{
txtRed.Text = mRed.ToString();
}
}
catch (Exception)
{
}
}
private string GetWebColor()
{
Color clr;
clr = Color.FromArgb(mRed, mGreen, mBlue);
string wc = ColorTranslator.ToHtml(clr).ToString();
return wc;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.