Vectors or Arrays in C / C ++ [closed]

0

I have a question about how to do item 1 in the menu, if anyone can explain me, I would appreciate it a lot :)

Faculty X thought of adopting lockers for students to leave their materials in the same way as American universities. With that, she thought of Computer Engineering students to assemble the automation of this system. To test the system you will have to control 10 cabinets. Mount a menu of options that will be displayed on a control display as shown below and implement the routines so that each menu option works correctly:

MENU

1 - Show the situation of all the cabinets, for example: Wardrobe 0: Busy, Wardrobe 1: Busy, Wardrobe 2: Free ...

2 - Show the free cabinets, eg: Cabinet 2, Cabinet 4, Cabinet 8 ...

3 - Use Cabinet: Inform the number of a free cabinet and mark it as occupied, if the cabinet is occupied, notify the user CABINET BEING USED.

4 - Remove Cabinet: Inform the number of a occupied cabinet and release the cabinet, if the cabinet is free to notify the user CABINET IS NOT USED.

5 - Cabinet Summary, example: 3 Free Lockers, 7 Lockers

0 - Exit

Remarks: The program should start with all free cabinets and the menu should be in infinite loop, ie after choosing any option should always return to the menu. The menu should handle invalid options.

    
asked by anonymous 10.06.2017 / 02:16

1 answer

0

You could create a vector of type bool, which will store whether the cabinet is empty or not:

bool armarioOcupado[10] = {false, false, ... //Inicializar todos em falso
  

1 - Show the situation of all the cabinets, for example: Wardrobe 0: Busy, Wardrobe 1: Busy, Wardrobe 2: Free ...

#include <iostream>...


int numArmario = 4;//Numero do armario escolhido
if(armarioOcupado[numArmario] == true)
{
    std::cout << "Armario " << numArmario << ": Ocupado";
    //Saída: Armario 4: Ocupado
}
else
{
    std::cout << "Armario " << numArmario << ": Livre";
}

Then put that part in a loop to make it easier to show everyone without getting Ctrl + C and Ctrl + V.

    
11.06.2017 / 00:35