C++ data.txt 300 450 500 210 510 600 750 400 627 100 420 430 530 621 730 530 200
ID: 3578118 • 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
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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.