2d array and stack

Hello. I just need some advice/tips/helps .
I wanna create an 2d array (in servedCustomers fuction) that will store the value of stack(customerServed)and print the 2d array when i choose the option "4".

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
114
115
116
117
118
119
120
121
122
  #include<iostream>
#include<stack>

// Standard
using namespace std;

// Structure Declaration
struct customerInfo
{
   // Queue Variables
   int customers[10], n = 10, front = - 1, rear = - 1;
   string done[2] = {"Pending", "Done"};
};

// Stacks
stack<int> customerServed;

// Calling the Structure as Global Variable
customerInfo customers;

// Add Customers
void addCustomers(){
   
   // Pointer Declaration in addCustomers
   int num;
   int *ptrnum = &num;

   if (customers.rear == customers.n - 1)
   cout << "All sits are occupied." << endl;
   else {
      if (customers.front == - 1)
      customers.front = 0;
      cout << "Enter Customer ID: ";
      cin >> num;
      cout << endl; 
      customers.rear++;
      customers.customers[customers.rear] = num;
   }
}

// Serve Customers
void serveCustomers(){

   // Pointer Declaration in serveCustomers
   int served = customers.customers[customers.front];
   int *ptrserved = &served;

   if (customers.front == -1 || customers.front > customers.rear)
   cout << "Nothing to serve here.\n" << endl;
   else {
      cout << "Customer #" << served << " has been served." << endl;
      cout << endl;
      customers.front++;
      customerServed.push(served);
   }
}

// View Pending
void viewPending(){
   if (customers.front == - 1)
   cout << "No Pending Customers.\n" << endl;
   else {
      cout << "Customer ID: #";
      for (int i = customers.front; i <= customers.rear; i++)
      cout << customers.customers[i] << ".\n";
      cout << "\n\n";
   }
}

// View Served
void servedCustomers(){

   

   // Stacks
   int customerServedSize = customerServed.size();
   cout << "The total customers we served is: " << customerServed.size() << "\n\n";
}


// Main
int main(){

   // Choice w/ Pointer Declaration
   int choice;
   int *ptrchoice = &choice;

   do{
       // Menu
      cout << "\t\t*******************Customer Serving System*******************\n" << endl;
      cout << "\t\t\t1.) Add Customer" << endl;
      cout << "\t\t\t2.) Serve Customer" << endl;
      cout << "\t\t\t3.) View Pending Customer(s)" << endl;
      cout << "\t\t\t4.) View Served Customer(s)" << endl;
      cout << "\t\t\t5.) Exit\n" << endl;

      // Choice
      cout << "\t\t\tInput Option(1/2/3/4): ";
      cin >> choice;
      cout << "\t\t*************************************************************\n" << endl;
      switch(choice){
         case 1:
            addCustomers();
            break;
         case 2:
            serveCustomers();
            break;
         case 3:
            viewPending();
            break;
         case 4:
            servedCustomers();
            break;
         case 5: 
            cout << "Thank you for using our Serving System!" << endl;
            break;
         default: 
            cout << "\t\t\tWrong Input choose another.\n" << endl;
      }
         
   }while(choice!=5);
}
Last edited on
Hey,
can you clarify?

What, exactly, does not work?
I looked for a bit and I don't see a 2-d array anywhere.

"print it" -- the stack? the 2-d array? Something else?

hello,
well my problem is i wanna create a 2d array that will hold the value of stack .but i dont know how to transfer the value of stack to 2d array .

yes i wanna print the 2d array when i choose the option number 4.
ok. what do the columns and rows represent in your 2-d construct?

A stack is a 1D container, so what is the advantage of transferring your data to a 2D container?

Printing out 1D data with simulated 2D rows and columns is certainly doable.
Topic archived. No new replies allowed.