Images
General
- All submissions must include a work history to be worth credit.
- Make sure to name files exactly as specified, including capitalization.
- Make sure your program accepts input in exactly the order and format specified. Do not ask for extra input or change the order of inputs. (If you want to make an expanded version of a program and get feedback on it, email it to me or show me in person.)
- Output the requested information in the specified order. Slight variations in output wording/formatting are usually fine, as long as formatting isn't part of the assignment. If you cannot get the right final output, print out some evidence of the work your program did to demonstrate your progress.
- Readability and maintainability of your code counts. Poor formatting, confusing variable names, unnecessarily complex code, etc. can result in deductions from your score.
Objective
Upon completion of this assignment, the student will be able to read data from a file and use string functions to process text.
Assignment Instructions
Use the BasicProject template folder.
Submit file: assign5.zip
I should be able to compile and run your program with:
g++ -std=c++17 main.cpp -o program.exe
.\program.exe (./program.exe on a mac)
Write a program that extracts information from a text file containing information about images on a website.
Your program should read from a file called "Images.txt" which will consist of an unknown number of lines. Each line consists of an image URL (web address), an MD5 hash identifying the image, and a file size in bytes. Here is what a line might look like:
http://smugmug.com/thumbs/Lacus.jpeg?170x330 44cf8edbd53cf75be874604b39a7694c 21990
Note that the URL consists of http://smugmug.com/thumbs/
followed by a
filename (Lacus.jpeg
) including extension, then a question mark and
the width (170
) and height (330
) of the image. Do not count on the extension or the
width & height being a specific length.
Make sure that you read the right input file name. Capitalization counts!
Do not use a hard-coded path to a particular directory, like "C:\Stuff\Images.txt"
.
Your code must open a file that is just called "Images.txt"
.
Here is a sample data file you can use during development. Note that this file has 5 lines, but when I test your program I will not use this exact file. You cannot count on there always being exactly 5 images. The file will end with an empty line (like the sample file). Make sure to test your program with more/fewer lines than 5.
Your program should print out a well organized table that for each image shows: the filename, image type (the file extension), the width, the height and the size in kB (1024 bytes in a kB) rounded to one decimal place. (For the layout, you can assume that no filename will be more than 30 characters long. and no other value will take up more than 6 characters of space.)
After the list of files, it should display the total size in kB of the images.
Sample output
Name Type Width Height Size Lacus.jpeg jpeg 170 330 21.5 Vel.tiff tiff 300 220 10.4 ElementumNullam.png png 1080 720 58.6 MontesNasceturRidiculus.gif gif 180 2200 101.5 AtLorem.jpeg jpeg 200 240 21.6 Total Size: 213.5
Hints
Make sure you can open the file and read something before trying to solve the whole problem. Get your copy of
Images.txt
stored in the folder with your code, then try to open it, read in the first string (http://smugmug.com/thumbs/Lacus.jpeg?170x330
), and just print it out. Until you get that working, you shouldn't be worried about anything else.Work your way to a final program. Maybe start by just handling one line. Get that working before you try to add a loop. And initially don't worry about chopping up what you read so you can print the final data, just read and print. Worry about adding code to chop up the strings you read one part at a time.
Remember, my test file will have a different number of lines.
If you need to turn a string into an int or a double, you can use this method:
string foo = "123"; int x = stoi(foo); //convert string to int string bar = "123.5"; double y = stod(bar); //convert string to double
If you need to turn an int or double into a string use
to_string()
int x = 100; string s = to_string(x); //s now is "100"