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
|
// CS 2308.0001
// 22 October 2008
// prog5.cpp
// coded by Christy Sylvest
//This Program shows the donations made to
//the United Cause by the employees of CK Graphics, Inc.
//It displays the donations in order from lowest
//to highest ans in the original order they were received.
//It uses a struct to show the donor and amount of donation.
#include<iostream>
#include<fstream>
#include "arrBubbleSort.h"
#include "showArray.h"
#include "showArrPtr.h"
using namespace std;
int main()
{
ofstream outFile;
outFile.open ( "outFile.txt" ) ; //open the output file
const int NUM_DONATIONS = 15; //Number of Donations
struct Donor
{
int amount[];
int donorNum[];
};
Donor donations;
donations.amount[NUM_DONATIONS] = (5,100,5,25,10,5,25,5,5,100,10,15,10,5,10);
donations.donorNum[NUM_DONATIONS] = (100, 47, 226, 84, 134, 53, 175, 38, 77, 82, 156, 44, 91, 103, 187);
int *arrPtr[NUM_DONATIONS]; //array of pointers
//iterate throught the array
for ( int count = 0; count < NUM_DONATIONS; count++ )
arrPtr[count] = &(donations.amount[count]);
for ( int count = 0; count < NUM_DONATIONS; count++)
arrPtr[count] = &(donations.donorNum[count]);
//call the Bubble Sort function
arrBubbleSort ( arrPtr, NUM_DONATIONS ) ;
//output the array in ascending order using the pointers
outFile << "The donations, sorted in ascending order are: \n";
showArrPtr ( arrPtr, NUM_DONATIONS, outFile ) ;
//output the array in its original order using ints
outFile << "The donations, in their original order are: \n";
showArray ( donations.amount, donations.donorNum, NUM_DONATIONS, outFile ) ;
//close the output file
outFile.close () ;
system ( "pause" ) ;
return 0;
}
|