Vectors or Matrices in C/C++

Asked

Viewed 152 times

0

follows below a problem can use vectors or matrices, I have a question on how to do item 1 of the menu, if anyone can explain me, I would appreciate it very much :)

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

MENU

1 - Show situation of all cabinets, example: Armory 0: Occupied, Armory 1: Occupied, Armory 2: Free...

2 - Show free cabinets, example: Armory 2, Armory 4, Armory 8...

3 - Use Locker: Inform the number of a free locker and mark it as occupied, if the locker is busy warn the user LOCKER BEING USED.

4 - Remove Cupboard: Inform the number of a busy cupboard and make the release of the cupboard, if the cupboard is free warn the user CUPBOARD IS NOT BEING USED.

5 - Locker Summary, Example: 3 Free Cabinets, 7 Occupied Cabinets

0 - Exit

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

  • 1

    Can you show how far you’ve come in coding? If there’s a problem or if you have a doubt in any specific concept?

  • I have a question about the concept of vectors even, if you can give a little help, I would really appreciate it

1 answer

0


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

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

1 - Show situation of all cabinets, example: Armory 0: Occupied, Armory 1: Occupied, Armory 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 this part in a loop to make it easy to show everyone without getting Ctrl+C and Ctrl+V.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.