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
|
#include "stdafx.h"
#include "invoice.h"
using namespace std;
void selectionSort(Invoice invoices[], int SIZE);
int main()
{
const int SIZE = 8;
int in;
Invoice invoices[] = {
Invoice( 83, "El", 7, 57.98),
Invoice( 24, "P", 18, 99.99),
Invoice( 7, "Sl", 11, 21.5),
Invoice( 77, "H", 76, 11.99),
Invoice( 39, "L", 3, 79.5),
Invoice( 68, "Sc", 106, 6.99),
Invoice( 56, "J", 21, 11),
Invoice( 3, "W", 34, 7.5) };
selectionSort(invoices, SIZE);
cin >> in ;
return 0;
}
void selectionSort(Invoice invoice[], int size)
{
int start, minIndex;
string minValue;
for(start = 0; start < (size - 1); start++)
{
minIndex = start;
minValue = invoice[start].getDesc();
for(int index = start + 1; index < size; index++)
{
if (invoice[index].getDesc() < minValue)
{
minValue = invoice[index].getDesc();
minIndex = index;
}
}
invoice[minIndex].getDesc() = invoice[start].getDesc();
invoice[start].getDesc() = minValue;
}
for (int i = 0; i < size; i++)
{
cout << setprecision(4) << " " << invoice[i].getPart() << " " << invoice[i].getDesc() << " " << invoice[i].getQuant() << " " << invoice[i].getPri() << '\n';
}
}
|