Description
Numeric Conversion
Overview
In this assignment you are going to read common color names and their corresponding numeric values from a group of files. One small issue: the numbers are in the wrong format. They are stored in integers, while typically color values are represented in one of two ways–either in hexadecimal form, or as their 3 separate color channels. For example, the color red might be represented like this:
0xFF0000 as hexadecimal
Red: 255, Green: 0, Blue: 0 as unsigned characters, or
Red: 1.0f, Green: 0.0f, Blue: 0.0f as floats
The integer representation of that color would be 16711680—this number is, at face value, useless. However, breaking that integer into multiple, individual pieces is often done. In this assignment, you are going to convert this not-so-helpful integer into a helpful hex value and RGB value. For more general information on color codes:
https://htmlcolorcodes.com/ https://www.w3schools.com/colors/colors_names.asp
Hexadecimal Conversion
After converting your colors to RGB, you will have to store it in a string representing the hexadecimal equivalent. Color values are often represented as hexadecimal numbers, with 2 letters each for the red, green, and blue values. Color values in character form range from 0-255, which can be stored in two hexadecimal digits, 0-FF. The color green would be 0x00FF00, blue would be 0x0000FF, a dark purple color with a value of 93, A0, 106 would be #5D006A.
Hexadecimal is base 16, which means each digit has a value from 0-15, or 0-9, then A is 10, B is 11, C, D, E, and F is 15. The first digit contributes its value to the total value of the number, the second digit contributes 161 times the value of the digit to the total of the number, and so on. For example, a value of F3 is (15∗161)+(3∗160), or 243.
Color Class
The Color class you will write for this assignment is pretty simple. You will need to store the name and hex value of the color as std::strings, and the RGB values as unsigned characters. You should have the following functions in your class. Any other supporting functions/variables you want to create are up to you.
/* Insert any other functions/data members that you want */
Sorting
After you’ve loaded the color values from the file(s), you will need to sort them alphabetically, in ascending order. There are a variety of ways to sort things, from simple sorts we’ve discussed in class (refer back to previous lecture slides/ recordings), to using std::sort (though we haven’t talked about that last option just yet).
Example Output
The output for files 1 and 2 are given so you can test your code against different sets of data. Each other file follows exactly the same format, though of the number of colors in each are different.










