Question: PLEASE DO IN C++ Programming Assignment 05 - Computer Monitoring Labs ComputerLab.cpp This project is adapted from Programming Project #5 on Page 520 of Savitch

PLEASE DO IN C++

Programming Assignment 05 - Computer Monitoring Labs ComputerLab.cpp

This project is adapted from Programming Project #5 on Page 520 of Savitch 9th Edition. To solve this problem, we will be using dynamic arrays.

Problem Description

You run four computer labs. Each lab contains certain number of computer stations to be determined at runtime.

Your program should keep track of the status of each computer station, whether it's empty or used by some user. Whenever a user (identified by 5-digit ID number) logs in or logs off, the program updates its data, and displays the new status of the lab.

In addition to the login and logoff, your program also supports a search command that looks up whether a certain user is using any computer station or not.

Your program then needs to dynamically allocate space for the current labs array of arrays using the entry in labsizes that corresponds (same index) to the labs[index] for the size. Please start with the starter code (as found on Blackboard) as it controls the Menu and showLabs displays.

Please implement the following functions:

void createArrays(IntPtr labs[], int labsizes[]); // should dynamically allocate the arrays.

void freeArrays(IntPtr labs[]); // should free the arrays

void search(IntPtr labs[], int labsizes[]); // should search for the user in the lab

void login(IntPrt labs[], int labsizes[]) //should log the user in, reading in and validating the users ID number, lab number, and computer number, in that order.

void logout(IntPtr labs[], int labsizes[]); // should logout the user from the lab

Don't forget to add a comment at the top of the function declaration to explain what it does, and add comments throughout the code explaining the process. Flesh out the function comments in the starter code!

STARTER CODE

/* Include Header Comment Here */ #include  using namespace std; // 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[]); /* 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 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; cout << "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); } } freeArrays(labs); // Free memory before exiting cout << "Bye! "; 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 # 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[]) { //Implement the Code! } void logout(IntPtr labs[], int labsizes[]) { //Implement the Code! } void search(IntPtr labs[], int labsizes[]) { //Implement the Code! }

EXAMPLE OUTPUT

An example execution of the program is displayed below (user input is bolded):

Welcome to the LabMonitorProgram! Please enter the number of computer stations in each lab: How many computers in Lab 1?4 How many computers in Lab 2?5 How many computers in Lab 3?6 How many computers in Lab 4?4

MAIN MENU

0) Quit 1) Simulate login 2) Simulate logout

3) Search 1 Enter the 5 digit ID number of the user logging in: 33333 Enter the lab number the user is logging in from (1-4): 3 Enter computer station number the user is logging in to (1-6): 3 LAB STATUS Lab # Computer Stations 1 1: empty 2: empty 3: empty 4: empty 2 1: empty 2: empty 3: empty 4: empty 5: empty 3 1: empty 2: empty 3: 33333 4: empty 5: empty 6: empty 4 1: empty 2: empty 3: empty

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!