Algorithm with flowchart / diagram

2

Well, I'm taking a course in logic and the following question fell:

  

Develop a block diagram to check which products need to be purchased and the quantity to be purchased: Having the following information:

     
  • Product code (CODPRO), Minimum quantity (QTDMIN), Maximum quantity (QTDMAX) and quantity in stock (QTDEST) of each product.

  •   
  • A product should only be purchased when: quantity in stock is less than or equal to the minimum quantity: QTDCOMPRA = (QTDMAX - QTDEST)

      
  • Save to another file: Product ID and Quantity to Buy

  •   

I did so, and would like to know if I'm more or less on the right track or completely out of the way and why?

    
asked by anonymous 09.12.2017 / 00:31

2 answers

2

In addition to the problems reported in the first response, this diagram shows how the flow of comparisons would be, where% with% means that one of the comparisons was not met, therefore valid, and NÃO that were met, are not valid .

In the case SIM , that is, respectively:

  • (k > z) ou (k < y) ou (k > w) : the purchase quantity is greater than the maximum quantity;

  • (k > z) : The purchase quantity is less than the minimum quantity, and

  • (k < y) : The purchase quantity is greater than the quantity in the inventory.

(k > w) checks whether the product code exists or does not exist.

codpro = x;
qtdmin = y;
qtdmax = z;
qtdest = w;
qtdcompra = k;

         Se não x (EOF)    ou    x (EOF)
              |                     |
---------------------------------   |
(k > z)  ou  (k < y)  ou  (k > w)   |
---------------------------------   |
          |    |                    |
         NÃO  SIM--------           |
          |             |           |
      [COMPRAR]   [NÃO COMPRAR]------
          |             |
        [FIM]------------
    
09.12.2017 / 02:53
1

Your flowchart is pretty confusing and wrong. The only diamond I see, where a decision should be made is in the " Se EOF " . However, beneath it there are not two lines " Sim " and " Não " exiting. But in the boxes below, which as rectangles should represent statements / assignments, there are a lot of " Sim " if " Não " / p>

Note, for example, the " X > Y " box. There are two edges written " Não " going to it, and since there are no little ones, you can not know which one I should choose.

Since " CODPRO " is " X " and " QTDMAX " is " Z ", the box" X <= Z "means" CODPRO <= QTDMAX ". There is no point in comparing the code of a product with the quantity of that product. The other boxes " X > Y ", " X <= Y " and " X == Z " also do the same kind of nonsense operation . The only one that is on the right track is " K = Z - W ".

In addition, your algorithm does not write to the file, it only uses " Se EOF " as if it had to read from it.

Getting renaming variables like you did is a bad programming practice and only serves to cause confusion, even seems to confuse yourself. If you have not invented this " CODPRO " is " X " and " QTDMAX " is " Z ", you would not have written" X <= Z ".

And also, what is that " Não comprar " ? A box written " Comprar " would even make sense as an action to be taken, but a step in the algorithm specifying what it is not to do has no meaning at all. Also, your algorithm should not buy or stop buying anything, it should be write an information in the file.

Excuse me for honesty, but what you have done is completely wrong. You can throw it all away and start over with a blank sheet.

    
09.12.2017 / 01:09