home / study / questions and answers / engineering / computer science / you run
ID: 3773391 • Letter: H
Question
home / study / questions and answers / engineering / computer science / you run four computer labs, each lab contains computer ...
Your question has expired and been refunded.
We were unable to find a Chegg Expert to answer your question.
Question
You run four computer labs, Each lab contains computer stations that are numbered as shown in the table below:
Lab Number
Computer Station Numbers
1
1 - 5
2
1 - 6
3
1 - 4
4
1 - 3
Each user has a unique five-digit ID number. Whenever a user logs on, the user’s ID, lab number, and the computer station number are transmitted to your system. For example, if user 49193 logs onto station 2 in lab 3, then your system receives (49193, 2, 3) as input data. Similarly, when a user logs off a station, then your system receives the lab number and the computer station number.
Write a computer program that could be used to track, by lab, which user is logged onto which computer. For example, if 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 display the following:
Lab# Computer Stations
1 1: empty 2: empty 3: empty 4: empty 5: empty
1 1: empty 2: empty 3: empty 4: empty 5: empty 6:empty
3 1: empty 2: 49193 3: empty 4: empty
4 1: 99577 2: empty 3: empty
Create a menu that allows the administrator to stimulate the transmission of information by manually typing in the login of logoff data. Whenever someone logs in or out, the display should be updated. Also write 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 “None” if the user ID is not logged into any computer station.
You should use a fixed array of length 4 for the labs. Each array entry points to a dynamic array that stores the user login information for each respective computer station.
The structure is shown in the figure below. This structure is sometimes called a ragged array since the columns are of unequal length.
#include <iostream>
#include <cstdlib>
using namespace std;
int **dynArray(int row, int cols)
{
int **myPtr;
int lab[4];
myPtr = new int *[row];
for(int i = 0; i < row; i++)
myPtr[i] = new int[lab[i]];
for(int i = 0; i<row ; i++)
if(myPtr[i] == 0)
cout<<"empty";
return myPtr;
}
void getinput(int ID,int &Station,int &labnumb)
{
cout<<" Enter your ID number: "<<endl;
cin>>ID;
cout<<" Enter your station number: "<<endl;
cin>>Station;
cout<<" Enter your lab number: "<<endl;
cin>>labnumb;
return;
}
void logout(int ID,int &Station,int &labnumb)
{
cout<< "You have been logged out."<<endl;
return;
}
void login(int **dynArray,int ID,int &Station,int &labnumb)
{
dynArray[labnumb][Station] = ID;
return;
}
bool search(int **dynArry,int ID,int &row,int &cols,int lab[])
{
cout<<"Enter user ID to check: "<<endl;
cin>>ID;
bool found = false;
for(int i = 0; i < row;i++)
for(int j = 0; j < lab[i];j++)
if(ID == dynArry[i][j])
{
found = true;
row = i;
cols = j;
}
return found;
}
void Menu(int **dynArray,int ID,int &Station,int &labnumb,int lab[])
{
int choice;
cout<<"Enter 1 for login, 2 for search,3 for exit. "<<endl;
cin>>choice;
if(choice == 1)
login(dynArray,ID,Station,labnumb);
if(choice == 2)
search(dynArray,ID,Station,labnumb,lab);
if(choice == 3)
exit(0);
}
int main()
{
int lab[4];
lab[0] = 5;
lab[1] = 6;
lab[2] = 4;
lab[3] = 3;
int **labmain;
labmain = new int*[4];
for(int i = 0; i <4 ; i++)
{
*(labmain + i) = new int;
}
labmain = dynArray(4,7);
int ID,Station,labnumb;
Menu(dynArray,ID,Station,labnumb,lab);
system("PAUSE");
return 0;
}
I keep getting error messages for this code. Can someone please fix it and let me know what I did wrong. I provided the assignment prompt above so you can refer to it.
Lab Number
Computer Station Numbers
1
1 - 5
2
1 - 6
3
1 - 4
4
1 - 3
Explanation / Answer
Program:
Lab.h:
#ifndef LAB_H
#define LAB_H
#include <iostream>
#include <string>
namespace csc161
{
class Lab_T
{
public:
friend bool operator ==(const Lab_T& lab1, const Lab_T& lab2);
Lab_T();
Lab_T(std::string p_lab_name, unsigned int p_lab_size);
Lab_T(const Lab_T& p_lab);
~Lab_T();
std::string getLabName() const;
void setLabSize(std::string p_lab_name);
unsigned int getLabSize() const;
void setLabSize(unsigned int p_lab_size);
ComputerPtr getComputers();
friend ostream& operator <<(ostream& outs, const Lab_T& the_object);
private:
std::string lab_name;
int lab_size;
ComputerPtr computers;
};
typedef Lab_T* LabPtr;
}
#endif
Computer.h:
#ifndef COMP_H
#define COMP_H
#include <iostream>
#include <string>
using namespace std;
namespace csc161
{
class Computer_T
{
public:
friend bool operator ==(const Computer_T& comp1, const Computer_T& comp2);
Computer_T();
Computer_T(string model);
Computer_T(const Computer_T& p_computer);
// Destructor
~Computer_T();
void set(string model);
string get_model() const;
void reboot();
void putOffline();
void putOnline();
bool isAvailable();
int whoIsLoggedIn();
void signon(int p_student_id);
void signoff();
friend istream& operator >>(istream& ins, Computer_T& the_object);
friend ostream& operator <<(ostream& outs, const Computer_T& the_object);
private:
string model;
bool online;
bool available;
int student_id;
};
typedef Computer_T* ComputerPtr;
}
#endif
Lab.cpp:
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
#include "Computer.h"
#include "Lab.h"
namespace csc161
{
bool operator ==(const Lab_T& lab1, const Lab_T& lab2)
{
return (lab1.getLabSize() == lab2.getLabSize());
};
Lab_T::Lab_T(string p_lab_name, unsigned int p_lab_size) {
lab_name = p_lab_name;
computers = new Computer_T[p_lab_size];
for (unsigned int j = 0; j<p_lab_size; j++)
{
computers[j].reboot();
}
};
Lab_T::Lab_T(const Lab_T& p_lab) {};
Lab_T::Lab_T() {};
Lab_T::~Lab_T() {
delete[] computers;
};
std::string Lab_T::getLabName() const { return lab_name; };
void Lab_T::setLabSize(std::string p_lab_name) { };
unsigned int Lab_T::getLabSize() const { return lab_size; };
void Lab_T::setLabSize(unsigned int p_lab_size) { };
ComputerPtr Lab_T::getComputers() {
return computers;
};
ostream& operator <<(ostream& outs, const Lab_T& the_object)
{
outs << "Lab - " << the_object.lab_name << " :: " << the_object.lab_size << endl;
return outs;
}
}
Computer.cpp:
#include "stdafx.h"
#include <iostream>
#include <string>
#include "Computer.h"
using namespace std;
const int OPEN = -1;
namespace csc161
{
std::string Computer_T::get_model() const { return model; };
bool operator ==(const Computer_T& comp1, const Computer_T& comp2)
{
return comp1.get_model() == comp2.get_model();
};
Computer_T::Computer_T(string p_model) {
model = p_model;
};
Computer_T::Computer_T(const Computer_T& p_computer)
{
ComputerPtr a = new Computer_T;
*a = p_computer;
};
Computer_T::Computer_T() {
model = "";
>
available = true;
student_id = 0;
};
Computer_T::~Computer_T() {};
void Computer_T::reboot()
{
>
available = true;
student_id = OPEN;
};
void Computer_T::putOffline() {
>
};
void Computer_T::putOnline() {
>
};
bool Computer_T::isAvailable() { return available; };
int Computer_T::whoIsLoggedIn() { return student_id; };
void Computer_T::signon(int p_student_id)
{
available = false;
student_id = p_student_id;
};
void Computer_T::signoff()
{
student_id = OPEN;
available = true;
};
istream& operator >>(istream& ins, Computer_T& the_object)
{
ins >> the_object.model;
return ins;
}
ostream& operator <<(ostream& outs, const Computer_T& the_object)
{
{
if (the_object.student_id == OPEN)
outs << "Open ";
else
outs << the_object.student_id;
return outs;
}
}
}
ComputerLabInterface.cpp:
#include "stdafx.h"
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;
#include "Computer.h"
#include "Lab.h"
using namespace csc161;
const int NUMLABS = 4;
void createLabs(LabPtr cscLabs[], int labsizes[]);
void destroyLabs(LabPtr cscLabs[]);
void login(LabPtr cscLabs[], int labsizes[]);
void logoff(LabPtr cscLabs[], int labsizes[]);
void search(LabPtr cscLabs[], int labsizes[]);
void showLabs(LabPtr cscLabs[], int labsizes[]);
bool validID(int p_id)
{
return (p_id < 0 || p_id > 99999);
}
int enterID(int p_id)
{
cout << "Please enter your 5 digit ID." << endl;
validID(p_id);
return p_id;
}
void createLabs(LabPtr cscLabs[], string labNames[], int labSizes[])
{
for (int i = 0; i < NUMLABS; i++)
{
cscLabs[i] = new Lab_T(labNames[i], labSizes[i]);
}
return;
}
void destroyLabs(LabPtr cscLabs[])
{
int i;
for (i = 0; i < NUMLABS; i++)
{
delete cscLabs[i];
}
return;
}
void showLabs(LabPtr cscLabs[], int labsizes[])
{
int i, 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) << ": ";
cout << cscLabs[i]->getComputers()[j];
}
cout << endl;
}
cout << endl;
}
void login(LabPtr cscLabs[], int labsizes[])
{
int id = -1, lab = -1, num = -1;
while ((id < 0) || (id > 99999))
{
cout << "Enter the 5 digit ID number of the user logging in:" << endl;
cin >> id;
}
while ((lab < 0) || (lab > NUMLABS))
{
cout << "Enter the lab number the user is logging in from (1-" <<
NUMLABS << "):" << endl;
cin >> lab;
}
while ((num < 0) || (num > labsizes[lab - 1]))
{
cout << "Enter computer station number the user is logging in to " <<
"(1-" << labsizes[lab - 1] << "):" << endl;
cin >> num;
}
if (!cscLabs[lab - 1]->getComputers()[num - 1].isAvailable())
{
cout << "ERROR, user " << cscLabs[lab - 1]->getComputers()[num - 1].whoIsLoggedIn() <<
" is already logged into that station." << endl;
return;
}
cscLabs[lab - 1]->getComputers()[num - 1].signon(id);
return;
}
void logoff(LabPtr cscLabs[], int labsizes[])
{
int id = -1, i, j;
while ((id < 0) || (id > 99999))
{
cout << "Enter the 5 digit ID number of the user to find:" << endl;
cin >> id;
}
for (i = 0; i<NUMLABS; i++)
{
for (j = 0; j<labsizes[i]; j++)
{
if (cscLabs[i]->getComputers()[j].whoIsLoggedIn() == id)
{
(cscLabs[i]->getComputers())[j].signoff();
cout << "User " << id << " is logged off." << endl;
return;
}
}
}
cout << "That user is not logged in." << endl;
return;
}
void search(LabPtr cscLabs[], int labsizes[])
{
int id = -1, i, j;
while ((id < 0) || (id > 99999))
{
cout << "Enter the 5 digit ID number of the user to find:" << endl;
cin >> id;
}
for (i = 0; i<NUMLABS; i++)
{
for (j = 0; j<labsizes[i]; j++)
{
if (cscLabs[i]->getComputers()[j].whoIsLoggedIn() == id)
{
cout << "User " << id << " is in lab " << i + 1 <<
" at computer " << j + 1 << endl;
return;
}
}
}
cout << "That user is not logged in." << endl;
return;
}
int main()
{
int choice;
LabPtr cscLabs[NUMLABS];
int labSizes[NUMLABS] = { 5, 6, 4, 3 };
string labNames[NUMLABS] = { "Lab-A", "Lab-B", "Lab-C", "Lab-D" };
createLabs(cscLabs, labNames, labSizes);
while (true)
{
cout << endl;
showLabs(cscLabs, labSizes);
cout << "MAIN MENU" << endl;
cout << "0) Quit" << endl;
cout << "1) Simulate login" << endl;
cout << "2) Simulate logoff" << endl;
cout << "3) Search" << endl;
cin >> choice;
switch (choice)
{
case 0:
system("pause");
return 0;
break;
case 1:
login(cscLabs, labSizes);
break;
case 2:
logoff(cscLabs, labSizes);
break;
case 3:
search(cscLabs, labSizes);
break;
default:
break;
};
}
destroyLabs(cscLabs);
system("pause");
return 0;
}
Sample Output:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.