Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Getting ton of errors: IntelliSense: name followed by \'::\' must be a class or

ID: 3686323 • Letter: G

Question

Getting ton of errors: IntelliSense: name followed by '::' must be a class or namespace name  
and have a lot of undefined errors but I declared those in class so I don't get what's wrong??

I'm using Visual Studio 2012

//donlist.h

#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

//donlist.cpp

#include <iostream> //needed for cout

#include "donlist.h"

using namespace std;

//**********************************************************

// Constructor. *

// The argument passed to num indicates the number of *

// elements in array passed to gifts. The gifts array *

// holds the list of donation values. The constructor *

// allocates the donations and arrPtr arrays. The gifts *

// array is copied to the donations array. The elements *

// of the arrPtr array are made to point to the elements *

// of the donations array, and then sorted in ascending *

// order by the selectSort function. *

//**********************************************************

DonationList::DonationList(int num, double gifts[])

{

numDonations = num;

if (num > 0)

{

// Allocate an array of doubles.

United Cause Relief Agency Case Study 667

donations = new double[num];

// Allocate an array of pointers-to-doubles.

arrPtr = new double*[num];

// Initialize the arrays.

for (int count = 0; count < numDonations; count++)

{

donations[count] = gifts[count];

arrPtr[count] = &donations[count];

}

// Now, sort the array of pointers.

selectSort();

}

}

//**********************************************************

// Destructor frees the memory allocated by the constructor*

//**********************************************************

DonationList::~DonationList()

{

if (numDonations > 0)

{

delete [ ] donations;

donations = 0;

delete [ ] arrPtr;

arrPtr = 0;

}

}

//************************************************************

// The selecSort function performs a selection sort on the *

// arrPtr array of pointers. The array is sorted on the *

// values its elements point to. *

//************************************************************

void DonationList::selectSort()

{

int minIndex;

double *minElem;

for (int scan = 0; scan < (numDonations - 1); scan++)

{

minIndex = scan;

minElem = arrPtr[scan];

for(int index = scan + 1; index < numDonations; index++)

{

if (*(arrPtr[index]) < *minElem)

{

minElem = arrPtr[index];

minIndex = index;

}

}

arrPtr[minIndex] = arrPtr[scan];

arrPtr[scan] = minElem;

}

}

//*******************************************************

// The show function uses cout to display the donations *

// array in sequential order. *

//*******************************************************

void DonationList::show()

{

for (int count = 0; count < numDonations; count++)

cout << donations[count] << " ";

cout << endl;

}

//*********************************************************

// The showSorted function uses cout to display the values*

// pointed to by the elements of the arrPtr array. Since *

// arrPtr is sorted, this function displays the elements *

// of the donations array in ascending order. *

//*********************************************************

void DonationList::showSorted()

{

for (int count = 0; count < numDonations; count++)

cout << *(arrPtr[count]) << " ";

cout << endl;

}

int main()

{

   double *funds;

   int n;

   cout << "Enter size of donation list";

   cin >> n;

   funds=new double[n];

   cout << "Enter values" << endl;

   for(int i=0; i<n; i++)

   { cin >> funds[i]; }

   DonationList ckGraphics(15, funds);

   cout << "The donations sorted in ascending order are: ";

   ckGraphics.showSorted();

   cout << "The donations in their original order are: ";

   ckGraphics.show();

  

   system("pause")

   return 0;

}

Explanation / Answer

main.cpp
#include <iostream>
#include <cstdlib> // for malloc.
#include "donlist.h"
using namespace std;

int main()
{

// dynamically allocate space for array.
int numFunds;
cout << "Enter number of funds: ";
cin >> numFunds;
double *funds = (double *)malloc(sizeof(double) * numFunds);
for (int i = 0; i < numFunds; i++) {
    cout << "Enter fund " << i << " : ";
    cin >> funds[i];
}

/*double funds[]={5, 100, 5, 25, 10,
          5, 25, 5, 5, 100,
          10, 15, 10, 5, 10 };*/
DonationList ckGraphics(numFunds, funds);
cout << "The donations sorted in ascending order are:" << endl;
ckGraphics.showSorted();
cout << "The donations in their original order are:" << endl;
ckGraphics.show();
return 0;
}

donlist.h

#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

donlist.cpp
#include <iostream>
#include "donlist.h"
using namespace std;
DonationList::DonationList(int num, double gifts[])
{
numDonations = num;
if (num > 0)
    {
      // Allocate an array of doubles.
      donations = new double[num];
      // Allocate an array of pointers-to-doubles.
      arrPtr = new double*[num];
      // Initialize the arrays.
      for (int count = 0; count < numDonations; count++)
        {
      donations[count] = gifts[count];
      arrPtr[count] = &donations[count];
        }
      // Sort the array of pointers
      selectSort();
    }
}
//***********************************************************
// Destructor frees the memory allocated by the constructor *
//***********************************************************
DonationList::~DonationList()
{
if (numDonations > 0)
    {
      delete[] donations;
      donations = 0;
      delete[] arrPtr;
      arrPtr = 0;
    }
}
//***********************************************************
// The selecSort functions performs a selection sort on the *
// arrPtr array of pointers. The array is sorted on the     *
// values its elements point to.                            *
//***********************************************************
void DonationList::selectSort()
{
int minIndex;
double *minElem;
for (int scan = 0; scan < (numDonations - 1); scan++)
    {
      minIndex = scan;
      minElem = arrPtr[scan];
      for (int index = scan + 1; index < numDonations; index++)
        {
      if (*(arrPtr[index]) > *minElem)
            {
          minElem = arrPtr[index];
          minIndex = index;
            }
        }
      arrPtr[minIndex] = arrPtr[scan];
      arrPtr[scan] = minElem;
    }
}
//*********************************************************
// The show function uses cout ot display the donations   *
// array in sequential order                              *
//*********************************************************
void DonationList::show()
{
for (int count = 0; count < numDonations; count++)
    {
      cout << donations[count] << " ";
    }
cout << endl;
}
//***********************************************************
// The showSorted functions uses cout to display the values *
// pointed to by the elements of the arrPtr array. Since    *
// arrPtr is sorted, this function displays the elements    *
// of the donations array in ascending order.               *
//***********************************************************
void DonationList::showSorted()
{
for (int count = 0; count < numDonations; count++)
    {
      cout << *(arrPtr[count]) << " ";      
    }
cout << endl;
}


sample output

Enter number of funds: 5                                                                                                                                    
Enter fund 0 : 50000                                                                                                                                        
Enter fund 1 : 4000                                                                                                                                         
Enter fund 2 : 3000                                                                                                                                         
Enter fund 3 : 2000                                                                                                                                         
Enter fund 4 : 10000                                                                                                                                        
The donations sorted in ascending order are:                                                                                                                
50000 10000 4000 3000 2000                                                                                                                                  
The donations in their original order are:                                                                                                                  
50000 4000 3000 2000 10000                                                                                                                                  

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote