Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This assignment builds on the class hierarchy of Unit 5 Lab (see below) Inventor

ID: 3806765 • Letter: T

Question


This assignment builds on the class hierarchy of Unit 5 Lab (see below) Inventory Items description string gantityon Hand int price double Inventory Item Inventory Item (string, int double) getDescription const string getQuantityOnhand const: int get Price const double setDescription (string) void setQuantityOnhand (int) void set Price (double) void display const void read (ifstream &) void Book title string author string publisher string Book Book (string, int, double string, string string) getTitle const string get Author const: string get Publisher const string setTitle (string) void setAuthor (string) void set Publisher (string) void display const void read (ifstream &) void

Explanation / Answer

#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
using namespace std;

int main()
{
ifstream inputFile;
string filename;
string Large;
string Small;
string smallestCountry;
string largestCountry;

int num = 0;
double countrySize, num2 =-1;

cout <<" Give the file name: ";
cin >>filename;
cout <<"n";

inputFile.open(filename.c_str());

if(inputFile)
{
while (inputFile >> Small)
{
cout<< right <<setw(3) << ++num << " " << left <<setw(30) << Small;
inputFile>>countrySize;
if(num == -1)
{
num2 = countrySize;
smallestCountry = Small;
}
else if (countrySize<num)
{
num2=countrySize;
smallestCountry=Small;
}
cout<< right << setw(10) << static_cast<int>(countrySize)<<endl;
}
cout << " ";
cout << "The smallest country on the list is " << smallestCountry <<endl;
}
else
{
cout << "Error opening the file. ";
}

return 0;
}