Algorithm with flow chart/diagram

Asked

Viewed 155 times

2

Guys, I’m taking a course in logic and the following question has fallen:

Draw up a block diagram to verify 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: the quantity in stock is less than or equal to the minimum quantity: QTDCOMPRA = (QTDMAX - QTDEST)

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

I did so, and I would like to know if I am more or less on the right track or completely off course and why?

diagrama

  • 1

    Don’t confuse "logic" with "programming logic". Are different things.

  • This is supposed to be a flowchart?

  • I didn’t understand the comparisons with X if he’s just the product code.

2 answers

2


In addition to the problems reported in the first answer, this diagram shows how the flow of comparisons would be, where NÃO means that one of the comparisons has not been met, and therefore valid, and SIM which have been met, are not valid.

In the case (k > z) ou (k < y) ou (k > w), that is, respectively:

  • (k > z): the purchase quantity is greater than the maximum quantity;

  • (k < y): the buying-in quantity is less than the minimum quantity, and

  • (k > w): the purchase quantity is greater than the quantity in stock.

The Se não x (EOF) ou x (EOF) 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]------------
  • Thank you very much!

  • Now I did so: [![insert image description here][1]][1] [1]: https://i.stack.Imgur.com/0m3H9.jpg Did it make a difference? What do you think?

  • @Hernanemendes Just use the "answer" field to put an answer that answers the question. If you want a ask a new question, use the "ask" button. Abs!

1

Your flowchart is quite confused and wrong. The only diamond I see where a decision should be made is at "Se EOF". However, below it there are no two lines "Sim" and "Não" leaving. But in the boxes below, which as rectangles should represent instructions/assignments, there are a lot of "Sim"s and "Não"s coming out to various sides.

Note for example the box of "X > Y". There are two written edges "Não" going to her, and since there are no arrows, it is not possible to know which one I should choose.

Since "CODPRO" is "X" and "QTDMAX" is "Z", the little box "X <= Z" that is to say "CODPRO <= QTDMAX". Now, it is pointless to compare 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 meaningless operation. The only one that is on track is the "K = Z - W".

Also, your algorithm doesn’t write to the file, it just uses the "Se EOF" like I had to read from it.

Renaming variables as you did is a bad programming practice and only serves to cause confusion, even it seems that you have confused yourself. If I hadn’t made up that "CODPRO" is "X" and "QTDMAX" is "Z", you wouldn’t have written "X <= Z".

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

I’m sorry to be blunt, but what you did is completely wrong. You can throw it all away and start over with a blank sheet.

  • 1

    Ahhh yes! All right, I don’t mind the sincerity, actually I would like to thank you. Thank you very much! I’ll try again and anything play here again!

  • Now I did so: [![insert image description here][1]][1] [1]: https://i.stack.Imgur.com/0m3H9.jpg Did it make a difference? What do you think?

Browser other questions tagged

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