Dynamic Array. Struggling!!

I am having a lot of trouble with this project. We have 3 projects due by midnight and the first two I have done flawlessly but I can not figure this one out at all, I honestly don't know where to even start. Please please help, I am so stressed!!!

The directions are: Modify Program 10-19 (the United Cause case study program) so it can be used with any set of donations. The program should dynamically allocate the donations array and ask the user to input its values. Using a dynamic array is mandatory.Save your source code with the following names: Ch10_19.cpp (modified), dinlist.h, donlist.cpp.

I will include the code for 10-19 and donlist.h I have read the book up and down on arrays and I am just lost. I will also include the external files used in a reply. I am not sure how I end up with three files either.

Any help is very greatly appreciated. Thank you.
Main Code
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
 
#include <iostream>
#include "donlist.h"
using namespace std;

int main()
{
	const int FUNDS = 15;
	int donations[FUNDS]; // Holds sets of donations
	
	// Input amount of funds donated by each person (set)
	
	cout << "Enter the amount donated by each person: " << FUNDS << " donations: ";
	cin >> donation[0];
	cin >> donation[1];
	cin >> donation[2];
	cin >> donation[3];
	cin >> donation[4];
	cin >> donation[5];
	cin >> donation[6];
	
	// Display the contents of the array
	cout << "The donations you entered are: ";
	cout << " " << donation[0];
	cout << " " << donation[1];
	cout << " " << donation[2];
	cout << " " << donation[3];
	cout << " " << donation[4];
	cout << " " << donation[5];	
	cout << " " << donation[6] << endl;
	return 0;
	
	double funds[] = {5,  100, 5,  25, 10,
		            5,  25,  5,  5,  100,
		            10, 15,  10, 5,  10 };	                    				
	DonationList ckGraphics(15, funds);
	cout << "The donations sorted in ascending order are:\n";
	ckGraphics.showSorted();
	cout << "The donations in their original order are:\n";
	ckGraphics.show();
	system("pause");
	return 0;
}


External File
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#ifndef DONLIST_H
#define DONLIST_H

class DonationList
{
private:
	int numDonations;
	double *donations;
	double **arrPtr;
	void selectSort();
public:
	DonationList(int num, double gifts[]);
     ~DonationList(); 
	void show();
	void showSorted();
};
#endif 
Below is the example of dynamically allocated array,

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
#include <iostream>

int main()
{

    double *donations = nullptr; // To dynamically allocate an array.
    int numberofPerson = 0;
    double totalOfDonations = 0.0;

    // Ask the user to input the number of people donating.
    std::cout << "Enter the amount of people who donated.\n";
    std::cout << ">>> ";
    std::cin >> numberofPerson;

    //Dynamically allocate an array large enough to hold
    // that many number of people who donated.
    donations = new double[numberofPerson];

    // Run a for loop to input the donations based on number of people.
    for (int count = 0; count < numberofPerson; count++)
    {
	   std::cout << "Enter the donations for person number " << count + 1 << ":\n";
	   std::cout << ">>> ";
	   std::cin >> donations[count];
	   totalOfDonations += donations[count];
    }

    // Run a for loop to display the list of the people who donated and their donations.
    std::cout << "Displaying the number of people who donated and their donations...\n";
    for (int count = 0; count < numberofPerson; count++)
    {
	   std::cout << "Person number " << count + 1 << " donated $" << donations[count] << std::endl;

    }

	   std::cout << "The total of donations is $" << totalOfDonations << std::endl;
    // Free dynamically allocated memory.
    delete[] donations;
    donations = nullptr;


    return 0;
}
Last edited on
Topic archived. No new replies allowed.