Programming Assignment 05 - Computer Monitoring Labs ComputerLab.cpp This project is adapted from Programming Project #5 on
Question:
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 theloginandlogoff, your program also supports asearchcommand that looks up whether a certain user is using any computer station or not.
Your program then needs todynamically allocatespace for the currentlabsarray of arrays using the entry inlabsizesthat corresponds (same index) to thelabs[index]for the size. Please start with the starter code (as found on Blackboard) as it controls theMenuandshowLabsdisplays.
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 definitiontypedef int* IntPtr;// Constantsconst 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> // Prompt the user to enter labsizes cout \"please>for (int i=0; i { do { cout \"how> cin >> labsizes[i]; } while (labsizes[i]0);>} // Create ragged array structure createArrays(labs, labsizes); // Main Menu while (choice != 0) { cout cout cout cout cout cout 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 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 cout Computer Stations\" for (i=0; i { cout \"; for (j=0; j { cout if (labs[i][j] == -1) { cout } else { cout } } cout } cout 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 isbolded):
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
MAIN MENU 0) Quit 1) Simulate login 2) Simulate logout 3) Search 1 Enter the 5 digit ID number of the user logging in: 22222 Enter the lab number the user is logging in from (1-4): 2 Enter computer station number the user is logging in to (1-5): 2 LAB STATUS Lab # Computer Stations 1 1: empty 2: empty 3: empty 4: empty 2 1: empty 2: 22222 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
MAIN MENU 0) Quit 1) Simulate login 2) Simulate logout 3) Search 3 Enter the 5 digit ID number of the user logging in: 22222 User 22222 logged in Lab 2 at computer 2
MAIN MENU 0) Quit 1) Simulate login 2) Simulate logout 3) Search 2 Enter the 5 digit ID number of the user logging in: 11111 User not logged in. LAB STATUS Lab # Computer Stations 1 1: empty 2: empty 3: empty 4: empty 2 1: empty 2: 22222 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 4: empty
MAIN MENU 0) Quit 1) Simulate login 2) Simulate logout 3) Search 2 Enter the 5 digit ID number of the user logging in: 33333 Logout user 33333 in Lab 3 at computer 3 LAB STATUS Lab # Computer Stations 1 1: empty 2: empty 3: empty 4: empty 2 1: empty 2: 22222 3: empty 4: empty 5: empty 3 1: empty 2: empty 3: empty 4: empty 5: empty 6: empty 4 1: empty 2: empty 3: empty 4: empty
MAIN MENU 0) Quit 1) Simulate login 2) Simulate logout 3) Search