Question: only in c++ please, use dynamic arrays or just arrays to make the code. keep it simple please and don't delete any of the original

only in c++ please, use dynamic arrays or just arrays to make the code. keep it simple please and don't delete any of the original code.

/* Include Header Comment Here

*/

#include

using namespace std;

int numberOfLabs;

// Type definition

typedef int* IntPtr;

// Constants

const int NUMLABS = 4;

// Function prototypes

/*

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.

@precondition: labsize[0] is the # of computers in lab1,

labsize[1] is the # of computers in lab2, ...

@postcondition: labs[0] points to lab1's array (of size given by labsize[0])

labs[1] points to lab2's array (of size given by labsize[1])

...

*/

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

for(int i=0;i

// allocating memory to the labsize

int *temp;

temp = (int*)malloc(labsizes[i]*(sizeof(int)));

labs[i] = temp;

for(int j=0;j

{

labs[i][j] = -1;

}

}

}

/*

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[]);

// ======================

// logout:

// Searches through the arrays for the input user ID and if found

// logs that user out.

// ======================

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

// ======================

// search:

// Searches through the arrays for the input user ID and if found

// outputs the station number.

// ======================

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

// ======================

// main function

// ======================

int main()

{

IntPtr labs[NUMLABS]; // store the pointers to the dynamic array for each lab

int labsizes[NUMLABS]; // Number of computers in each lab

int choice = -1;

cout <<"Welcome to the LabMonitorProgram! ";

// 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 are in the Lab ? "<< i+1<<"?";

cin >> labsizes[i];

} while (labsizes[i]<0);

}

// Create ragged array structure

createArrays(labs, labsizes);

// Main Menu

while (choice != 0)

{

cout << endl;

cout << "Welcome to the MAIN MENU" << endl;

cout << "0) Quit" << endl;

cout << "1) Simulate login" << endl;

cout << "2) Simulate logout" << endl;

cout << "3) Search" << endl;

cin >> choice;

if (choice == 1)

{

login(labs, labsizes);

showLabs(labs, labsizes);

}

else if (choice == 2)

{

logout(labs, labsizes);

showLabs(labs, labsizes);

}

else if (choice == 3)

{

search(labs, labsizes);

}

else if (choice == 0 )

freeArrays(labs); // Free memory before exiting

cout << "Bye! ";<

break;

}

}

return 0;

}

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

{

//Implement the Code!

//Hint: for each of the 4 labs, dynamically allocate an int array of size given by the number of computers in the lab.

}

void freeArrays(IntPtr labs[])

{

//Implement the Code!

}

/* showLabs:

Displays the status of all labs (who is logged into which computer).

Precondition: labs[] is a multidimension array of labs with computers

labsizes[i] contains the size of the array in labs[i]

*/

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

{

int i;

int j;

cout << "Lab Status " << endl;

cout << "Lab # of 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[])

{

}

void logout(IntPtr labs[], int labsizes[])

{

//Implement the Code!

}

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

{

//Implement the Code!

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!