Question: #include #include #include #include #include struct ImageInfo { string filename; string type; int width; int height; double sizeKB; } ; using namespace std; int main

#include
#include
#include
#include
#include
struct ImageInfo {
string filename;
string type;
int width;
int height;
double sizeKB;
};
using namespace std;
int main()
{
ifstream inputFile("Images.txt");
if (!inputFile){
cerr << "Error: Could not open the file 'Images.txt'."<< endl;
return 1;
}
vector images;
string line;
double totalSizeKB =0.0;
while (getline(inputFile, line)){
if (line.empty()){
continue;
}
istringstream lineStream(line);
string url, md5Hash;
int sizeBytes;
lineStream >> url >> md5Hash >> sizeBytes;
size_t lastSlashPos = url.find_last_of('/');
size_t questionMarkPos = url.find('');
string filename = url.substr(lastSlashPos +1, questionMarkPos -1);
size_t dotPos = filename.find_last_of('.');
string type = filename.substr(dotPos +1);
string dimensions = url.substr(questionMarkPos +1);
size_t xPos = dimensions.find('x');
int width = stoi(dimensions.substr(0, xPos));
int height = stoi(dimensions.substr(xPos +1));
double sizeKB = sizeBytes /1024.0;
totalSizeKB += sizeKB;
images.push_back({filename, type, width, height, sizeKB});
}
cout << left << setw(35)<< "Filename" << setw(10)<< "Type" << setw(10)
<< "Width" << setw(10)<< "Height" << setw(10)<< "Size (KB)"<< endl;
cout << string(75,'-')<< endl;
for (const auto& image : images){
cout << left << setw(35)<< image.filename << setw(10)<< image.type
<< setw(10)<< image.width << setw(10)<< image.height << fixed
<< setprecision(1)<< setw(10)<< image.sizeKB << endl;
}
cout << "Total Size: "<< fixed << setprecision(1)<< totalSizeKB <<" KB"
<< endl;
inputFile.close();
return 0;
}
Can someone explain to me what this program does and break it down for me please?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!