I am trying to sort this, but it is not working and I do not know how to fix it. My function in question is selection sort.
Here is what I have:
//CSIS 112 – Fall 2015
//Lab 4 -
#include <fstream>
#include <iostream>
#include <string>
#include "Taxes.h"
#include <iomanip>
#include <vector>
using namespace std;
void salesTaxfunc();
void propTaxfunc();
void lowestTax();
void selectionSort(Taxes * const, const int);
void swap(int * const, int * const);
int main()
{
cout << endl << "Running Lab 4 . . . " << endl << endl;
cout << ID << endl << endl << endl;
// DEFINITIONS
bool noErrors = true;
char exit;
const int Salary = 100000,
House = 267000,
Purchases = 36000;
ofstream fout,
errOut;
ifstream fin;
double *colomn1Pntr,
*colomn2Pntr,
*colomn3Pntr,
taxRates[20][20],
taxBill;
string nameOfstate;
int i,
count,
j;
const int a = 5;
vector <Taxes> integers1(a);
// ADMINISTRATIVE STUFF
fout.open(ID + ".out");
errOut.open(ID + ".err");
fout << ID << endl << endl << endl;
errOut << ID << endl;
errOut << " *** Error Report ***" << endl << endl << endl;
fin.open("Lab4.dat");
if (!fin)
{
cout << "ERROR! Problem reading file" << endl;
fout << "ERROR! Problem reading file" << endl;
errOut << "ERROR! Problem reading file" << endl;
noErrors = false;
errOut << endl << endl;
fout << endl << endl;
errOut << "END OF ERROR REPORT";
fout << "END OF MAIN REPORT";
cout << endl << "Enter any key to end execution of this program . . . ";
cin >> exit;
return 0;
}
// PROGRAM LOGIC
fout << " TAX RATES";
fout << " Total" << endl;
fout << "State Tax Bill Sales"; //Main structure
fout << " Property Income Tax Rate";
fout << endl << "------------------------------------- ";
fout << "------------------------------------------------------";
fout << endl;
i = 0;
j = 0;
for (; !fin.eof();)
{
fin >> nameOfstate >> taxRates[i][j] >> taxRates[i][j + 1] >> taxRates[i][j + 2];
if (taxRates[i][j] < 0)
taxRates[i][j] = 0;
if (taxRates[i][j + 1] < 0)
taxRates[i][j + 1] = 0;
if (taxRates[i][j + 2] < 0)
taxRates[i][j + 2] = 0;
colomn1Pntr = &taxRates[i][j];
colomn2Pntr = &taxRates[i][j + 1];
colomn3Pntr = &taxRates[i][j + 2];
taxBill = *colomn1Pntr * Purchases + *colomn2Pntr * House + *colomn3Pntr * Salary;
count = i;
integers1[i].setTaxes(nameOfstate, taxBill, count, fout);
i++;
}
selectionSort(integers1, a);
cout << endl;
cout << taxBill << endl;
//EXIT ROUTINE
errOut << endl << endl;
fout << endl << endl;
if (noErrors)
errOut << "No Errors Were Detected" << endl << endl << endl;
errOut << "END OF ERROR REPORT";
fout << "END OF MAIN REPORT";
cout << "Enter any key to end execution of this program . . . ";
cin >> exit; //to pause program
return 0;
}
void salesTaxfunc()
{
}
void propTaxfunc()
{
}
void lowestTax()
{
}
void selectionSort(Taxes * const integers1, const int a)
{
int smallest;
for (int z = 0; z < a - 1; ++z)
{
smallest = z;
for (int index = z + 1; index < a; ++index)
if (integers1[index] < integers1[smallest])
smallest = index;
swap(integers1[z], integers1[smallest]);
}
}
void swap(int * const element1Ptr, int * const element2Ptr)
{
int hold = *element1Ptr;
*element1Ptr = *element2Ptr;
*element2Ptr = hold;
}
Last edited on
I unfortunately, cannot use algorithms yet in my labs for class