0% found this document useful (0 votes)
6 views

T6.2 VBA Algorithms EN

VBA algoritmos

Uploaded by

petros barros
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

T6.2 VBA Algorithms EN

VBA algoritmos

Uploaded by

petros barros
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Algorithms and Programming

Algorithm & Flowchart


Problem Solving

 Analyze the problem


 Understand the problem and its domain
 Describe the requirements: subdivide, detail

 Structure a step-by-step solution


 Verify that there is no ambiguity
 Flowchart

 Implement the solution


 In a programming language (VBA)
Problem Solving
Algorithms

 Algorithm
 Methodical and unambiguous finite sequence of steps
which describes the solution of a problem, efficiently.
 Program: accurate description of an algorithm according to
a specific terminology (programming language)
 Essential in the world of programming!
 But, also applied in everyday situations
 Cake recipe
 Manual of a kitchen appliance
 Assembly instructions for furniture (IKEA)
 Etc…
Algorithms
 Recipe
 Ingredients: (data)
1 bottle of red wine
1 bottle of carbonated water
1 glass of Port wine
2 spoons of sugar
1 big orange
1 apple
1 pear
1 red peach
1 stalk of mint

 Preparation: (procedure)
 In a large jug drop the wine, the water, the Port wine and the sugar.
 Mix everything very well.
 Add the fruits in small pieces.
 Aromatize with mint.
 Cover and leave the infusion in the refrigerator for two hours.
 Serve in tall glasses, placing some ice cubes.
Algorithms
 Procedure to replace a flat tire:
1. ?
2. ?
3. ?
4. ?
5. ?
6. ?
7. ?
8. ?
9. ?
10. ?
11. ?
12. ?
Algorithms
Steps to take in case of a tire hole:
Step 1 - Place your car in a flat area and pull or charge (in the case of cars with electric handbrake) on your handbrake. Shift the
reverse gear and make sure it is out of the way to avoid disturbing traffic and for your safety. Then switch off the engine and turn on the
hazard lights ("four blinkers"). Then, wear the reflector vest and properly mark the location with the triangle.

Step 2 - Gather the necessary tools to change the wheel, look for the cross wrench, the jack, and of course the spare wheel. If you can
not find them, consult your car owner's manual to find out where they are.

Step 3 - Slightly unscrew the tire screw-nuts before putting the jack under the vehicle. If your car is equipped with safety screw-nut, an
adapter supplied by the manufacturer is required to remove one of the special anti-theft screw-nut. Do not forget that it will be easier to
use the weight of your feet instead of doing it with the arms to relieve the screw-nuts, because sometimes they are very tight.

Step 4 - Then place the jack in the area indicated by the manufacturer for this device, otherwise you can see where it is by consulting
the instruction manual of the car again. They usually have a small down arrow in the area of the vehicle spar. Then raise it until the
wheel stops touching the ground. Then remove all the screw-nuts and place them in a location where you can not lose any of them.

Step 5 - Remove the flat tire with both hands and place the spare tire. For complete safety, the wheel (with the hole) you just removed
from the car place it under the car. This allows you to be more secure if the car jack is damaged for any reason.

Step 6 - With the spare tire already tucked into the axle of the car, place the first screw-nut, and then place the second diagonally of this
i.e. a star grip pattern. Tighten them slightly and gradually lower the car. Then screw tightly using the weight of the feet for a greater
tightening force.

Step 7 - Store the material and safety equipment. Do not forget to remedy the hole as quickly as possible, as you may have the same
mishap and have no way to make the switch.
Algorithms
Algorithms
 Description of algorithms
 Natural Language
 The algorithms are expressed in the language that the
programmer uses in his daily life
 Pseudo-Code
 Merges natural language and formal language
 Flowchart
 Uses standard geometric shapes that typify several
operations
 Formal Language
 The algorithms are translated into a programming language
Algorithms - Flowchart
Pseudo-Code Flowchart
BEGIN / END Begin / End

READ Input data

WRITE Output data

IF…THEN…
DO WHILE… Decision

DO…UNTIL…
FOR…NEXT flow execution

𝑥= 𝑎2 + 𝑏 2 Process
Algorithms - Concepts
 Data Structure
 Defines the organization of the data and its access

 Represented by:
 Simple variables (unitary value)
 Mono and two-dimensional indexed arrays
 Lists
 Queues
 Stacks
 Trees
 Graphs
 Etc.
Algorithms
 APROG: interaction Human↔Machine

WRITE

R
Begin E Data processing End
A
D

Data input Data output


(Excel) (Excel)
Algorithms - examples
 Describe an algorithm to calculate the average
of two numbers given by the user
 Read two numeric values (input)
 Calculate the arithmetic mean between them (processing)
 Write the result (output)

 Flowchart:

Begin Num1 Num2

Average Calculate
End
Average
Algorithms - examples
 Pseudo-Code: structured english
Algorithm Average
DS: num1, num2, avg: decimal numbers ‘Data Structure
Begin
write(“Insert two values”) ‘optional
read(num1, num2) ‘input data
avg ← (num1 + num2) / 2 ‘processing
write(“Average = ”, avg) ‘output results
End

 Formal Language: VBA


Algorithms - examples
 Algorithm to determine the Quotient and Remainder
of the division between two integer values
 Read dividend and divisor (input)
 Calculate quotient and remainder (processing)
 Write results (output)
Begin

dividend
 Flowchart: divisor

quotient = Divide(dividend; divisor)


remainder = Rest(dividend; divisor)

quotient
remainder

End
Algorithms - examples
 Algorithm to determine the
Begin
Quotient and Remainder of the
division between two integer values dividend
 Not allowing division by zero! divisor

Y N
divisor ≠ 0 ?
 Flowchart:

quotient = dividend \ divisor


remainder = dividend MOD divisor
“#DIV/0!”
quotient
remainder

End
?
Did you understand

Much?

Little??
NOTHING!??? 

You might also like