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 88 89 90 91 92 93 94
|
void sort(float sales[], int size) //the bubble sort we have to use
{
int i, j;
for(i=0;i<size-1;i++)
{
for(j=0;j<size-i-1;j++)
{
//checking if previous value is
//grater than next one or not
if(sales[j]>sales[j+1])
{
float temp=sales[j];
sales[j]=sales[j+1];
sales[j+1]=temp;
}
}
}
}
int search_ID(float sales[][4]) //completely stuck here
{
int r;
for(c=0;c<=0;c++)
{
for(r=0;r<13;r++)
{
if(sales[r][c]!=sales[r][c]) //was thinking of if the ID number matches the number already stored, then skip or only store col 1 for the sales
}
}
return sub;
}
float avgSale(float sales[][4], int rowNum) //the avg sales for each employee
{
int r, c, totalSales;
float avg;
for(r=rowNum;r<=rowNum;r++) //would just use a for loop in main to call each row num.
{
for (c=3;c<4;c++)
{
avg=sales[r][c]/totalSales;
}
}
return avg;
}
void printReport(float sales[][4]) //we have to print a report with ID, Num sales, total sales, and avg for each so the 4 columns
{
int r, c;
cout<<fixed<<setprecision(2);
for(r=0;r<13;r++)
{
for(c=0;c<=1;c++)
{
cout<<sales[r][c]<<" ";
}
cout<<endl;
}
}
/**************************************************************************************/
//beginning of main
int main()
{
infile.open("C://data//input//Sales.txt"); //opening the infile
outfile.open("C:\\data\\SalesmenReport.txt"); //opening the outfile
if(!infile) //check if file opens
{
cout<<"File did not open. Please try again."<<endl;
return 0;
}
int size=12;
int sub;
float avg;
float sales[size][4];
int r, c, sub;
for(r=0;r<13;r++)
{
for(c=0;c<=1;c++)
{
infile>>sales[r][c];
sub=search_ID(sales); //he showed us this as an example to call the search, idk where to put it or what to put in it.
}
}
printReport(sales);
avg=avgSale(sales, 0);
|