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

#include<iostream> #include<iomanip> #include<string> #include<vector> #include<

ID: 3634198 • Letter: #

Question

#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<fstream>

using namespace std;

void sortInput( int count, vector<int>& itemID, vector<string>& itemName, vector<int>& ordered, vector<int>& inStore, vector<int>& sold, vector<double>& mPrice, vector<double>& sPrice );

int getInput ( istream& inp, vector<int>& itemID, vector<string>& intemName, vector<int>& ordered, vector<int>& inStore, vector<int>& sold, vector<double>& mPrice, vector<double>& sPrice);

char displayMenu ();
void sellAnItem (vector<int> & itemID, vector<int>& inStore, vector<int> & solf, int count);
void printReport ( vector<int>& itemID, vector<string> itemName, vector<int> ordered, vector<int> inStore, vector<int> sold, vector<double> mPrice, vector<double> sPrice,int count );

int maint()
{

char fileName [ 15 ];
vector<int> itemID;
vector<string> itemName;
vector<int> ordered;
vector<int> inStore;
vector<int> sold;
vector<double> mPrice;
vector<double> sPrice;
int count;
char choice;

cout<<" Program that work with functions "
<< " Vectors and files.";

cout<<" Enter the name of input file: ";
cin>>fileName;

ifstream inFile (fileName);

if (! inFile )
{
cout<<" Error in opening input file";
return 1 ;
}

count = getInput ( inFile, itemID, itemName, ordered, inStore, sold, mPrice, sPrice );

do
{
choice = displayMenu();

if ( choice == '1' )

sellAnItem ( itemID, inStore , sold, count );

if (choice == '2')
printReport (itemID, itemName, ordered, inStore, sold, mPrice, sPrice, count );
} while ( choice !='3');

inFile.close();
inFile.clear();

return 0;
}

int getInput ( istream& inp, vector<int>& itemID, vector<string>& itemName, vector<int>& ordered, vector<int>& inStore, vector<int>& sold, vector<double>& mPrice, vector<double>& sPrice)
{

int myInt, count = 0;
string str = "";
char ch;
double myDouble;

do

if (( inp >> myInt ) == NULL )
break;
itemID.push_back ( myInt);

inp.get(ch);
getline( inp, str);
itemName.push_back(str );

inp >> myInt;
ordered.push_back(myInt);
inStore.push_back(myInt);
sold.push_back(0);

inp>> myDouble;
mPrice.push_back(myDouble);

inp>> myDouble;
sPrice.push_back(myDouble);

count++;

}
while (true);

sortInput ( count, itemID, itemName, ordered, inStore, sold, mPrice, sPrice );


return count;
}

void sortInput ( int count, vector<int>& itemID,vector<string>& itemName, vector<int> & ordered, vector<int>& inStore, vector<int>& sold, vector<double> & mPrice, vector<double>& sPrice)
{

int myInt, min;
string tr = "";
double myDouble;

for (int i = 0; i < count - 1; itt)
{
min = i;

for ( int j = i+1; j < count; j++)
if ( itemName[j].compare(itemName[min])< 0 )
min= j;

if ( min != i )
{
myInt = itemID [ i ];
itemID [ i ] = itemID [ min ];
ItemID[ min ] = myInt;

itemName [ i ]. swap ( itemName [ min ]);

myInt = ordered [ i ];
ordered [ i ] = ordered [ min ];
ordered [ min ] = myInt;

myInt = instore [ i ];
inStore[ i ] inStore [ min ];
instore[ min ] = myInt;

myInt = sold [ i ];
sold[ i ] sold [ min ];
sold[ min ] = myInt;

myDouble = mPrice[i ];
mPrice[ i ] = mPrice [ min];
mPrice[ min ] = myDouble;

myDouble = sPrice[i ];
sPrice[ i ] = sPrice [ min];
sPrice[ min ] = myDouble;

}

}
}

