pointer array

I'm looking to show the amounts stored in the array that i saved using a pointer, but i am only getting back the dresses when i use my .show function. i could use some direction on what i should fix






# include <iostream>

using namespace std;

//moviegoers class
class movieGrs
{
private: int students, *location;
public:
void selectSort(int[],int);
void getStudents();
void makeLocation();
void loadArray(){cin>>location[students];}
int takeStudents(){return students;}
void show();

};

void movieGrs::show()
{ for(int x =0; x < students; x++)
cout << location[x] << " " << endl;
}

void movieGrs::getStudents() {cin >> students;}

void movieGrs::makeLocation(){location = new int[students];}


//void movieGrs::selectSort(int location[],int students)
//{
// int startScan, minValue, minIndex;
//
// for(int index = 0; index < (students -1); index++)
// {
// minIndex = startScan;
// minValue = location[startScan];
// for( int index = startScan +1; index < students; index++)
// {
// if(location[index] < minValue)
// {
// minValue= location[index];
// minIndex = index;
// }
// }
//
// location[minIndex] = location[startScan];
// location[startScan] = minValue;
// }
//}








int main()
{

movieGrs stats;

cout << "Please enter the amount of student that have been survayed for the last month" << endl << endl;
stats.getStudents();

stats.makeLocation();


for(int index = 0; index < stats.takeStudents(); index++)
{
cout << "Please enter the amount of movies seen by student " << index +1 << endl;
stats.loadArray();
}

stats.show();





system("PAUSE");
}

I did not look through all your code but it is obvious that this function

void loadArray(){cin>>location[students];}


is invalid. You are trying to enter one element of your array outside allocated memory. You shall use a loop to enter a value for every elemnt of the array.
Last edited on
Topic archived. No new replies allowed.