SALES DATA ANALYSIS

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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include <iostream>
#include <fstream>
#include <iomanip>
#include <string>
using namespace std;

const int noOfSalesPerson = 6;
enum quarterType{QT1,QT2,QT3,QT4};

struct salesPersonRec
{
string ID; //salesperson’s ID
double saleByQuarter[4];
double totalSale;
};

void initialize(ifstream& indata, salesPersonRec list[],int listSize)
{
int count;
quarterType quarter;
for(count = 0; count < listSize; count++)
{
indata>>list[count].ID; //get salesperson’s ID
for(quarter = QT1; quarter <= QT4;
quarter = static_cast<quarterType>(quarter + 1))
list[count].saleByQuarter[quarter] = 0.0;
list[count].totalSale = 0.0;
}
}

void getData(ifstream& infile, salesPersonRec list[],int listSize)
{
int count;
quarterType quarter;
string sID;
int month;
double amount;
infile>>sID; 

while(infile)
{
infile>>month>>amount; 
for(count = 0; count < listSize; count++) 
{
if(sID == list[count].ID)
{
if(1 <= month && month <= 3) 
quarter = QT1;
else if(4 <= month && month <= 6)
quarter = QT2;
else if(7 <= month && month <= 9)
quarter = QT3;
else
quarter = QT4;
list[count].saleByQuarter[quarter] += amount;
//Step 4
break;	
}
}
infile>>sID;	


void saleByQuarter(salesPersonRec list[], int listSize,double totalByQuarter[])
{
quarterType quarter;
int count;
for(quarter = QT1; quarter <= QT4;
quarter = static_cast<quarterType>(quarter+1))
totalByQuarter[quarter] = 0.0;
for(quarter = QT1; quarter <= QT4;
quarter = static_cast<quarterType>(quarter+1))
for(count = 0; count < listSize; count++)
totalByQuarter[quarter] += list[count].saleByQuarter[quarter];
}


void totalSaleByPerson(salesPersonRec list[],int listSize)
{
int count;
quarterType quarter;
for(count = 0; count < listSize; count++)
for(quarter = QT1; quarter <= QT4; 
quarter = static_cast<quarterType>(quarter + 1))
list[count].totalSale +=
list[count].saleByQuarter[quarter];
}
void maxSaleByPerson(ofstream& outData,salesPersonRec list[], int listSize)
{
int maxIndex = 0;
int count;
for(count = 1; count < listSize; count++)
if(list[maxIndex].totalSale < list[count].totalSale)
maxIndex = count;
outData<<"Max Sale by SalesPerson: ID = "
<<list[maxIndex].ID
<<", Amount = $"
<<list[maxIndex].totalSale<<endl;
}


void maxSaleByQuarter(ofstream& outData,double saleByQuarter[])
{
quarterType quarter;
quarterType maxIndex = QT1;
for(quarter = QT1; quarter <= QT4;
quarter = static_cast<quarterType>(quarter+1))
if(saleByQuarter[maxIndex] < saleByQuarter[quarter])
maxIndex = quarter;
outData<<"Max Sale by Quarter: Quarter = "
<<static_cast<int>(maxIndex) + 1
<<", Amount = $"<<saleByQuarter[maxIndex]<<endl;
}

void printReport(ofstream& outfile,salesPersonRec list[], int listSize,double saleByQuarter[])
{
int count;
quarterType quarter;

outfile<<"----------- Annual  Report -------------"

<<endl;
outfile<<endl;

outfile<<" ID QT1 QT2 QT3 "

<<"QT4 Total"<<endl;

outfile<<"________________________________________________"

<<"_______________"<<endl;

for(count = 0; count < listSize; count++)	
{
outfile<<list[count].ID<<" ";
for(quarter = QT1; quarter <= QT4;
quarter = static_cast<quarterType>(quarter + 1))
outfile<<setw(10)<<list[count].saleByQuarter[quarter];
outfile<<setw(10)<<list[count].totalSale<<endl;
}
outfile<<"Total ";	 
for(quarter = QT1; quarter <= QT4;
quarter = static_cast<quarterType>(quarter + 1))
outfile<<setw(10)<<saleByQuarter[quarter];
outfile<<endl<<endl<<endl;
}

int main()

{

//Step 1
ifstream infile;
ofstream outfile; 
char inputfile[25];
char outputfile[25];
double totalSaleByQuarter[4]; 

salesPersonRec salesPersonList[noOfSalesPerson];

cout<<"Enter SalesPerson ID file name : "; 
cin>>inputfile;	 
cout<<endl;

infile.open(inputfile); 

if(!infile)	 

{

cout<<"Cannot open input file."<<endl;

return 1;

}

initialize(infile, salesPersonList, noOfSalesPerson);

infile.close(); 
cout<<"Enter sales data file name: ";	 
cin>>inputfile;	 
cout<<endl;
infile.open(inputfile);	 
if(!infile)	 

{

cout<<"Cannot open input file."<<endl;

return 1;

}



cout<<"Enter output file name: ";	

cin>>outputfile;	

cout<<endl;

outfile.open(outputfile);
outfile<<fixed<<showpoint<<setprecision(2);
getData(infile, salesPersonList, noOfSalesPerson);
saleByQuarter(salesPersonList, noOfSalesPerson,totalSaleByQuarter);
totalSaleByPerson(salesPersonList, noOfSalesPerson);
printReport(outfile, salesPersonList, noOfSalesPerson,totalSaleByQuarter);	 
maxSaleByPerson(outfile, salesPersonList,noOfSalesPerson);
maxSaleByQuarter(outfile, totalSaleByQuarter);

infile.close();	 
outfile.close();	

system("pause");
return 0;


Enter SalesPerson ID file name : ID.txt

Enter sales data file name:  SalesData.txt

Enter output file name: Annual Sale Report.TXT

Press any key to continue . . .



The Output should be for the file is like this (.txt file)

Annual Sales Report
 
ID                    QT1                 QT2                 QT3                 QT4                 Total
12345              1829.00           0.00                 494.00             322.00             2708.00
32214                343.00       892.00               9023.00                 0.00           10258.00
23422              1395.00     1901.00                     0.00                 0.00             3296.00
57373                893.00       892.00               8834.00                 0.00           10619.00
35864              2882.00     1221.00                     0.00           1223.00             5326.00
54654                893.00           0.00                 392.00           3420.00             4705.00
 
Total               8298.00     4906.00             18743.00           4965.00
 
Max Sale by SalesPerson: ID = 57373, Amount = $10619.00
Max Sale by Quarter: Quarter = 3, Amount = $18743.00



But the Output FOR THE Annual sale report(.txt file) is this

----------- Annual  Report -------------

 ID QT1 QT2 QT3 QT4 Total
_______________________________________________________________
12344       0.00      0.00      0.00      0.00      0.00
32214       0.00      0.00      0.00      0.00      0.00
23422       0.00      0.00      0.00      0.00      0.00
57373       0.00      0.00      0.00      0.00      0.00
35864       0.00      0.00      0.00      0.00      0.00
54654       0.00      0.00      0.00      0.00      0.00
Total       0.00      0.00      0.00      0.00


Max Sale by SalesPerson: ID = 12344, Amount = $0.00
Max Sale by Quarter: Quarter = 1, Amount = $0.00



only the ID file was generated to the file but the sales data file is not.
the saledata (.txt file) content is

Salespeople’s Data
12345 1 893
32214 1 343
23422 3 903
57373 2 893
35864 5 329
54654 9 392
12345 2 999
32214 4 892
23422 4 895
23422 2 492
57373 6 892
35864 10 1223
54654 11 3420
12345 12 322
35864 5 892
54654 3 893
12345 8 494
32214 8 9023
23422 6 223
23422 4 783
57373 8 8834
35864 3 2882


HELP PLS..
Last edited on
Topic archived. No new replies allowed.