structs logic problem
Mar 10, 2014 at 3:49am UTC
I'm trying to separate the data into the separate warehouses so that I just output the warehouse name once and move all the data associated with that warehouse with it. I'm not sure how to do that, any help would be appreciated.
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 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
#include <iostream>
#include <fstream>
#include <iomanip>
//Jacob Wilt
//Warehouse Inventory Report
using namespace std;
ifstream infile1, infile2, infile3, infile4;
ofstream outfile;
int cnt = 0;
const int Max = 65;
int Item_Number;
string WareHouse_Name;
string Item_Name;
int Quantity;
double WSP;
double MarkUp;
double Retail;
struct WIR
{
int Item_Number;
int Item_Number2;
int Item_Number3;
string WareHouse_Name;
string Item_Name;
string Item_Name2;
string Item_Name3;
int Quantity;
double WSP;
double MarkUp;
double Retail;
char per;
};
WIR WH[Max];
void openfiles();
void read();
void SortFile1();
void SortFile2();
void SortFile3();
void SortFile4();
void GetRetail();
void print();
void closefiles();
int main()
{
openfiles();
read();
SortFile2();
SortFile1();
SortFile3();
SortFile4();
GetRetail();
print();
closefiles();
return 0;
}
void openfiles()
{
infile1.open("C:\\Users\\Jacob\\Desktop\\WLL1.txt" );
infile2.open("C:\\Users\\Jacob\\Desktop\\WLL2.txt" );
infile3.open("C:\\Users\\Jacob\\Desktop\\WLL3.txt" );
infile4.open("C:\\Users\\Jacob\\Desktop\\WLL4.txt" );
outfile.open("WarehouseOutfile.txt" );
}
void read()
{
int i;
for (i = 0; i < Max; i++)
{
infile1 >> WH[i].Item_Number2 >> WH[i].Item_Name;
infile2 >> WH[i].Item_Number >> WH[i].WareHouse_Name;
infile3 >> WH[i].Item_Name2 >> WH[i].Quantity;
infile4 >> WH[i].Item_Name3 >> WH[i].Item_Number3 >> WH[i].WSP >> WH[i].MarkUp >> WH[i].per;
}
}
void SortFile2()
{
int temp;
string tmp;
int i, j;
for (j = 0; j < Max; j++)
{
for (i = 0; i < Max; i++)
{
if (WH[i].Item_Number < WH[i+1].Item_Number)
{
temp = WH[i].Item_Number;
tmp = WH[i].WareHouse_Name;
WH[i].Item_Number = WH[i+1].Item_Number;
WH[i].WareHouse_Name = WH[i+1].WareHouse_Name;
WH[i+1].Item_Number = temp;
WH[i+1].WareHouse_Name = tmp;
}
}
}
}
void SortFile1()
{
int temp;
string tmp;
int i, j;
for (j = 0; j < Max; j++)
{
for (i = 0; i < Max; i++)
{
if (WH[i].Item_Number2 < WH[i+1].Item_Number2)
{
temp = WH[i].Item_Number2;
tmp = WH[i].Item_Name;
WH[i].Item_Number2 = WH[i+1].Item_Number2;
WH[i].Item_Name = WH[i+1].Item_Name;
WH[i+1].Item_Number2 = temp;
WH[i+1].Item_Name = tmp;
}
}
}
}
void SortFile3()
{
int temp;
string tmp;
int i, j;
for (j = 0; j < Max; j++)
{
for (i = 0; i < Max; i++)
{
if (WH[i].Item_Name2 == WH[i].Item_Name)
{
temp = WH[i].Quantity;
tmp = WH[i].Item_Name2;
WH[i].Quantity = WH[i+1].Quantity;
WH[i].Item_Name2 = WH[i+1].Item_Name2;
WH[i+1].Quantity = temp;
WH[i+1].Item_Name2 = tmp;
}
}
}
}
void SortFile4()
{
double temp2, temp3;
int temp;
string tmp;
int i, j;
for (j = 0; j < Max; j++)
{
for (i = 0; i < Max; i++)
{
if (WH[i].Item_Number3 < WH[i+1].Item_Number3)
{
temp = WH[i].Item_Number3;
temp2 = WH[i].WSP;
temp3 = WH[i].MarkUp;
tmp = WH[i].Item_Name3;
WH[i].Item_Number3 = WH[i+1].Item_Number3;
WH[i].WSP = WH[i+1].WSP;
WH[i].MarkUp = WH[i+1].MarkUp;
WH[i].Item_Name3 = WH[i+1].Item_Name3;
WH[i+1].Item_Number3 = temp;
WH[i+1].WSP = temp2;
WH[i+1].MarkUp = temp3;
WH[i+1].Item_Name3 = tmp;
}
}
}
}
void GetRetail()
{
int i;
for (i = 0; i < Max; i++)
{
WH[i].Retail = WH[i].WSP + (WH[i].WSP * WH[i].MarkUp);
}
}
void print()
{
int i;
outfile << "WareHouse_Name\t Item_Name\t Quantity WSP\t MarkUp\t Retail\n" ;
outfile << "--------------------------------------------------------------------------------\n" ;
for (i = 0; i < Max; i++)
{
outfile << setprecision(2) << fixed << setw(11) << WH[i].WareHouse_Name << setw(20) << WH[i].Item_Name << setw(8);
outfile << WH[i].Quantity << setw(15) << WH[i].WSP << setw(10) << WH[i].MarkUp << "%" << setw(15) << WH[i].Retail << endl;
}
}
void closefiles()
{
infile1.close();
infile2.close();
infile3.close();
infile4.close();
outfile.close();
}
Mar 10, 2014 at 3:50am UTC
This is the current output
WareHouse_Name Item_Name Quantity WSP MarkUp Retail
--------------------------------------------------------------------------------
DesertWest Hallies-x 18 41.15 18.00% 781.85
WestCoast Hallies-l 23 79.95 34.00% 2798.25
DesertWest CutThroat-k 16 82.97 81.00% 6803.54
GreatLakes Whiskers-m 23 14.72 26.00% 397.44
WestCoast TwoB1Ask1-x 23 58.92 66.00% 3947.64
Mississippi StuffedStuff-m 2 43.53 18.00% 827.07
DesertWest Whiskers-g 16 71.11 93.00% 6684.34
DesertWest TenEShoe-k 2 67.35 67.00% 4579.80
SwappySouth TightShoes-k 18 77.88 12.00% 1012.44
GreatLakes Hallies-w 5 34.46 47.00% 1654.08
SwappySouth MacARainy-c 8 19.30 4.00% 96.50
SwappySouth Whiskers-v 23 81.03 49.00% 4051.50
GreatLakes MacARainy-h 8 34.61 82.00% 2872.63
GreatLakes Woosies-e 1 94.36 65.00% 6227.76
GreatLakes TenEShoe-t 29 87.64 93.00% 8238.16
SwappySouth StuffedStuff-p 1 77.85 25.00% 2024.10
DesertWest HailBock-p 10 81.60 42.00% 3508.80
Mississippi TightShoes-m 26 96.79 65.00% 6388.14
WestCoast HailBock-o 23 47.79 81.00% 3918.78
SwappySouth Gowns-c 29 26.42 95.00% 2536.32
WestCoast MacARainy-y 3 29.48 4.00% 147.40
DesertWest Woosies-p 10 22.33 29.00% 669.90
GreatLakes TightShoes-l 20 93.67 46.00% 4402.49
Mississippi HailBock-a 23 57.40 80.00% 4649.40
WestCoast CutThroat-l 6 84.89 66.00% 5687.63
SwappySouth TwoB1Ask1-q 5 66.75 22.00% 1535.25
WestCoast Whiskers-a 5 88.12 66.00% 5904.04
DesertWest MacARainy-t 8 63.83 41.00% 2680.86
Mississippi Woosies-h 11 84.92 43.00% 3736.48
Mississippi Hallies-t 0 27.36 64.00% 1778.40
WestCoast TenEShoe-s 0 76.39 27.00% 2138.92
SwappySouth Hallies-i 26 49.18 51.00% 2557.36
SwappySouth HailBock-g 1 47.91 24.00% 1197.75
WestCoast Gowns-r 25 71.19 90.00% 6478.29
GreatLakes CutThroat-x 25 11.11 81.00% 911.02
Mississippi Whiskers-j 20 77.76 5.00% 466.56
Mississippi Galixies-t 8 10.20 45.00% 469.20
WestCoast Toosies-m 10 35.71 92.00% 3321.03
WestCoast TightShoes-p 15 12.14 52.00% 643.42
SwappySouth Galixies-v 29 13.96 82.00% 1158.68
Mississippi TwoB1Ask1-u 21 26.91 22.00% 618.93
Mississippi Toosies-b 13 39.99 30.00% 1239.69
DesertWest Toosies-a 19 78.78 79.00% 6302.40
WestCoast Galixies-r 25 39.79 61.00% 2466.98
GreatLakes StuffedStuff-j 19 91.13 72.00% 6652.49
GreatLakes Gowns-o 0 77.62 9.00% 776.20
DesertWest StuffedStuff-a 3 90.42 69.00% 6329.40
Mississippi TenEShoe-h 1 22.31 70.00% 1584.01
DesertWest Gowns-u 16 24.22 37.00% 920.36
GreatLakes TwoB1Ask1-r 23 80.51 98.00% 7970.49
SwappySouth Toosies-x 4 39.18 26.00% 1057.86
SwappySouth CutThroat-z 18 86.98 95.00% 8350.08
DesertWest TightShoes-n 26 32.68 58.00% 1928.12
GreatLakes HailBock-q 13 47.52 77.00% 3706.56
GreatLakes Toosies-o 7 11.18 89.00% 1006.20
SwappySouth TenEShoe-d 27 44.35 56.00% 2527.95
WestCoast Woosies-w 25 54.12 63.00% 3463.68
DesertWest TwoB1Ask1-m 21 90.40 1.00% 180.80
Mississippi CutThroat-y 26 32.43 72.00% 2367.39
Mississippi Gowns-i 4 24.84 68.00% 1713.96
DesertWest Galixies-s 17 42.79 59.00% 2567.40
SwappySouth Woosies-c 22 37.94 69.00% 2655.80
GreatLakes Galixies-u 24 90.25 63.00% 5776.00
WestCoast StuffedStuff-z 6 16.56 95.00% 1589.76
Mississippi MacARainy-j 16 69.70 14.00% 1045.50
Topic archived. No new replies allowed.