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

The txt file is: Zip Drive 89 Warehouse C 75.89 Keyboard 133 Warehouse C 25.95 B

ID: 3876546 • Letter: T

Question

The txt file is:

Zip Drive

89

Warehouse C

75.89

Keyboard

133

Warehouse C

25.95

Blu Ray

54

Warehouse J

34.87

Iphone

110

Warehouse M

209.93

Ipod

174

Warehouse M

180.99

DVD Player

85

Warehouse J

124.91

Heat Sink

157

Warehouse C

138.45

Ext Drive

245

Warehouse C

152.87

Speakers

187

Warehouse J

163.55

Camera

147

Warehouse J

138.97

SD Card

100

Warehouse C

18.87

Router

148

Warehouse C

115.28

Printer

125

Warehouse M

145.87

Bluetuth Speakers

102

Warehouse J

19.99

Microsoft Mouse

202

Warehouse J

49.99

USB Hub

7

Warehouse M

29.99

Mousepad

119

Warehouse C

9.99

HDMI cable

23

Warehouse C

32.50

Tablet

56

Warehouse M

199.99

Create a program that will read data from a file called prog1.txt. The data will consist of the product item name, quantity, location and price for products in an inventory. You do not know how many data items there will be in the file and should read the file until no more data is found. Some strings will contain a space (use getline). All of the output for the program will go to the screen. Have the main call a function to input the data from the file progl.txt and store the data in four parallel arrays, item, qty, location and price. The max number of elements should be set to 30 utilize a globally declared named constant. However, the input function will keeps track of the number of products actually read from the file and return that count to main0. It is possible that the data file contains more than 30 items in it, handle that in your function knowing that you only have room for 30 in your arrays. The main) should: . Declare all arrays and variables needed 2. Call the ReadData function to read the data and populate the arrays a. b. c. d. Pass the arguments needed Open the file prog1.txt inside this function. Use a while loop to read data into the arrays until EOF is reached and you have room in the arrays. close the file 3. Call the BSort function to sort all four arrays from highest to lowest by quantity. (WORRY ABOUT THIS FUNCTION LAST, IN THE MEANTIME, USE A STUB) a. Use the bubble sort to sort all four arrays simultaneously using the qty array as the key 4. Call the PrintArrays function that prints the four arrays in tabular form with column headers Print the arrays in tubular form using formatting via the setw function a. 5. Call the Restock function to print each product that is under stock. A product is under stock if it has fewer than 100 items in stock. Display the product item name and quantity in tahular form. Call the HiPrice function to return the subscrint of the highest price product in stock via the return statement. Call the AverWarehouse function to return the average price for each of the three warehouses (see data). (Hint: You will 6. 7. need three sets of counters and accumulators. Lastly, the function will return all three averages via reference parameters). 8. Add code in your main to display the item name, location and price of the highest price product in stock. (Output: The highest priced item is located in warehouse with a price of $ 9. Add code in your main to display the average prices for all three warehouses.

Explanation / Answer

here is your program : -------------------->>>>>>>>>>>>

#include<iostream>
#include<fstream>
#include<string>
#define MAX 30

using namespace std;

char loc[MAX];
string item[MAX];
int quantity[MAX];
double price[MAX];

void readData(int &c){
ifstream file;
file.open("pppp.txt");
string s = "Warehouse";
string s1;
char ch;
string s2;
c = 0;
if(file.is_open()){
  while(!file.eof()){
   file>>s1;
   if(s1 == s){
    file>>loc[c];
    file>>price[c];
    file>>item[c];
    file>>quantity[c];
    c++;
   }
   if(c >= Max)
    break;
    
   s1 = "";
  }
  
  file.close();
}else{
  cout<<"file opening error check prog1.txt file";
}
}

void bubbleSort(int c){
int qtemp;
string ntemp;
ntemp.reserve(30);
double ptemp;
char ltemp;
for(int i=0; i<(c-1); i++)
{
  for(int j=0; j<(c-i-1); j++)
  {
   if(quantity[j]<quantity[j+1])
   {
    ltemp=loc[j];
    loc[j]=loc[j+1];
    loc[j+1]=ltemp;
    ntemp=item[j];
    item[j]=item[j+1];
    item[j+1]=ntemp;
    ptemp=price[j];
    price[j]=price[j+1];
    price[j+1]=ptemp;
    qtemp=quantity[j];
    quantity[j]=quantity[j+1];
    quantity[j+1]=qtemp;
   }
  }
}
}

void printArrays(int c){
cout<<" Name Location price Quantity ";
for(int i = 0;i<c;i++){
  cout<<" "<<item[i]<<" "<<"Warehouse "<<loc[i]<<" "<<price[i]<<" "<<quantity[i];
}
}

void restock(int c){
cout<<" Name Location price Quantity ";
for(int i = 0;i<c;i++){
  if(quantity[i] < 100){
   cout<<" "<<item[i]<<" "<<"Warehouse "<<loc[i]<<" "<<price[i]<<" "<<quantity[i];
  }
}
}

double Hiprice(int c){
double pr = 0;
for(int i = 0;i<c;i++){
  if(pr < price[i]){
   pr = price[i];
  }
}

return pr;
}

int main(){
int count = 0;
readData(count);
bubbleSort(count);
printArrays(count);
restock(count);
double pr = Hiprice(count);
cout<<" High price = "<<pr;
return 0;
}