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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158
|
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
const int size = 65;
struct WarehouseInfo
{
int Item_Number;
string Item_Name;
string WareHouse_Name;
int Quantity;
float WholesalePrice;
int MarkUpValue;
float RetailValue;
float total;
};
void readIn1(WarehouseInfo STD1[]);
void readIn2(WarehouseInfo STD2[]);
void readIn3(WarehouseInfo STD3[]);
void readIn4(WarehouseInfo STD4[]);
void sort(WarehouseInfo STD1[], WarehouseInfo STD2[], WarehouseInfo STD3[], WarehouseInfo STD4[]);
void print(WarehouseInfo STD1[], WarehouseInfo STD2[], WarehouseInfo STD3[], WarehouseInfo STD4[]);
int main()
{
WarehouseInfo STD1[size];
WarehouseInfo STD2[size];
WarehouseInfo STD3[size];
WarehouseInfo STD4[size];
readIn1(STD1);
readIn2(STD2);
readIn3(STD3);
readIn4(STD4);
sort(STD1, STD2, STD3, STD4);
print(STD1, STD2, STD3, STD4);
return 0;
}
void readIn1(WarehouseInfo S1[]) //Read first input file
{
string ItemName[size];
ifstream infile;
infile.open("WLL1.dat");
while(!infile.eof())
{
for(int i = 0; i < size; i++)
{
infile >> S1[i].Item_Number;
getline(infile, ItemName[i]);
}
}
for(int i = 0; i < size; i++)
{
S1[i].Item_Name = ItemName[i];
}
infile.close();
}
void readIn2(WarehouseInfo S2[]) //Read second input file
{
string WareHouseName[size];
ifstream infile;
infile.open("WLL2.dat");
while(!infile.eof())
{
for(int i = 0; i < size; i++)
{
infile >> S2[i].Item_Number;
getline(infile, WareHouseName[i]);
}
}
for(int i = 0; i < size; i++)
{
S2[i].WareHouse_Name = WareHouseName[i];
}
infile.close();
}
void readIn3(WarehouseInfo S3[]) //Read third input file
{
string ItemName[size];
ifstream infile;
infile.open("WLL3.dat");
while(!infile.eof())
{
for(int i = 0; i < size; i++)
{
getline(infile, ItemName[i], '\t');
infile >> S3[i].Quantity;
}
}
for(int i = 0; i < size; i++)
{
S3[i].Item_Name = ItemName[i];
}
infile.close();
}
void readIn4(WarehouseInfo S4[]) //Read fourth input file
{
string ItemName[size];
ifstream infile;
infile.open("WLL4.dat");
while(!infile.eof())
{
for(int i = 0; i < size; i++)
{
getline(infile, ItemName[i], '\t');
infile >> S4[i].Item_Number;
infile >> S4[i].WholesalePrice;
infile >> S4[i].MarkUpValue;
}
}
for(int i = 0; i < size; i++)
{
S4[i].Item_Name = ItemName[i];
}
infile.close();
}
void sort(WarehouseInfo S1[], WarehouseInfo S2[], WarehouseInfo S3[], WarehouseInfo S4[]) //Selection sort
{
WarehouseInfo temp;
WarehouseInfo temp2;
for(int i = 0; i < size; i++)
{
for(int j = 0; j < (size - 1); j++)
{
if(S1[j].Item_Number > S1[j+1].Item_Number)
{
temp = S1[j];
S1[j] = S1[j+1];
S1[j+1] = temp;
}
if(S2[j].Item_Number > S2[j+1].Item_Number)
{
temp2 = S2[j];
S2[j] = S2[j+1];
S2[j+1] = temp2;
}
}
}
for(int i = 0; i < size; i++)
{
S1[i].WareHouse_Name = S2[i].WareHouse_Name;
}
return;
}
void print(WarehouseInfo S1[], WarehouseInfo S2[], WarehouseInfo S3[], WarehouseInfo S4[])
{
for(int i = 0; i < size; i++)
{
cout << S1[i].Item_Number << " " << S1[i].Item_Name << " " << S1[i].WareHouse_Name << endl;
}
//cout << endl << endl;
/*for(int i = 0; i < size; i++)
{
cout << S3[i].Item_Name << " " << S3[i].Quantity << endl;
}*/
/*for(int i = 0; i < size; i++)
{
cout << S4[i].Item_Name << " " << S4[i].Item_Number << " " << S4[i].WholesalePrice << " " << S4[i].MarkUpValue << endl;
}*/
}
|