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