1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
#include<iostream>
#include<conio.h>
#include<fstream>
#include<string>
using namespace std;
int main()
{int i,j;
char days[7][5]={"mon","tue","thur","wed","fri","sat","sun"};
char item[5][8]={"milk","sugar","juice","rice","coffee"};
int sold[7][5]={1,1,3,1,1,1,1,3,1,1,1,1,1,1,1,3,1,1,1,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1};
int rowsum=0,culsum=0;
/*for(i=0;i<7;i++)
{
cout<<"Please enter the quantity sold for each item in "<<days[i]<<": ";
cin>>sold[i][0]>>sold[i][1]>>sold[i][2]>>sold[i][3]>>sold[i][4];
}*/
cout<<"\t";
for(int i=0;i<7;i++)
cout<<days[i]<<"\t";
cout<<"sum"<<endl;
int maxSale=0;
char product[10];
strcpy(product,item[0]);
//print the row sum for each day
for( j=0;j<5;j++)
{
cout<<item[j]<<"\t";
for( i=0;i<7;i++)
cout<<sold[i][j]<<"\t";
{
rowsum+=sold[j][i];
cout<<rowsum<<"\n";
rowsum=0;
}
}
if(rowsum>maxSale)
{
maxSale=rowsum;
strcpy(product,item[j]);
}
cout<<endl;
cout<<"sum\t";
//print the column sum at each day
for(int i=0;i<7;i++){
for(int j=0;j<5;j++)
{
culsum+=sold[i][j];
}
cout<<culsum<<"\t";
culsum=0;
}
cout<<endl;
//product of maximum sale
cout<<"The best seller product is "<<product<<endl;
//maximum sale
cout<<"Qunatity sold "<<maxSale<<endl;
getch();
return 0;
}
|