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
|
#include <iostream>
#include <string>
#include <fstream>
#define N 10
using namespace std;
class cust{
public:
string first;
string last;
int UPerchased;
string state;
double SHistory[10];
};
void printcust(cust[],int);
void sortsales(double [],int);
void sortname(cust[],int);
int main(){
ifstream namefile, statefile, salehistoryfile, unitsfile;
namefile.open("/Users/Soul/Documents/School/CISC/Assignment10/Assignment10/namefile.txt");
statefile.open("/Users/Soul/Documents/School/CISC/Assignment10/Assignment10/statefile.txt");
salehistoryfile.open("/Users/Soul/Documents/School/CISC/Assignment10/Assignment10/salehistoryfile.txt");
unitsfile.open("/Users/Soul/Documents/School/CISC/Assignment10/Assignment10/namefile.txt");
class cust{
public:
string first;
string last;
int UPerchased;
string state;
double SHistory[10];
};
cust cust[N];
for(int a = 0; a<N; a++){
namefile >> cust[a].first;
namefile >> cust[a].last;
}
for(int b = 0; b<N; b++){
statefile >> cust[b].state;
}
for(int c = 0; c<N; c++){
unitsfile >> cust[c].UPerchased;
}
for(int d = 0; d<N; d++){
salehistoryfile >> cust[d].SHistory[0];
salehistoryfile >> cust[d].SHistory[1];
salehistoryfile >> cust[d].SHistory[2];
}
printcust(cust,N);
sortname(cust,N);
printcust(cust,N);
sortsales(cust,N);
printcust(cust,N);
return 0;
}
void sortname(cust name[],int nelts){
string temp;
for(int pass = 0; pass<nelts-1;pass++)
for(int cand = 1;cand<nelts; cand++ )
if(name[pass].last>name[cand].last){
temp = name[pass].last;
name[pass].last = name[cand].last;
name[cand].last = temp;
}
return;
}
void sortsales(cust name[],int nelts){
double temp;
for(int pass = 0; pass<nelts-1;pass++)
for(int cand = 1;cand<nelts; cand++ )
if((name[pass].SHistory[1]+name[pass].SHistory[2]+name[pass].SHistory[0])>(name[cand].SHistory[1]+name[cand].SHistory[2]+name[cand].SHistory[0])){
temp = name[pass].SHistory[0];
name[pass].SHistory[0] = name[cand].SHistory[0];
name[cand].SHistory[0] = temp;
}
return;
}
void printcust(cust custo[],int nelts){
for(int w = 0; 0<nelts; w++)
cout << custo[w].first << " " << custo[w].last << " " << custo[w].state << " " << custo[w].SHistory[0] << " " << custo[w].SHistory[1] << " " << custo[w].SHistory[2] << " " << custo[w].UPerchased << endl;
return;
}
|