Michael L.

asked • 05/25/22

CS161, File List Analysis, Image File Parser, C++

Instructions:

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.

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. It should then 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

  1. 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.
  2. 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.
  3. Remember, my test file will have a different number of lines.
  4. 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
  1. 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"

I need help, can somebody write out this program that reads an image.txt file like the assignment says? It really helps for me to see completed code and learn how it works from there, I had submitted this assignment a few weeks ago and had trouble with it. I need working code of this to study for final exams, thank you!



1 Expert Answer

By:

Donald W. answered • 05/25/22

Tutor
5.0 (214)

Experienced and Patient Tutor for Math and Computer Science

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.