Struct of Arrays and pointer manipulation

Ok I have the program all done, but when I compile to run I get this popup that says Project5.exe has encountered a problem and has to close...could someone please tell me where the problem is...I can't find it. Thanks

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;
    
}
    


1
2
3
4
5
6
7
8
//This function iterates through the array and shows the array information
//in its original form in terms of ints

#include <iostream>
#include <fstream>
using namespace std;

void showArray ( int [], int [], int, ofstream &outFile ) ;


1
2
3
4
5
6
7
8
9
#include "showArray.h"

void showArray ( int array[], int array2[], int size, ofstream & outFile )
{
     for ( int count = 0; count < size; count++ )
         outFile << array[count] << " " <<"From Donor: " << array2[count] << " " ;
         outFile << endl;
    
}


1
2
3
4
5
6
7
8
//This function uses and array of pointers to show the information in the
//original array in ascending order in terms of pointers

#include <iostream>
#include <fstream>
using namespace std;

void showArrPtr ( int *[], int, ofstream &outFile ) ;


1
2
3
4
5
6
7
8
9
10
11
#include "showArrPtr.h"


void showArrPtr ( int *array[], int size, ofstream & outFile )
{
     
    
     for ( int count = 0; count < size; count++ )
         outFile << *( array[count] ) << " "  ;
         outFile << endl;
}


1
2
3
4
5
6
7
8
//This function uses a Bubble Sort to sort the information in the array
//using an array of pointers 

#include <iostream>
#include <fstream>
using namespace std;

void arrBubbleSort ( int *[], int ) ;


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "arrBubbleSort.h"


void arrBubbleSort ( int *array[], int size )
{
     bool swap;
     int* temp;
     
     do
     {
         swap = false;
         for ( int count = 0; count < (size -1); count++ )
         {
             if ( *array[count] > *array[count +  1] )
             {
                temp = array[count];
                array[count] = array[count + 1];
                array[count + 1] = temp;
                swap = true;
                
             }
         }
     } while ( swap );
}    
I don't know what this does:

1
2
3
4
5
6
7
8
9
10
11
12
 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);


struct Donor should have the array size defined in it.

1
2
3
4
5
 struct Donor    
    {
        int amount[NUM_DONATIONS]; 
        int donorNum[NUM_DONATIONS];
    };                                    

Topic archived. No new replies allowed.