diff options
author | Matthew Strapp <msattr@gmail.com> | 2019-05-08 17:59:56 -0500 |
---|---|---|
committer | Matthew Strapp <msattr@gmail.com> | 2019-05-08 17:59:56 -0500 |
commit | cd0fc71c46d7fab385bcf25be606f43a5d832689 (patch) | |
tree | ef5767b117eac379eec66b45e7c9b749c7dda1e8 /ee1301/wk7 | |
parent | time to fail a hw (diff) | |
download | homework-cd0fc71c46d7fab385bcf25be606f43a5d832689.tar homework-cd0fc71c46d7fab385bcf25be606f43a5d832689.tar.gz homework-cd0fc71c46d7fab385bcf25be606f43a5d832689.tar.bz2 homework-cd0fc71c46d7fab385bcf25be606f43a5d832689.tar.lz homework-cd0fc71c46d7fab385bcf25be606f43a5d832689.tar.xz homework-cd0fc71c46d7fab385bcf25be606f43a5d832689.tar.zst homework-cd0fc71c46d7fab385bcf25be606f43a5d832689.zip |
E
Diffstat (limited to '')
-rw-r--r-- | ee1301/wk7/hw7_directory/HouseDB.cpp | 58 |
1 files changed, 46 insertions, 12 deletions
diff --git a/ee1301/wk7/hw7_directory/HouseDB.cpp b/ee1301/wk7/hw7_directory/HouseDB.cpp index b09aff4..3eb0d73 100644 --- a/ee1301/wk7/hw7_directory/HouseDB.cpp +++ b/ee1301/wk7/hw7_directory/HouseDB.cpp @@ -23,7 +23,8 @@ void ProcHeader(ifstream &file); houseData* ReadRecord(ifstream &file); houseData* Scanlist(houseData* head, int Zipcode); void DelRecord(houseData *record); - +void bsort(int list[], int length); +void swap (int &a, int &b); void printAllHousesByZip(houseData* head); int main(int argc, char* argv[]) { @@ -62,9 +63,11 @@ int main(int argc, char* argv[]) { } } } - int zipSort[1000]; bool newZip=true; int currentUnique=0; - for (int i=0; i<999; i++) {zipSort[i]=0;} + + houseData* currentZipFind = head; + int zipSort[1000]; bool newZip=true; int currentUnique=0; + for (int i=0; i<999; i++) {zipSort[i]=0;} while(currentZipFind!=nullptr) { for (int i=0; i<999; i++) { //Find a new zipcode to average @@ -77,19 +80,32 @@ int main(int argc, char* argv[]) { } if ( (newZip) ) { zipSort[currentUnique]=currentZipFind->zipcode; - cout << zipSort[currentUnique] << endl; + //cout << zipSort[currentUnique] << endl; currentUnique++; } currentZipFind = currentZipFind->nextZip; } - houseData* currentAvgFind = head; - currentUnique=0; int totalCost=0, houseNumber=0; - while (currentAvgFind!=NULL) { - totalCost+=currentAvgFind->price; - houseNumber++; - currentAvgFind=Scanlist(currentAvgFind, currentAvgFind->zipcode); - cout << currentAvgFind; - } + bsort(zipSort, 1000); + + houseData* findAvg = head; + int costPerZip[1000]={0}, totalPerZip[1000]={0}; + //Set all of the values to zero + for (int i=0; i<999; i++) {costPerZip[i]=0; totalPerZip[i]=0;} + while (findAvg!=NULL) { + for(int j=0; j<999; j++) { + if (zipSort[j]=findAvg->zipcode) { + costPerZip[j]+=findAvg->price; + totalPerZip[j]++; + break; //Break for loop + } + } //end for + findAvg=findAvg->nextZip; + } //end while + for (int k=0; k<999; k++) { + if (zipSort[k]!=0) { + cout << zipSort[k] << ":average price=" << totalPerZip[k] << endl; + } + } //printAllHousesByZip(head); @@ -121,6 +137,24 @@ void ProcHeader(ifstream &file) { } } +//This function is the algorithm. +void bsort(int list[], int length) { + for (int i=0; i<length; i++) { + for (int j=0; j<length-1; j++) { + if (list[j]>list[j+1]) { + //This is so the bubble can happen + swap(list[j], list[j+1]); + } + } + } +} + +//This function simply swaps two values so the bubbling can commence +void swap (int &a, int &b) { + int temp; + temp=a; a=b; b=temp; +} + houseData* ReadRecord(ifstream &file) { int b = 0; int endOfHeader = 0; |