due Tuesday, March 23rd, 1:30 pm
This assignment is not accepted late.
The goal of this assignment is to give you practice using the Standard Template Library, bitmaps, SFML, and lambda functions. The assignment consists of reading a binary file, storing the data in a map of bitset, flipping bits, moving the data to a vector, loading the vector into an image, loading the image into a texture, using the texture to create a sprite, and displaying the sprite in a RenderWindow. You will need to do some SFML research into how to create an image and how to work with type color Color. Use the sample output as checks to make sure you are proceeding correctly. Your output should look like that that shown below (including formatting).
The input file consists of pairs of unsigned int. Open the input file and count the number of records in the file without reading every record. You'll need to know (save) the number of records in the file.
Read the file and display the first 5 records and the last 5.
Read the file and store the data in a map with an unsigned key and an unsigned value. Note: you will have to pay attention to the way the pairs of unsigned int are stored.
Print the first 5 and the last five elements of the map (this is a good place to use a lambda function).
Copy the map values into a vector of bitset<32>.
Print elements 12058 to 12062 of the vector.
Flip the bits in each element of the vector. Print elements 12058 to 12062 of the vector again.
Print elements 12058 to 12062 of the vector again as unsigned int.
Create an SFML image of size 400 x 400 (you may need some research here).
Load the vector bitset data into the image pixels (you may need some more research and you may have to convert the bitsets to unsigned int or sf::Uint32).
Create a texture using your image.
Create a sprite using your texture.
Display your sprite. You will know if you did this correctly. If it is not oriented correctly, you may have to switch your rows and columns or your x's and y's, or your first and second.
window(sf::VideoMode(400, 400), "Assignment 7");
sf::Image image; // step 9
// load the bitset data into the image pixels (step 10)
... ? ...
sf::Texture texture; // step 11
sf::Sprite sprite(texture); // step 12
if (event.type == sf::Event::Closed)
// Add non-event handling code here
window.draw(sprite); // step 13
records = 160000
Original input data
Vector data (records 12058 to 12062) <=== Step 6
Vector data after bit flip (records 12058 to 12062) <=== Step 7
Vector data as unsigned (records 12058 to 12062) <=== Step 8
Your code should be "perfect" - some documentation, no warnings unless they are originated by SFML, use "good" practices.
Your code should contain two or more lambda functions.
Do not write a multiple file application - all of your code should be contained in one file.
Use iterator loops or algorithms for the map. You may use index loops for the vector.