char displayMenu()
{
char choice;

cout<<" M E N U ";
cout<< " -----------------------";
cout<<" Sell an item : 1";
cout<< " Print a report : 2";
cout<< " Quit : 3";
cout<<" "tEnter your choice :" ";

cin>> choice;

return tolower ( choice);
}
void sellAnItem(vector<int> & itemID, vector<int>& inStore, vector<int>& sold, int count)
{
int i, n , quantity;

cout<< " Enter item-ID number: ";
cin>>n;

for ( i = 0; i < count; i++)
if(itemID[i ] == n )
break;

if( i != count)
{
cout<< " Enter quantity : ";
cin>>quantity;

if (quantity > inStore [ i ] )
cout<< " Stock is not available. ";
else {
inStore[i ] -= quantity;
sold[ i ] += quantity;
cout<< " " << quantity
<<" it is sold out.";
}

else
cout<<" Specified item was not founf in the store";
}

void printReport ( vector<int> itemID,vector<string> itemNamw, vector<int> ordered, vector <int> instore, vector<int> sold, vector<double> mPrice, vector<double> sPrice, int count)
{
double inventory = 0;
int items = 0;

cout<< " Chaz's Hardware Store";
cout<< " ItemID Item Name"
<< "pOrdered pInstore pSold "
<< "manuPrice sellingPrice";

cout<< fixed;
cout.precision(2);

for( int i = 0; i < count i++)
{
inventory += inStore [ i ] * sPrice [ i ];
items += inStore[ i ];
cout<<" "
<<setw(6) << right<< itemID [ i ] <<" "
<<setw(15) << left << itemName [ i ]
<< setw(10)<<right<< ordered[i]
<<setw(10)<< right<< inStore[ i ]
<<setw(7) << right<< sold [ i ]
<<setw(12) << right << mPrice [ i ]
<<setw(13) << right << sPrice[ i ];
}

cout <<" Total inventory: $ "<< inventory;
cout << " Total number of items in the store; "
<< items;
}

please help make sure compiles

Explanation / Answer

#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<fstream>

using namespace std;

void sortInput(int count, vector<int>& itemID, vector<string>& itemName, vector<int>& ordered, vector<int>& inStore, vector<int>& sold, vector<double>& mPrice, vector<double>& sPrice);
int getInput(istream& inp, vector<int>& itemID, vector<string>& itemName, vector<int>& ordered, vector<int>& inStore, vector<int>& sold, vector<double>& mPrice, vector<double>& sPrice);
char displayMenu();
void sellAnItem(vector<int>& itemID, vector<int>& inStore, vector<int>& sold, int count);
void printReport(vector<int> itemID, vector<string> itemName, vector<int> ordered, vector<int> inStore, vector<int> sold, vector<double> mPrice, vector<double> sPrice, int count);

int main()
{
   char fileName[15];
   vector<int> itemID;
   vector<string> itemName;
   vector<int> ordered;
   vector<int> inStore;
   vector<int> sold;
   vector<double> mPrice;
   vector<double> sPrice;
   int count;
   char choice;

   cout << " Program that work with functions "
        << " Vectors and files.";

   cout << " Enter the name of input file: ";
   cin >> fileName;

   ifstream inFile(fileName);

   if (!inFile)
   {
      cout << " Error in opening input file ";
      return 1 ;
   }

   count = getInput(inFile, itemID, itemName, ordered, inStore, sold, mPrice, sPrice);

   do
   {
      choice = displayMenu();

      if (choice == '1')
         sellAnItem(itemID, inStore , sold, count);

      if (choice == '2')
         printReport(itemID, itemName, ordered, inStore, sold, mPrice, sPrice, count);
   }
   while (choice != '3');

   inFile.close();
   inFile.clear();

   return 0;
}

int getInput(istream& inp, vector<int>& itemID, vector<string>& itemName, vector<int>& ordered, vector<int>& inStore, vector<int>& sold, vector<double>& mPrice, vector<double>& sPrice)
{
   int myInt, count = 0;
   string str = "";
   char ch;
   double myDouble;

   do
   {
      if ((inp >> myInt) == NULL)
         break;
      itemID.push_back(myInt);

      inp.get(ch);
      getline(inp, str);
      itemName.push_back(str);

      inp >> myInt;
      ordered.push_back(myInt);
      inStore.push_back(myInt);
      sold.push_back(0);

      inp >> myDouble;
      mPrice.push_back(myDouble);

      inp >> myDouble;
      sPrice.push_back(myDouble);

      count++;
   }
   while (true);

   sortInput(count, itemID, itemName, ordered, inStore, sold, mPrice, sPrice);

   return count;
}

void sortInput(int count, vector<int>& itemID,vector<string>& itemName, vector<int>& ordered, vector<int>& inStore, vector<int>& sold, vector<double>& mPrice, vector<double>& sPrice)
{
   int myInt, min;
   string tr = "";
   double myDouble;

   for (int i = 0; i < count - 1; i++)
   {
      min = i;

      for (int j = i + 1; j < count; j++)
         if (itemName[j].compare(itemName[min]) < 0)
            min= j;

      if (min != i)
      {
         myInt = itemID[i];
         itemID[i] = itemID[min];
         itemID[min] = myInt;

         itemName[i].swap(itemName[min]);

         myInt = ordered[i];
         ordered[i] = ordered[min];
         ordered[min] = myInt;

         myInt = inStore[i];
         inStore[i] = inStore[min];
         inStore[min] = myInt;

         myInt = sold[i];
         sold[i] = sold[min];
         sold[min] = myInt;

         myDouble = mPrice[i];
         mPrice[i] = mPrice[min];
         mPrice[min] = myDouble;

         myDouble = sPrice[i];
         sPrice[i] = sPrice[min];
         sPrice[min] = myDouble;
      }
   }
}

char displayMenu()
{
   char choice;

   cout <<" M E N U ";
   cout << " -----------------------";
   cout <<" Sell an item : 1";
   cout << " Print a report : 2";
   cout << " Quit : 3";
   cout <<" Enter your choice :";

   cin >> choice;

   return tolower(choice);
}

void sellAnItem(vector<int>& itemID, vector<int>& inStore, vector<int>& sold, int count)
{
   int i, n , quantity;

   cout << " Enter item-ID number: ";
   cin >>n;

   for (i = 0; i < count; i++)
      if(itemID[i] == n)
         break;

   if (i != count)
   {
      cout << " Enter quantity : ";
      cin >> quantity;

      if (quantity > inStore[i])
         cout << " Stock is not available. ";
      else
      {
         inStore[i] -= quantity;
         sold[i] += quantity;
         cout << " " << quantity
              << " it is sold out.";
      }
   }
   else
      cout << " Specified item was not founf in the store";
}

void printReport(vector<int> itemID,vector<string> itemName, vector<int> ordered, vector<int> inStore, vector<int> sold, vector<double> mPrice, vector<double> sPrice, int count)
{
   double inventory = 0;
   int items = 0;

   cout << " Chaz's Hardware Store";
   cout << " ItemID Item Name"
        << "pOrdered pInstore pSold "
        << "manuPrice sellingPrice";

   cout << fixed;
   cout.precision(2);

   for(int i = 0; i < count; i++)
   {
      inventory += inStore [ i ] * sPrice [ i ];
      items += inStore[ i ];
      cout<<" "
      << setw(6) << right << itemID[i] << " "
      << setw(15) << left << itemName[i]
      << setw(10) << right << ordered[i]
      << setw(10) << right << inStore[i]
      << setw(7) << right << sold[i]
      << setw(12) << right << mPrice[i]
      << setw(13) << right << sPrice[i];
   }

   cout << " Total inventory: $ " << inventory;
   cout << " Total number of items in the store; "
        << items;
}