User Tools

Site Tools


haas:fall2011:cprog:projects:colorithmetic

Color Arithmetic

In C++, write a Color class that accomplishes the following:

  • Has the following Public: member functions:
    • Color() constructor
    • Color(string) parametered constructor that accepts a string color
    • display() accessor method that returns the string of the current color
    • overload the + operator to allow the addition of two Color class instances
    • overload the - operator to allow the subtraction of two Color class instances
  • Has the following Private: member functions:
    • value: an integer that corresponds to the current color
    • shade: a string that corresponds to the current color

To “add” or “subtract” colors, look to actual color combinations:

  • Red, Yellow, and Blue are primary colors
  • Orange, Green, and Purple are secondary colors
  • White is the presence of all colors
  • Black is the absence of all colors

Might there be some mathematical relationship between the colors, so that we can apply numerical values to aid us in our processing?

With the completion of your Color class, write a small application program (ie a main()) that instantiates a few Color objects.

With this program, do the following:

  • Instantiate at least 3 color objects
  • Set two of them to various colors
  • Add two colors together (using the + operator), and store the result in the third color
  • Subtract two colors (using the - operator), and store the result in another color
  • Display the colors going into various operations, and the resulting color after the operation has taken place.
haas/fall2011/cprog/projects/colorithmetic.txt · Last modified: 2011/08/22 16:36 by 127.0.0.1