The purpose of this assignment is to get familiar with basic C operators and data types, as well as working in a Unix environment.
Write a program that gets three positive integers in the range from 0 to 232-1 as input, converts each one to an html color code in RGB form such as rgb(3, 140, 210), and then creates a new color by taking the red value from the first input, the green value from the second input and the blue value from the third input. Display this result in rbg(red, green, blue) form, the equivalent hexademical code such as "#234A9B", and the (decimal) integer equivalent.
Each of our input values may be 4 bytes, and we need one byte (8 bits) to represent each R, G, B value (recall they are values from 0 to 255 inclusive). We will use the right most byte for Blue (bits 0-7), the next byte for Green (bits 8-15), and the third one for Red (bits 16-23), ignoring the left-most byte.
Don't forget to provide a detailed prompt for the input. The user should be able to enter the numbers in any combination with whitespace (all on one line, each on a separate line, etc.). For this part of the assignment your program only needs to process one set of input values, creating one new color from them. However, you must validate input and quit if negative or bad values are given.
Implementation Details: You may only use getchar() for input, so one component of your program must be to read characters until a whitespace is encountered, converting the digits into an integer. Also, you must use bitwise operators to split each integer into parts, not standard arithmetic operators. Lastly, you should have a few functions to organize the processing. Name your file "pg1a.c".
Grading: 5 points style & submission, 10 points functionality, 15 points implementation = 30 total. -5 points if there are any warnings using the required compilation options. 0 points if it doesn't compile (has errors, no a.out created).
This part of the assignment is an enhanced version of the first one, and must be coded as a separate stand-alone program (pg1b.c). Instead of getting only one set of three integers to combine, get an entire series of triples. You will combine them the same way as in Part A. However, this time the output must be the html tags needed to create a table with four columns. The first three columns should contain the three input values and the fourth is the combination result. In each table cell display the hexadecimal color code only, and use the bgcolor="#RRGGBB" attribute within each
You can use output redirection in Unix to save the program output to an html file and then view it in a browser. You can also use input redirection to get the triples from a plain text file instead of the keyboard.
We will have trouble reading the default black text color on darker color backgrounds when the table is displayed by a browser. Do some experimenting to figure out when to use white as the text color instead. You can use the font color tag that we used in our in-class example to change the text of a cell from black to white. Or try experimenting with bit operations (complement?) to see if you can get interesting background/foreground color combinations that way. Your resulting table needs to be readable, but the exact details of the text color for each cell may vary.
Grading: 5 points style & submission, 15 points functionality = 20 total. -5 points if there are any warnings using the required compilation options. 0 points if it doesn't compile (has errors, no a.out created).
General assignment requirements, style and submission details:
gcc -std=c99 -pedantic -Wall -Wextra -O g++ -std=c++98 -pedantic -Wall -Wextra -ORemember: you will receive NO credit for programs that do not compile. Use incremental coding to insure that you always have a working program, even though it might be incomplete.