Presentation is loading. Please wait.

Presentation is loading. Please wait.

17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices.

Similar presentations


Presentation on theme: "17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices."— Presentation transcript:

1 17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices

2 17 March, 2000 Introduction Use computers as a problem solving tool A computer program is a sequence of instructions that must be followed to solve a particular problem. Software engineering is the study and application of programming and problem solving techniques and methodologies

3 17 March, 2000 Simple Program Design Process Start Specify & analyze the problem you are trying to solve Test the resulting Fortran program Convert algorithm into Fortran statements Design the algorithm Define required inputs and outputs Finished!

4 17 March, 2000 Problem Statement A nuclear physicist is conducting research with the radioactive element polonium. The half-life of polonium is 140 days, which means that because radioactive decay, the amount of polonium that remains after 140 days is one-half of the original amount. How much polonium will remain after 180 days if 10 milligrams are present initially. What information is given? … which ones are important ? What information must be produced?

5 17 March, 2000 Data analysis and organization Specific InputOutput Initial amount: 10 mgAmount remaining Half-life: 140 days Time period: 180 days Generalize InputOutput Initial amountAmount remaining Half-life Time period InitialAmount HalfLife Time AmountRemaining

6 17 March, 2000 Algorithm Design & Refinement Get values for InitialAmount, HalfLife, and Time Compute the value of AmountRemaining for a given Time Display AmountRemaining AmountRemaining = InitialAmount*(0.5)**(Time/HalfLife) Assignment = multiplication * division / raise to power ** Logics errors

7 17 March, 2000 Coding General form of Fortran program: Heading specification execution subprogram END PROGRAM Documentation –Opening documentation –http://www.cs.wpi.edu/Help/documentation-standard.html

8 17 March, 2000 Coding PROGRAM Radioactive_Decay !-------------------------------------------------------- ! This program calculates the amount of a radioactive ! substance that remains after a specified time, given ! an initial amount and its half-life. Variables used are: ! InitalAmount : initial amount of substance (mg) ! HalfLife : half-life of substance (days) ! Time : time at which the amount remaining ! is calculated (days) ! AmountRemaining : amount of substance remaining (mg) ! ! Input: InitialAmount, HalfLife, Time ! Output: AmountRemaining !--------------------------------------------------------- ! Use for Comments Program heading Opening documentation Other useful information: author, date, version number, etc.

9 17 March, 2000 IMPLICIT NONE REAL :: InitialAmount, HalfLife, Time, AmountRemaining ! Get values for InitialAmount, HalfLife, and Time. PRINT *, "Enter initial amount (mg) of substance, & &its half-life (days)" PRINT *, "and time (days) at which to find amount remaining:" READ *, InitialAmount, HalfLife, Time ! Compute the amount remaining at the specified time. AmountRemaining = InitialAmount * 0.5 ** (Time / HalfLife) ! Display AmountRemaining. PRINT *, "Amount remaining =", AmountRemaining, "mg" END PROGRAM Radioactive_Decay Prompt for, and obtain input PRINT, READ Display the result as an output PRINT END PROGRAM statement Specification Continuation Execution

10 17 March, 2000 Preparing a Program for Execution You enter the program and save it as a source file The compiler attempts to translate the program You correct syntax error The linker links the new object file with other object files The loader places the load file into memory Executable program in memory Load File Source file on disk New Object File Other Object File Revised Source file List of errors Oops! Good job! Syntax or compile-time errors Run-time errors

11 17 March, 2000 Testing Initial test -- the ones that you can calculate easily by hand. E.g.: – InitialAmount = 2, HalfLife=140, Time=140. AmountRemaining should = 1.0000000 mg –InitialAmount = 4, HalfLife=140, Time=280. AmountRemaining should = 1.0000000 mg. –Then InitialAmount = 10, HalfLife=140, Time=180. AmountRemaining= 4.1016769 mg “Once we are confident that the program is correct” –what? when? how? how much?

12 17 March, 2000 More Realistic Process Start Specify & analyze the problem you are trying to solve Test the resulting Fortran program Convert algorithm into Fortran statements Design the algorithm Define required inputs and outputs Decomposition Stepwise refinement Release Maintain the resulting Fortran program End of life

13 17 March, 2000 A typical testing process for a large program Start Unit testing of individual subtasks Beta release Alpha release Successive builds (adding subtasks to the program) Release -- a little breather ! Subtasks validated separately As many times as necessary Subtasks combined into programs Major bugs fixed Minor bugs fixed As many times as necessary

14 17 March, 2000 Program Design Tips This process is often iterative because you may not initially know what all you want to print out, or input. –Design a little –Code a little –Test a little –Take a break –Repeat until finished

15 17 March, 2000 Summary Program solving process, SE process Fortran statements: PROGRAM program_name IMPLICIT NONE REAL:: list_of_real_variables INTEGER:: list_of_integer_variables Comments ! Continuation & Operations + - * / ** Assignment = Input READ*, input_list_of_variables Output PRINT *, output_list_of variables END PROGRAM program_name


Download ppt "17 March, 2000 CS1001 Lecture 2 Programming and problem solving Software engineering practices."

Similar presentations


Ads by Google