Computer sign-in/sign-out

So I've been trying to code a simulation in which you can sign into a computer in a computer lab. First you must enter in the lab you wish (1-4) and a seat. Each lab has their own specified seats available such as lab 1 has 5 seats while lab 2 has 6. I only have the login function for now because when I call upon the status function, which is supposed to display all seats that are taken and not taken, it doesn't work.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
  #include <iostream>
using namespace std;
class sign
{
public:
   sign();
   void login(int* lab[], int lab_slots[]);
   void status(int *lab[],int lab_slots[]);
   void generate(int* lab[], int lab_slots[]);
   void main2();
private:
   int lab_no;
   int ID;
   int *labs_slots;
   int* lab[4];
};

sign::sign()
{
  
  
}

void sign::generate(int* lab[], int lab_slots[])
{
   for (int i = 0;i < 4;i++)
   {
       lab[i] = new int[lab_slots[i]];//creating lab with labslots[i]
       for (int j = 0;j < lab_slots[i];j++)//go through all slots and equal them to 0
       {
           lab[i][j] = 0;
       }
   }
  
}

int main()
{
   sign enter;
   enter.main2();
  
}

void sign::main2()
{
   sign enter;
   int anwser;
   int lab_slots[] = { 5,6,4,3 };//contains number slots of each lab
   cout << "MAIN MENU" << endl;
   cout << "0.Quit" << endl;
   cout << "1.login" << endl;
   cout << "2.logoff" << endl;
   cout << "3.Search" << endl;
   cin >> anwser;
   switch (anwser)
   {
   case 0:
       cout << "GoodBye!" << endl;
       exit(1);
       break;
   case 1:
       enter.login(lab, lab_slots);
   }
}

void sign::status(int* lab[], int lab_slots[])
{
   cout << "Status";
   for (int i = 0;i < 4;i++)//going through the labs
   {
       cout << i + 1;
       for (int j = 0;j < lab_slots[i];j++)//inner loop going though the labs
       {
           if (lab[i][j] != 0)//if the seat is taken, it will display so
           {
               cout << " " << j + 1 << ": " << lab[i][j];
           }
           else
           {
               cout << " " << j + 1 << ":empty ";
           }
       }
       cout << endl;
   }

}


void sign::login(int* lab[], int lab_slots[])
{
   int slot;
   cout << "Enter in the 5 digit code to log in" << endl;
   cin >> ID;
   cout << "Enter in lab number (1-4)" << endl;
   cin >> lab_no;
   if (lab_no >= 5)
   {
       cout << "Invalid output!" << endl;
       exit(1);
   }
   int slots = lab_slots[lab_no - 1];// get the available number of slots in the Lab entered by the user from array.
   cout << "Input computer station # (1-" << slots << "): \n";
   cin >> slot;
   if (lab[lab_no - 1][slot - 1] != 0)//if this is set to true it is taken as seen with the !=0
   {
       cout << "Lab is taken" << endl;
   }
   else
   {
       lab[lab_no][slot - 1] = ID;//ID entered is now assigned to the lab and slot (or station)
   }
   status(lab, lab_slots);
}
I don't know if you're required to have your functions the way they are, but generate should be a constructor. Why? Because that way, it's harder to forget to call it before you call status, as you do in your program.

Are you allowed to use std::vector? I think it would help you here.

-Albatross
Yea I could use vectors,but I'm not sure how I should incorporate it.
Registered users can post here. Sign in or register to post.