You are on page 1of 24

PROGRAMMING FOR ENGINEERS

Introduction to Programming

GRUPO DE INVESTIGACIN A+D

INTRODUCTION TO PROGRAMMING LOGIC


Formulate and resolve problems constitute an essential activity in life. Educational models are dedicated to formulate problem to human being and to teach him how to find solutions. However, it wont be teach a technique to how resolve problems in general. It had been an awful omission and today we find college student that are great collector of problems and answers, so it can be found a lack of investigators. Some investigations perform by Oregon University, had demonstrated that neglecting the external differences, every problem have three parts: data, operations and objectives. Data are the elements that we know from the problem; operations are the procedures to drive, combine and transform the data, basically it is the capacity to interpret assumptions and to perform some calculated transformations. Objectives are the solution o results given from manipulate data by means of an operation conjunct.

GRUPO DE INVESTIGACIN A+D

INTRODUCTION TO PROGRAMMING LOGIC


Our area of problem analysis has two phases clearly defined and related: Problem Formulation Problem Resolution In the problem formulation it can be found three aspects: Problem definition Assumptions: What is the data we have and what are the restrictions. Expected results. In the same way, problem resolution is divided in: Options analysis and solution selection. Detailed specification of the solution procedure. Adoption of a tool for its implementation.

GRUPO DE INVESTIGACIN A+D

INTRODUCTION TO PROGRAMMING LOGIC


In that last aspect, where it is considered the usage of a tool for its operation, it can be notice that the computer appears as a mean and not as an end for the resolutions of problems. In other words, the computer does not resolve problems, we are the one who resolve them and through a programming language we present to the computer. We can make use of the computer speed and the accuracy of its work with great volumes of information. In computer science field, the solution of a problem can be described through the design of procedures named algorithms to then, be implemented as

PROBLEM

ALGORITHM

SOFTWARE

GRUPO DE INVESTIGACIN A+D

COMPUTER MEMORY FOR PROGRAMMING


Computer memory (RAM Memory) is where is stored the input data or the results of calculation that the computer performs when executing a program. To programmer, memory is a big field that is divided in cells and each is identified with a name and it stores a data. These cells are called the VARIABLES.

GRUPO DE INVESTIGACIN A+D

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

GRUPO DE INVESTIGACIN A+D

OPERATORS
Arithmetical: +, -, *, /, ^ Relationship: >, <, >=, <=, <> Logical: AND, OR, NOT

GRUPO DE INVESTIGACIN A+D

Analyze this expression and to identify which corresponds


var = a + b / c + d

1).

2).

3).

4).

GRUPO DE INVESTIGACIN A+D

OPERATOR HIERARCHY
Parenthesis ^, NOT *, /, residue, AND +, -, OR >, <, >=, <=, <>

GRUPO DE INVESTIGACIN A+D

Proposed: Transform this expression in a one-line instruction

GRUPO DE INVESTIGACIN A+D

METHODOLOGY FOR DEVELOPING A PROGRAM


To create a program it should be followed the next stages in the development: Analysis Stage Design Stage Programming Stage Verification and debugger Stage Maintenance

GRUPO DE INVESTIGACIN A+D

PROBLEM ANALYSIS STAGE


The first stage to resolve a computer problem requires: a clear definition of the problem that wants to be resolved, to determine what the program needs to do and to know what results o solutions are desired. In this stage is determined what the program does. It is a good start answer questions like: What is the data necessary to input the computer? What are the data or results required for the computer?

GRUPO DE INVESTIGACIN A+D

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

GRUPO DE INVESTIGACIN A+D

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:

Donde N=numero de datos

x = promedio

GRUPO DE INVESTIGACIN A+D

SOLUTION DESIGN STAGE


In this stage is determined how the program does the required task; in the design process of an effective method is based in the Divide and Win postulate, it means the resolution of a complex problem is made by dividing the problem in small easy-to-solve problems, until a solution can be programmed into the computer. This method is known like top-down design or modular design. The process to break the problem in each stage and express each step in a more detailed way is named successive refinement. Each small easy-to-solve problem is solved through a subprogram that has a unique input and output. Thus, every well-designed program has a main program that calls other subprograms. For programs designed that way, it is said that they have a modular design. The methods are described in ALGORITHMS where it must be questioned about: What calculations should be performed to achieve results. What conditions are necessary to be evaluated to obtain specific results. What iterative processes drive me to the results.
GRUPO DE INVESTIGACIN A+D

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.

GRUPO DE INVESTIGACIN A+D

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.

GRUPO DE INVESTIGACIN A+D

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.

GRUPO DE INVESTIGACIN A+D

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.

GRUPO DE INVESTIGACIN A+D

Case Study

GRUPO DE INVESTIGACIN A+D

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

GRUPO DE INVESTIGACIN A+D

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.

GRUPO DE INVESTIGACIN A+D

GRUPO DE INVESTIGACIN A+D

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:

GRUPO DE INVESTIGACIN A+D

You might also like