Professional Documents
Culture Documents
Introduction to Programming
PROBLEM
ALGORITHM
SOFTWARE
TYPES OF VARIABLES
Character: A, B, C, , Z,0,1,2, , 9 Numeric Real: Numbers with a decimal Numeric Integer: Number without decimals Logical: True or False String
OPERATORS
Arithmetical: +, -, *, /, ^ Relationship: >, <, >=, <=, <> Logical: AND, OR, NOT
1).
2).
3).
4).
OPERATOR HIERARCHY
Parenthesis ^, NOT *, /, residue, AND +, -, OR >, <, >=, <=, <>
Example
Analyze what information is required to write an algorithm that calculates the area and perimeter of a circle: Solution: Input data: radio Output data: Area, perimeter Area = pi * radius ^ 2 Perimeter = 2 * pi * radius Variables: radius, area, perimeter
Case Study
Perform the analysis phase of the following case:
La norma ASTM D 666 aplica para determinar las propiedades de Tensin de se algunos tipos de plsticos. Despus de realizar los ensayos mecnicos en la maquina universal se obtuvieron los siguientes resultados. Ensayo 6 6 6 6 6 RT (MPa) 3 3 3, 33 6 6 6 6 6, 66
RT=Resistencia a la tensin. Disee un algoritmo que genere un reporte final del ensayo donde calcule la desviacin estndar segn la frmula:
x = promedio
ALGORITHMS
The word algorithm is so antique; it takes the name of the famous Arabian mathematician and astronomer Al-Khwarizmi (9th Century), who wrote a document about the manipulation of numbers and equations. An algorithm is the group of steps, procedures or actions that permit reach a result or resolve a problem. An algorithm is expressed in a verbal or writes way and it has the following characteristics: accurate, deterministic, finite, it must have zero or more inputs, one or more outputs. To write an algorithm are used Flow Diagrams, Nassi-Schneiderman Diagrams or Pseudocode.
FLOW DIAGRAMS
Is one of the most antiques techniques of representation, where are used symbols connected by flow lines, which it indicates the sequence of execution.
Case Study
Are the coordinates of three points in the Cartesian plane. Design an algorithm to determine the distance between the points and also determine if the shape is an equilateral triangle (three sides equal), isosceles (two sides equal) or scalene (different sides). Represented by a flowchart and Rectangular or NS.
NASSI DIAGRAMS
It is a flow diagram where the connectors are omitted and the boxes are together. The successive actions are written in successive boxes and like the flow diagrams, different actions can be written in a single box.
Case Study
Pseudocode
It is a language of specification of algorithms that uses reserved words and require indentation, e.g. left tabulation; of some lines. The usage of this language makes too much easier the transition to the programming language. The advantage of the pseudocode is that the programmer can focus in the logic and the control structures. The pseudocode will always initiate with the word START and fill finish with the word END. Example: This example already mentioned transforms degrees Celsius in Kelvin, would be written in pseudocode as follows: Home Read (Celsius) Kelvin = Celsius +273.15 Write (kelvin) End
Case Study
Given two vectors X = (2, -3,4,1) and Y = (-1,2,4,2) find the angle between vectors. Build the algorithm pseudocode.
Case Study
Apply any of the previous representations. A particle of mass (m) moves through a fluid subject to a resistance R which is a function of the speed of m. The relationship between the resistance (R), velocity (v) and time (ti) is given by the equation: