Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work…..

C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work stations that are numbered as shown in the table below:

Lab Number Computer station numbers
1 1-19
2 1-15
3 1-24
4 1-33
5 1-61
6 1-17
7 1-55
8 1-37

We are going to build each lab as an array. We also will be using a strategy to make these structures which allows them to be different sizes, and this is known as a jagged structure. We will be using a separate array for each university’s computer lab, and those arrays will be different sizes based upon the number of labs required by each university. For example, The University of Akron may have 44 lab stations while Case Western University may have 28, and so on.

We are going to create an additional data structure to help out with our programming efforts by reducing the amount of coding that we have to do. We will build an array which holds the values (above) of the maximum number of possible stations for each given computer labs. These represent the sizes of the jagged member arrays. So this array will simply be used to build the 2D jagged arrays (see design of structures below). Let’s consider this static array to be a control support structure.

Each student or user has a unique five-digit ID number. Whenever a user logs on, the user’s ID, the lab number, and the computer station number are transmitted to (input into) your system. For example, if user 49193 logs onto station 2 in lab 3, then your system receives user ID 49193, lab number 3, and computer station number 2 as the input data. Similarly, when a user logs off a station, then your system receives the lab number and computer station number.

Your program is used to track, by lab, which user is logged onto which computer, and additionally the program has the capability to maintain those labs’ computer stations as per the menu-driven requests. The array of lab sizes (one for each lab) holds the values of the maximum number of possible stations for each given lab, and then those sizes are used to build our jagged arrays, that we will dynamically allocate using pointers that point to the elements that each hold the station number values, i.e., the user ID. All labs are of the type int. More details are provided under the design of structures sections. Default values for stations should set to -1 (this indicates it is free or empty).

A sample view of the lab arrays is given here, where user 49193 is logged into station 2 in lab 3 and user 99577 is logged into station 1 of lab 4 then your system might look as follows:

Lab Number Computer station numbers
1 1: empty 2: empty 3: empty 4: empty …… 19: empty
2 1: empty 2: empty 3: empty 4: empty … 15: empty
3 1: empty 2: 49193 3: empty 4: empty ……… 24: empty
4 1: 99577 2: empty 3: empty 4: empty …………… 33: empty
5 1: empty 2: empty 3: empty 4: empty …………………..… 61: empty
6 1: empty 2: empty 3: empty 4: empty .… 17: empty
7 1: 89098 2: 67890 3: empty 4: empty …………………. 55: empty
8 1: 12345 2: 67899 3: empty 4: empty ………….… 37: empty

Design of the structures

To make our program more dynamic, you are given the following code that will create a constant fixed array of length 8 for the labs. This array holds the number of possible work stations. This is a simple array of integers. NUMLABS is also created to enable us to add or subtract a lab. Using constants here allows our program to be much more dynamic in terms of modification efforts and control.

// Global Constants

// Number of computer labs

const int NUMLABS = 8;      

// Number of computers in each lab

const int LABSIZES[NUMLABS] = {19, 15, 24, 33, 61, 17, 55, 37};  

Note: you will need to research creating a jagged array. Array #1 holds the pointers to each member array, call it Array #2, which holds the lab user IDs.

Next establish an array to hold the reference (pointers) for each of the computer stations. This array, an array of pointers, is used in the dynamic allocation for each of the computer stations whose size is determined by the LABSIZES array. The next step would be to dynamically allocate member arrays pointed to by our reference array. Again, each of these holds the information for the respective computer stations. Thus, these are arrays that function as two dimensional. This is a key concept in our project’s implementation that must be followed.

The structure is shown in the figure below. This structure is sometimes also called a ragged array since the columns are of unequal length. Ragged or jagged, this array is an array of arrays. The member arrays can be of different sizes. If you visualize it as output, it produces rows of jagged edges. For our solution we created the member arrays as dynamic arrays.

When we allocate these arrays now, we will use the appropriate pointer from the 8 pointers in the labs array, and thereafter we will store the values into the dynamically allocated memory (the second array), which is also known as the member array.

So, for example, looking at the ragged array above, let’s examine how that works for the first array. The first member array has 6 slots, and so the code should be labs[0] = new int[LABSIZES[0]]. This says the first pointer in the labs array, the array of pointers, is now pointing to a new dynamic array allocated for 6 slots (that is what value would be found at LABSIZES[0]). By virtue of using the NUMLABS value and the values in the LABSIZES array, you can do this all with nested loops.

Looking again at the example, the first array (left) works as the row, and the array with 6 slots (right) works as the columns. The row array are the pointers, and the second array holds the values. You can access this by using the combined [row] [col] processing.

Menu design

Create a repeating menu that allows the administrator to simulate the transmission of information by manually typing in the login or logoff data. Whenever someone logs in or logs out, the array should be updated. Along with the options to log in and log out, include a display option that offers the user the opportunity to print any one of the four labs on the screen. Also, include a search option so that the administrator can type in a user ID and the system will output what lab and station number that user is logged into, or “that user is not logged on” if the user ID is not logged into any computer station.

The user interface design

The user interface must be built as described. Again, any and all entries should be validated. Also, any login actions that find the user seeking an already filled computer should be rejected, and an appropriate message should be displayed such as “this computer station is already in use”.

Again, make use of manipulators such as setw for the output and match the output.

Here is an example of the menu, and the process of login:Student Name Incorporated Computer Lab System MAIN MENU 1) Simulate login 22 Simulate logoff 3) Search 4) Display a lalb 5) Quit Your choice: 1 Enter the 5 digit ID number of the user logging in: 65432 Enter the lab number the user is logging in from(1-8): 4 Enter computer station number the user is logging in to (1-33): 22Here is an example of the menu, and a search request: Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 1

Here is an example of a display request:Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 2

And finally, an example of trying to add to a previously filled slot:Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 3

Note that any user ID can be reused. In other words, we can add 65432 to as many free slots as we wish to.

Normal validation is expected for all entries, and the user ID entries are limited to numbers only, and should always be 5 in length. Properly decompose your program into functions. NO Separate Compilation Files are required at this time

Make use of manipulators for the output. Replace the Student Name heading with your own name (first, last, both…up to you).

Student Name Incorporated Computer Lab System MAIN MENU 1) Simulate login 22 Simulate logoff 3) Search 4) Display a lalb 5) Quit Your choice: 1 Enter the 5 digit ID number of the user logging in: 65432 Enter the lab number the user is logging in from(1-8): 4 Enter computer station number the user is logging in to (1-33): 22

Expert Answer

 

Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 4Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 5Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 6Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 7Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 8Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 9Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 10Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 11

OUTPUT

//PROCESS OF LOG IN

Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 12Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 13

//SEARCH REQUEST

Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 14

//DISPLAY REQUEST

Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 15Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 16

Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 17

// LOG OFF REQUEST

Question & Answer: C++ You can run many computer labs. For now, we will have 8 universities under contract. These labs contain computer stations that hold the actual physical work..... 18

COPYABLE CODE

CODE

SOLUTION

#include <iostream>

#include <cstdlib>

using namespace std;

typedef int* pointer;

const int Numlab = 8;

// Function

void arraycreation(pointer labsval[], int labsvalizes[]);

void arrayfree(pointer labsval[]);

void displaylab(pointer labsval[], int labsvalizes[]);

void lablogin(pointer labsval[], int labsvalizes[]);

void lablogoff(pointer labsval[], int labsvalizes[]);

void searchlog(pointer labsval[], int labsvalizes[]);

//array creation

void arraycreation(pointer labsval[], int labsvalizes[])

{

int i,j;

for (i=0; i < Numlab; i++)

{

labsval[i] = new int[labsvalizes[i]];

for (j=0; j<labsvalizes[i]; j++)

{

labsval[i][j] = -1;

}

}

return;

}

// array free

void arrayfree(pointer labsval[])

{

int i;

for (i=0; i < Numlab; i++)

{

delete [] labsval[i];

}

return;

}

