Instituto Superior Técnico, Dep. de Engenharia Mecânica - ACCAII Objectivos e tarefas Aplicar os passos do processo de desenvolvimento para a construção de um algoritmo 1
Exercícios Resolvidos 1 - EXERCÍCIO 3.3 (LIVRO 1 - Ver referências no slide 20) Write a program to convert a Fahrenheit temperature to Celsius. Test it on the following data. 1. Contexto do Problema Desenvolver um programa para converter temperaturas de graus Fahrenheit para graus Celsius. 2
2.2 Especificações e Requisitos 2.3 Métodos de Processamento 2.1 Entradas 2.1 Saídas Conversão Temperaturas 2.1 Esquema de processamento Entradas: Temperatura em graus Fahrenheit (T_Fahrenheit) Saídas: Temperatura em graus Celsius (T_Celsius) 3
2.2 Especificações funcionais e Requisitos (EF) É dada uma temperatura em graus Fahrenheit (EF) O programa calcula e devolve a temperatura correspondente em graus Celsius (REQ) A precisão da apresentação dos resultados e até à segunda casa decimal. 2.3 Fluxo de dados Utilizador Fornece T_Fahrenheit Programa Apresenta mensagem a pedir temperatura em graus Farenheit para conversão Apresenta T_Celsius 4
2.3 Métodos de Processamento Conversão de temperaturas: T_Celsius = (T_Fahrenheit 32) * 5/9 (1) 3.1 Abordagem Top-Down 5
3.2 Lista de tarefas Fazer conversão de temperaturas Apresentar Temperatura Celsius Programa pede Temperatura Fahrenheit Utilizador escreve Temperatura Fahrenheit 3.3 Algoritmo i. Programa pede T_Fahrenheit ii. Utilizador escreve T_Fahrenheit iii. Converter temperatura para T_Celsius utilizando a fórmula (1) iv. Apresentar T_Celsius 6
4 Testes T_Fahrenheit Esperado T_Celsius Programa 68 69.8 20 21 20 21 MODELO DO PROCESSO DE DESENVOLVIMENTO 1. Contexto do problema Converter temperaturas de graus Fahrenheit para graus Celsius. 3.1 Abordagem top-down 3.2 Lista de tarefas 2.1 Esquema de processamento Entradas: Temperatura em graus Fahrenheit (T_Fahrenheit) Saídas: Temperatura em graus Celsius (T_Celsius) 2.2 Especificações funcionais e requisitos É dada uma temperatura em graus Fahrenheit O programa calcula e devolve a temperatura correspondente em graus Celsius Precisão do resultado até à segunda casa decimal. 2.3 Fluxo de dados Métodos de processamento Utilizador Programa Pede Temperatura T_Farenheit Fórmula da conversão de temperaturas: T_Celsius = (T_Fahrenheit 32) * 5/9 (1) Tarefas 3.3 Algoritmo 4. Testes Algoritmo i. Programa apresenta mensagem a pedir T_Fahrenheit ii. Utilizador fornece T_Fahrenheit iii. Converter temperatura para T_Celsius utilizando a fórmula (1) iv. Apresentar T_Celsius Testes Introduz T_Fahrenheit Apresenta T_Celsius 7
Exercícios Propostos 2 - EXERCÍCIO 3.4 (LIVRO 1 - Ver referências no slide 20) Write a script which inputs any two numbers (which may be equal) and displays the larger one with a suitable message. Exercícios Propostos 3 - EXERCÍCIO 3.5 (LIVRO 1 - Ver referências no slide 20) Write a script for the general solution of the quadratic equation ax 2 + bx + c = 0. Your script should be able to handle all possible values of the data a, b, and c. Try it out on the following values of a, b and c: (a) (b) (c) 1, 1, 1 (complex roots); 2, 4, 2 (equal roots of 1.0); 2, 2, 12 (roots of 2.0 and 3.0). 8
Exercícios Propostos 4 - EXERCÍCIO 3.6 (LIVRO 1 - Ver referências no slide 20) Develop a program that computes the solution of two simultaneous linear equations. Begin by deriving an algebraic formula for the solution of: ax + by = c dx + ey = f The program should input the coefficients a, b, c, d, e and f. Test: x + y = 3 2x y = 3 Solution: x=2, y=1 Exercícios Propostos 5 - EXERCÍCIO 1 DO CAPÍTULO 2 (LIVRO 2 - Ver referências no slide 20) Write a simple script that will calculate the volume of a hollow sphere which is, where is the inner radius and is the outer radius. Assign a value to a variable for the inner radius, and also assign a value to another variable for the outer radius. Then, using these variables, assign the volume to a third variable. Include comments in the script. 9
Exercícios Propostos 6 - EXERCÍCIO 2 DO CAPÍTULO 2 (LIVRO 2 - Ver referências no slide 20) The atomic weight is the weight of an atom of a chemical element. For example, the atomic weight of oxygen is 15.9994 and the atomic weight of hydrogen is 1.0079. Write a script that will calculate the molecular weight of hydrogen peroxide, which consists of two atoms of hydrogen and two atoms of oxygen. Include comments in the script. view the comment in your script. Use help to Referências [Livro 1] Capítulo 3 de Essential MATLAB for Engineers and Scientists, Brian Hahn e Dan Valentine (2007) Elsevier. [Livro 2] Capítulo 2 de Matlab: A Practical Introduction to Programming and Problem Solving, Stormy Attaway (2009) Elsevier. 10
MODELO DO PROCESSO DE DESENVOLVIMENTO 1. Contexto do problema Número de aluno 3.1 Abordagem top-down 3.2 Lista de tarefas 2.1 Esquema de processamento Entradas: Saídas: 2.2 Especificações funcionais e requisitos 3.3 Algoritmo 4. Testes 2.3 Fluxo de dados Métodos de processamento Utilizador Programa 11