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 <string>
# include <fstream>
using namespace std;
struct transaction
{
string salesPersonID, item1ID, item2ID, item3ID, item4ID, orderDate, contactEmail;
int item1Quantity, item2Quantity, item3Quantity, item4Quantity;
double item1Price, item2Price, item3Price, item4Price, item1amount, item2amount, item3amount, item4amount,calculateField;
};
void swap(transaction A[], int i, int j);
void sort(transaction A[], int size);
double getMax (transaction A[], int size);
double calc(int quantity, double price);
int main()
{
int count=0 ;//set counter
transaction data[1000];// read file into array
fstream getInfo;
getInfo.open ("data.txt");
fstream putInfo;
putInfo.open("report.txt");
getInfo >> data[count].salesPersonID >> data[count].item1ID >>data[count].item1Quantity>>data[count].item1Price>>data[count].item2ID>>data[count].item2Quantity>>data[count].item2Price>>data[count].item3ID>>data[count].item3Quantity>>data[count].item3Price>> data[count].item4ID >>data[count].item4Quantity>>data[count].item4Price>>data[count].orderDate>>data[count].contactEmail;
//
while (!getInfo.eof())
{
count++;
getInfo >> data[count].salesPersonID >> data[count].item1ID >>data[count].item1Quantity>>data[count].item1Price>>data[count].item2ID>>data[count].item2Quantity>>data[count].item2Price>>data[count].item3ID>>data[count].item3Quantity>>data[count].item3Price>> data[count].item4ID >>data[count].item4Quantity>>data[count].item4Price>>data[count].orderDate>>data[count].contactEmail;
//
data[count].item1amount = calc(data[count].item1Quantity, data[count].item1Price);
data[count].item2amount = calc(data[count].item2Quantity, data[count].item2Price);
data[count].item3amount = calc(data[count].item3Quantity, data[count].item3Price);
data[count].item4amount = calc(data[count].item4Quantity, data[count].item4Price);
data[count].calculateField=getMax(data, count);
if( count>0);
sort(data,count);
for (int i=0; i<count; i++)
{
putInfo<<"ON the given order date"<<data[i].orderDate<<"the maximum revenue came from"<<data[count].calculateField;
}
}
getInfo.close();
putInfo.close();
return 0;
}
void swap(transaction A[], int i, int j)
{
transaction temp = A[i];
A[i] = A[j];
A[j] = temp;
return;
}
//
void sort(transaction A[], int size)
{
for (int p = 1; p < size; p++)
for (int c = 0; c < size - p; c++)
if (A[c].orderDate > A[c + 1].orderDate) swap(A, c, c + 1);
return;
}
//
double calc(int quantity, double price)
{
double amount = quantity * price;
return amount;
}
// max function
double getMax (int arr[], int size)
{
double high= arr[0];
for ( int r=1; r<size; r++)
{
if(arr[r]>high)
{
high=arr[r];
}
}
return high;
}
|