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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
//Struct
struct Sale
{
string salespersonID, item1ID, item2ID, item3ID, item4ID, dateOrdered, email;
int item1Quantity, item2Quantity, item3Quantity, item4Quantity;
double item1Price, item2Price, item3Price, item4Price;
double max;
double item1Cost;
double item2Cost;
double item3Cost;
double item4Cost;
};
void swap(Sale A[], int i, int j);
void sort(Sale A[], int count);
int main()
{
int count = 0;
Sale mySales[1000];
ifstream fin;
fin.open("data.txt");
ofstream fout;
fout.open("report.txt");
//While loop input data and calculation
while (!fin.eof())
{
fin >> mySales[count].salespersonID >>
mySales [count].item1ID >>
mySales [count].item1Quantity >>
mySales [count].item1Price >>
mySales [count].item2ID >>
mySales [count].item2Quantity >>
mySales [count].item2Price >>
mySales [count].item3ID >>
mySales [count].item3Quantity >>
mySales [count].item3Price >>
mySales [count].item4ID >>
mySales [count].item4Quantity >>
mySales [count].item4Price;
mySales [count].item1Cost = mySales[count].item1Quantity* mySales[count].item1Price; //calculation for item 1
mySales [count].item2Cost = mySales[count].item2Quantity* mySales[count].item2Price; //calculation for item 2
mySales [count].item3Cost = mySales[count].item3Quantity* mySales[count].item3Price; //calculation for item 3
mySales [count].item4Cost = mySales[count].item4Quantity* mySales[count].item4Price; //calculation for item 4
mySales [count].max= mySales[count].item1Cost;
//Find Max
if (mySales[count].item2Cost > mySales[count].max)
{
mySales[count].item2Cost = mySales[count].max;
}
if (mySales[count].item3Cost > mySales[count].max)
{
mySales[count].item3Cost = mySales[count].max;
}
if (mySales[count].item4Cost > mySales[count].max)
{
mySales[count].item4Cost = mySales[count].max;
}
count++;
}
//LETS CLEAN IT UP!
count--;
fin.close();
//This is sorting our data
sort (mySales, count);
//Output
fout.open("report.txt");
for (int c = 0; c <= count; c++)
{
if (mySales[c].max >149 && mySales[c].max < 376)
{
fout <<" Sales Person ID:" << mySales[c].salespersonID << endl;
fout << "Item 1 ID: " << mySales[c].item1ID << "\t" << "Item 1 Quantity:" << mySales[c].item1Quantity << "Item 1 Price: " << mySales[c].item1Price << "\t" << endl;
fout << "Item 2 ID: " << mySales[c].item2ID << "\t" << "Item 2 Quantity:" << mySales[c].item2Quantity << "Item 2 Price: " << mySales[c].item2Price << "\t" << endl;
fout << "Item 3 ID: " << mySales[c].item3ID << "\t" << "Item 3 Quantity:" << mySales[c].item3Quantity << "Item 3 Price: " << mySales[c].item3Price << "\t" << endl;
fout << "Item 4 ID: " << mySales[c].item4ID << "\t" << "Item 4 Quantity:" << mySales[c].item4Quantity << "Item 4 Price: " << mySales[c].item4Price << "\t" << endl;
fout << " Item Max " << mySales[c].max << endl;
}
}
fin.close();
return 0;
}
//SORT AND SWAP
void swap(Sale A[], int i, int j)
{
Sale temp = A[i];
A[i] = A[j];
A[j] = temp;
return;
}
void sort(Sale A[], int count)
{
for (int p = 1; p < count; p++)
for (int c = 0; c < count - p; c++)
if (A[c].dateOrdered > A[c + 1].dateOrdered) swap(A, c, c + 1);
return;
}
|