Here is a simple C++ problem.
Imagine that this was a bitmap:
Code:
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBYYYYYYYYBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBYYYYYYYYBBBBYYYYYYYYBBBBBBBBBBBBBB
BBBBBBBBBBBBBBYYRRRRYYBBBBYYYYYYYYBBBBYYYYYYYYBB
BBBBBBBBBBBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYYYYYYYBB
BBBBBBBBBBBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBB
BBBBBBBBBBBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBB
BBYYYYYYYYBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBB
BBYYYYYYYYBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBB
BBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBB
BBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBB
BBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBB
BBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBB
BBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBBBBYYRRRRYYBB
Each letter represents a pixel in the bitmap. The colors blue, red, and yellow are labeled by the letters 'B', 'R', and 'Y' respectively. If you use your imagination, you can see that the bitmap shows a bar graph. As seen, the color yellow is used to outline each of the 4 rectangular bars. It makes a straight line which is 2 pixels thick, and which encloses the tops and sides of all the bars. The color Red fills the inside of the bars, while the color Blue fills the rest of the bitmap.
From the above bitmap picture, if we count each letter as a pixel, then we can say that:
BitMap Height = 16 pixels
BitMap Width = 48 pixels
Nuber of Bars = 4
Hieght of bars = 7, 13, 12, 11 in pixels
Start of First Bar = 2 (pixels between the left margin and the bar)
Bar Thickness = 8 pixels
Bar Separation = 4 pixels
Thickness of Yellow Outline = 2 pixels
What is required to be done:
- Given parameters like the ones shown above, create a new bitmap picture and choose your own representation of it.
- Next, save the pixels in your bitmap picture to a file. Preseve the order of the pixels but do not save any line breaks.
- For each pixel, save 4 bytes to the file. For Red, save 0x00FF0000. For Blue, save 0x0000FF00. And for Yellow, save 0x000000FF. Thus each pixel will be represented by its 4-byte set.
- Save the stream of pixels to a .bmp file.
- Use as few line of code as you can
- Start by using the following parameters:
BitMap Height = 1024
BitMap Width = 1280
Nuber of Bars = 34
Hieght of Bars =
27, 413, 14, 1111, 100, 888, 27, 413, 14, 1111,
456, 234, 874, 108, 576, 345, 207, 295, 356, 467,
100, 888, 244, 333, 777, 444, 122, 39, 590, 1000,
222, 777, 999, 854
Start of First Bar = 24
Bar Thickness = 26
Bar Separation = 10
Thickness of Yellow Outline = 8
The parameters are valid because the following conditions are true:
Code:
Maximum Hieght of Bars < BitMap Height ==> 1111 < 1024
Minimum Hieght of Bars > Thickness of Yellow Outline ==> 14 > 8
Bar Thickness > (2 * Thickness of Yellow Outline) ==> 26 > 8
Drawing width of all bars < BitMap Width ==> Start of First Bar + (Bar Thickness * Nuber of Bars) + (Bar Separation * (Nuber of Bars - 1)) < BitMap Width
==> 24 + (26 * 34) + (10 * (34 - 1)) < 1280
Note : Find an implementation that suits you .