I have to load two arrays, merge the two arrays into a third array, then create a control break report on name while outputting the most frequent style, then sort the array by style and to a control break on style. Can someone look at my code and see if they can see what I am doing wrong.
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
struct salesTran{
string name;
string style;
double price;
double quantity;
};
void MERGE(salesTran A[],int count1,salesTran B[],int count2,salesTran C[],int size, salesTran Temp[]){
for (int i=0; i<count1; i++){
C[i]=B[i];}
int j=count1;
for (int f=0; f<size; f++){
C[j]=B[f];
j++;}
for (int i=0; i<size; i++){
for (int f=0; f<size; f++){
if (C[f].name>C[f+1].name){
Temp[0]=C[f];
C[f]=C[f+1];
C[f+1]=Temp[0];}
}
}
return;
}
void CBR_NAME(salesTran C[], int size){
ofstream outdata1;
outdata1.open("CBR_Name.txt");
outdata1<<"Name"<<"\t"<<"\t"<<"Style"<<"\t"<<"\t"<<"Price""\t"<<"\t"<<"Quantity"<<"\t"<<"\t"<<endl;
int elegcount=0, excelcount=0, exqcount=0, excalcount=0, imagcount=0, inspcount=0, impresscount=0;
string freqStyle;
int count = 0;
int highest=0;
for(int i = 0; i < size; i++)
{
if(C[i].name == C[i+1].name)
{
outdata1 << C[i].name <<"\t"<< C[i].style <<"\t"<< C[i].price <<"\t"<< C[i].quantity << endl;
if (C[i].style=="Elegant") elegcount++;
else if (C[i].style=="Excelsior") elegcount++;
else if (C[i].style=="Exquisite") exqcount++;
else if (C[i].style=="Excalibur") excalcount++;
else if (C[i].style=="Imagine") imagcount++;
else if (C[i].style=="Inspire") inspcount++;
else if (C[i].style=="Impression") impresscount++;
}
else
{
if(elegcount<elegcount){
highest=elegcount;
freqStyle="Excelsior";}
else {
highest=elegcount;
freqStyle="Elegant";}
if (highest<exqcount){
highest=exqcount;
freqStyle="Exquisite";}
if (highest<excalcount){
highest=excalcount;
freqStyle="Excalibur";}
if (highest<imagcount){
highest=imagcount;
freqStyle="Imagine";}
if (highest<inspcount){
highest=inspcount;
freqStyle="Inspire";}
if (highest<impresscount){
highest=impresscount;
freqStyle="Impression";}
if (highest!=0) outdata1 << "The most frequently sold style was " << freqStyle << ", being sold " << highest << " times." << endl << endl;
highest = 0, elegcount=0, elegcount=0, exqcount=0, excalcount=0, imagcount=0, inspcount=0, impresscount=0;
}
}
outdata1.close();
return;}
void SORT_STYLE(salesTran C[], salesTran Temp[], int size){
for (int k=0; k<size; k++){
for (int j=0; j<(size-1); j++){
if (C[j].style>C[j+1].style){
Temp[0]=C[j];
C[j]=C[j+1];
C[j+1]=Temp[0];
}
}
}
return;
}
void CBR_STYLE(salesTran C[],int size){
ofstream outdata2;
outdata2.open("CBR_Style.txt");
outdata2<<"Name"<<"\t"<<"\t"<<"Style"<<"\t"<<"\t"<<"Price""\t"<<"\t"<<"Quantity"<<"\t"<<"\t"<<endl;
int count=0;
string oldstyle=C[0].style;
outdata2<< C[0].name << "\t" << "\t"<< C[0].style << "\t" << "\t"<< C[0].price << "\t" << "\t"<< C[0].quantity<< "\t" << "\t"<< endl;
count++;
for (int i=1; i<(size+1); i++){
if (C[i].style==oldstyle){
outdata2<< C[i].name << "\t" << "\t"<< C[i].style << "\t" << "\t"<< C[i].price << "\t" << "\t"<< C[i].quantity<< "\t" << "\t"<< endl;
count++;}
else{
outdata2 << endl << "Count is" << count << endl;
count=0;
oldstyle=C[i].style;
outdata2<< C[i].name << "\t" << "\t"<< C[i].style << "\t" << "\t"<< C[i].price << "\t" << "\t"<< C[i].quantity<< "\t" << "\t"<< endl;
count++;}
}
outdata2 << endl << "Count is" << count << endl;
outdata2.close();
return;
}
int main(){
ifstream indata1,indata2;
indata1.open("FPData1.txt");
indata2.open("FPData2.txt");
salesTran C[100],Temp[1];
int count1=100, count2=100;
int size=count1+count2;
salesTran A[100];
for (int i=0;i<100;i++){
indata1>>A[i].name;
indata1>>A[i].style;
indata1>>A[i].price;
indata1>>A[i].quantity;
}
salesTran B[100];
for (int i=0;i<100;i++){
indata2>>B[i].name;
indata2>>B[i].style;
indata2>>B[i].price;
indata2>>B[i].quantity;
}
MERGE(A,count1,B,count2,C,size,Temp);
CBR_NAME(C,size);
SORT_STYLE(C,Temp,size);
CBR_STYLE(C,size);
indata1.close();
indata2.close();
return 0;
}