Dynamic Allocation for Arrays

I need help figuring out the code to allocate the memory for my arrays in the create array function.

#include <iostream>
#include <cstdlib>

using namespace std;

typedef int* IntPtr;

const int NUMLABS = 4;

/*
Creates the dynamic arrays for the labs.
@param labs: the array of labs.
@param labsizes: contains the size (or number of computers) of each lab
This dictates the size of the dynamic array.
*/

void createArrays(IntPtr labs[], int labsizes[]);

/*
FreeArrays:
Releases memory we allocated with "new".
*/

void freeArrays(IntPtr labs[]);

/*
ShowLabs:
Displays the status of all labs (who is logged into which computer).
*/

void showLabs (IntPtr labs[], int labsizes[]);

/*
Login:
Simulates a user login by asking for the login info from the console.
*/

void login(IntPtr labs[], int labsizes[]);

/*
Logoff:
Searches through the arrays for the input user ID and if found logs that user out.
*/

void logoff(IntPtr labs[], int labsizes[]);

/*
Search:
Searches through th arrays for the input user ID and if found outputs the station number.
*/

void search(IntPtr labs[], int labsizes[]);

int main()
{

IntPtr labs[NUMLABS];
int labsizes[NUMLABS];
int choice = -1;

cout << "Welcome to the LabMonitorProgram!" << endl;

//Prompt the user to enter labsizes
cout << "Please enter the number of computer stations in each lab: ";
for (int i=0; i < NUMLABS; i++) {
do
{
cout << "How many computers in Lab " << i+1 << "?";
cin >> labsizes [i];
} while (labsizes[i] < 0);
}

// Create ragged array structure
createArrays(labs, labsizes);

// Main Menu
while (choice != 0)
{
cout << endl;
showLabs(labs, labsizes);
cout << "MAIN MENU" << endl;
cout << "0) Quit" << endl;
cout << "1) Simulate login" << endl;
cout << "2) Simulate logoff" << endl;
cout << "3) Search" << endl;
cin >> choice;
if (choice == 1)
{
login(labs, labsizes);
}
else if (choice == 2)
{
logoff(labs, labsizes);
}
else if (choice == 3)
{
search(labs, labsizes);
}
}

freeArrays(labs); // Free memory before exiting
return 0;

}

void createArrays(IntPtr labs[], int labsizes[])
{
labs = new int[labsizes];
}


void freeArrays(IntPtr labs[])
{



}



void showLabs(IntPtr labs[], int labsizes[])
{

int i;
int j;

cout << "LAB STATUS" << endl;
cout << "Lab # Computer Stations" << endl;
for (i=0; i < NUMLABS; i++)
{

cout << i+1 << " ";
for (j=0; j <labsizes[i]; j++)
{
cout << (j+1) << ": ";
if (labs[i][j] == -1)
{
cout << "empty ";
}
else
{
cout << labs[i][j] << " ";
}
}
cout << endl;
}
cout << endl;
return;

}

void login(IntPtr labs[], int labsizes[])
{
int id, lab, num = -1;

do
{
cout << "Enter the 5 digit ID number of the user logging in: " << endl;
cin >> id;
} while ((id < 0) || (id > 99999));

do
{
cout << "Enter the lab number the user is logging in from (1-" << NUMLABS << "):" <<endl;
cin >> lab;
} while ((lab < 0) || (lab > NUMLABS));

do
{
cout << "Enter computer station number the user is logging in to " << "(1-" << labsizes[lab-1] << "):" << endl;
cin >> num;
} while ((num < 0) || (num > labsizes[lab-1]));

if (labs[lab - 1][num - 1] != -1)
{
cout << "ERROR, user " << labs[lab-1][num-1] << " is already logged into that station." << endl;
return;
}

labs[lab-1][num-1] = id;
return;
}

void logoff(IntPtr labs[], int labsizes[])
{

int id, i, j;

do
{
cout << "Enter the 5 digit ID number of the user to find: " << endl;
cin >> id;
} while ((id < 0) || (id > 99999));

for (i=0; i < NUMLABS; i++)
{
for (j=0; j < labsizes[i]; j++)
{
if (labs[i][j] == id)
{
labs[i][j] = -1;
cout << "User " << id << " is logged off." << endl;
return;
}
}
}
cout << "That user is not logged in." << endl;
return;
}

void search(IntPtr labs[], int labsizes[])
{


}
Please use code tags when posting code, to make it readable:

http://www.cplusplus.com/articles/z13hAqkS/
Topic archived. No new replies allowed.