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

C++ data.txt 300 450 500 210 510 600 750 400 627 100 420 430 530 621 730 530 200

ID: 3580118 • Letter: C

Question

C++

data.txt

300 450 500 210
510 600 750 400
627 100 420 430
530 621 730 530
200 050 058 200
100 082 920 290

Your program will: Read in that data file into a 2 dimensional array, 6 rows by 4 columns. Each row represents a Factory with 4 shifts. The integer value represents the number of units produced at each shift for that Factory. 2 Allow the user to do several different tasks: Display the current Factories and each of their shifts' production runs (e each Factory 1 to 6 will each have 4 shifts Calculate the Highest and Lowest production runs among all of the shifts (total of 24 different shifts, 6 different factories X4 shifts each Calculate the Average production nun among all of the shifts (total of 24 different shifts, 6 different factories X4 shifts each) PLUS the average production run PER each Factory among its own 4 shifts Allow the user to manually change the production nun value for a particular factory for one of its 4 shifts (e,g. Factory 3, Shift #4) QUIT 3- se functions to carry out each task. The main is reduced to a switch that calls out one function We are passing an array to the function. We know there is a maximum of 24 values 6 factories with 4 different shifts each). You may want to use a nested for loop since that would be the easiest approach The average for each individual factory would be an "interesting calculation since we would have to know when to stop and when to start a factory within that nested for loop The first index location is always zero but humans are not use to seeing "Factory #0". How would display it as "Factory #1" instead (and No. let's use all elements of the array and not ignore the "zero" row and "zero" columns If we change any existing value for a factory shift's production run, we have to check for 1. Valid Factory value (e.g. 1 to 6) 2. Valid Shift value (eg 1 to 4) 3. No negative integers for the production run (zero is legitimate as avalue)

Explanation / Answer

#include<bits/stdc++.h>
using namespace std;

int main(int argc, char const *argv[])
{
  
int minp=INT_MAX;
   int maxp=INT_MIN;
int arr[6][4];
ifstream f("data.txt");
for (int i = 0; i < 6; ++i)
       {
           for (int j = 0; j < 4; ++j)
           {
               f>>arr[i][j];
           }
       }
int flag=1;
int sumall=0,sumfact=0;
int facno,shiftno,newprod;
while(flag)
{
cout<<"1)Display Factories and their shifts 2)Calculate lowest and highest production 3)Calculate Average production 4)Change production run value 5)Quit ";

int ch;

cin>>ch;

               switch(ch)
       {
   case 1:
      
       cout<<" Shift 1 Shift 2 Shift 3 Shift 4 ";
       for (int i = 0; i < 6; ++i)
       {
           cout<<"Factory "<<i+1<<" :";
           for (int j = 0; j < 4; ++j)
           {
               cout<<arr[i][j]<<" ";
           }
           cout<<endl;
       }
       break;
   case 2:
  

   for (int i = 0; i < 6; ++i)
       {
          
           for (int j = 0; j < 4; ++j)
           {
               if(arr[i][j]>maxp)
                   maxp=arr[i][j];
               if(arr[i][j]<minp)
                   minp=arr[i][j];
           }
          
       }

       cout<<"Highest production is "<<maxp<<endl;
       cout<<"Lowest production is "<<minp<<endl;
       break;
   case 3:
  
  

   for (int i = 0; i < 6; ++i)
       {
          
           for (int j = 0; j < 4; ++j)
           {
              
                   sumfact+=arr[i][j];
           }
           cout<<"Average Prodction For Factory "<<i+1<< " is "<<(sumfact/4)<<endl;

           sumall+=sumfact;
          
       }

       cout<<"Total Average Prodction "<<sumall/24<<endl;
       break;
   case 4:
       cout<<"Enter Factory no ";
       cin>>facno;

       cout<<" Enter Shift no ";
       cin>>shiftno;
       cout<<"Enter new production ";
       cin>>newprod;
       arr[facno-1][shiftno-1]=newprod;
       break;
   case 5:flag=0;break;
  
}

}


return 0;
}

=========================================================================

Output:

akshay@akshay-Inspiron-3537:~/Chegg$ g++ faco.cpp
akshay@akshay-Inspiron-3537:~/Chegg$ ./a.out
1)Display Factories and their shifts
2)Calculate lowest and highest production
3)Calculate Average production
4)Change production run value
5)Quit
1
   Shift 1   Shift 2   Shift 3   Shift 4
Factory 1 :300 450 500 210
Factory 2 :510 600 750 400
Factory 3 :627 100 420 430
Factory 4 :530 621 730 530
Factory 5 :200 50 58 200
Factory 6 :100 82 920 290
1)Display Factories and their shifts
2)Calculate lowest and highest production
3)Calculate Average production
4)Change production run value
5)Quit
2
Highest production is 920
Lowest production is 50
1)Display Factories and their shifts
2)Calculate lowest and highest production
3)Calculate Average production
4)Change production run value
5)Quit
3
Average Prodction For Factory 1 is 365
Average Prodction For Factory 2 is 930
Average Prodction For Factory 3 is 1324
Average Prodction For Factory 4 is 1927
Average Prodction For Factory 5 is 2054
Average Prodction For Factory 6 is 2402
Total Average Prodction 1500
1)Display Factories and their shifts
2)Calculate lowest and highest production
3)Calculate Average production
4)Change production run value
5)Quit
4
Enter Factory no 1

Enter Shift no 2
Enter new production 550
1)Display Factories and their shifts
2)Calculate lowest and highest production
3)Calculate Average production
4)Change production run value
5)Quit
1
   Shift 1   Shift 2   Shift 3   Shift 4
Factory 1 :300 550 500 210
Factory 2 :510 600 750 400
Factory 3 :627 100 420 430
Factory 4 :530 621 730 530
Factory 5 :200 50 58 200
Factory 6 :100 82 920 290
1)Display Factories and their shifts
2)Calculate lowest and highest production
3)Calculate Average production
4)Change production run value
5)Quit
5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote