Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Current Trends In Database Technology Edbt 2004 Workshops Edbt 2004 Workshops Phd Datax Pim P2panddb And Clustweb Heraklion Crete Greece March 2004 Revised Selected Papers Lncs 3268

Authors: Wolfgang Lindner ,Marco Mesiti ,Can Turker ,Yannis Tzitzikas ,Athena Vakali

2005th Edition

3540233059, 978-3540233053

More Books

Students also viewed these Databases questions