//display lab

void displaylab(pointer labsval[], int labsvalizes[])

{

int i;

int j;

cout << “STUDENDT NAME INCORPORATED” << endl;

cout << “COMPUTER LAB SYSTEM” << endl;

for (i=0; i < Numlab; i++)

{

cout << i+1 << ”         “;

for (j=0; j < labsvalizes[i]; j++)

{

cout << (j+1) << “: “;

if (labsval[i][j] == -1)

{

cout << “empty “;

}

else

{

cout << labsval[i][j] << ” “;

}

}

cout << endl;

}

cout << endl;

return;

}

//lab login

void lablogin(pointer labsval[], int labsvalizes[])

{

int id = -1, lab = -1, numb = -1;

 

while ((id < 0) || (id > 99999))

{

cout << “user logging in please enter 5 digit ID number :” << endl;

cin >> id;

}

while ((lab < 0) || (lab > Numlab))

{

cout << “put the lab number for user is logging in from (1-” <<

Numlab << “):” << endl;

cin >> lab;

}

while ((numb < 0) || (numb > labsvalizes[lab-1]))

{

cout << “the user is logging in to computer station number ” <<

“(1-” << labsvalizes[lab-1] << “):” << endl;

cin >> numb;

}

 

if (labsval[lab-1][numb-1]!=-1)

{

cout << “error occur, user ” << labsval[lab-1][numb-1] <<

” is already logged into that computer station number.” << endl;

return;

}

labsval[lab-1][numb-1] = id;

return;

}

//log off

void lablogoff(pointer labsval[], int labsvalizes[])

{

int id = -1, i,j;

 

while ((id < 0) || (id > 99999))

{

cout << “user logging in please enter 5 digit ID number:” << endl;

cin >> id;

}

for (i=0; i<Numlab; i++)

{

for (j=0; j<labsvalizes[i]; j++)

{

if (labsval[i][j]==id)

{

 

labsval[i][j] = -1;

cout << “User ” << id << ” is logged off.” << endl;

return;

}

}

}

cout << “That user is not logged in.” << endl;

return;

}

//search function

void searchlog(pointer labsval[], int labsvalizes[])

{

int idval = -1, i,j;

 

while ((idval < 0) || (idval > 99999))

{

cout << “user logging in please enter 5 digit ID number:” << endl;

cin >> idval;

}

for (i=0; i<Numlab; i++)

{

for (j=0; j<labsvalizes[i]; j++)

{

if (labsval[i][j]==idval)

{

cout << “User ” << idval << ” is in lab ” << i+1 <<

” at computer ” << j+1 << endl;

return;

}

}

}

cout << “That user is not logged in.” << endl;

return;

}

int main()

{

pointer labsval[Numlab];

int labsvalizes[Numlab];

int cho = -1;

 

labsvalizes[0] = 19;

labsvalizes[1] = 15;

labsvalizes[2] = 24;

labsvalizes[3] = 33;

labsvalizes[4] = 61;

labsvalizes[5] = 17;

labsvalizes[6] = 55;

labsvalizes[7] = 37;

 

arraycreation(labsval, labsvalizes);

 

while (cho != 0)

{

cout << endl;

displaylab(labsval, labsvalizes);

cout << “MAIN MENU” << endl;

 

cout << “1) Simulate lablogin” << endl;

cout << “2) Simulate lablogoff” << endl;

cout << “3) searchlog” << endl;

cout << “4) diplay lab” << endl;

cout << “0) Quit” << endl;

cin >> cho;

if (cho == 1)

{

lablogin(labsval, labsvalizes);

}

else if (cho == 2)

{

lablogoff(labsval, labsvalizes);

}

else if (cho == 3)

{

searchlog(labsval, labsvalizes);

}

else if (cho == 4)

{

displaylab(labsval, labsvalizes);

}

}

arrayfree(labsval);

return 0;

}

Still stressed from student homework?
Get quality assistance from academic writers!