CS1001 Lecture 2 Software engineering practices
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
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?
Data analysis and organization Specific Input Output Half-life: 140 days Time period: 180 days Generalize Input Output Initial amount Amount remaining Half-life Time period
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)
Coding General form of Fortran program: - Heading
- specification
- execution
- subprogram
- END PROGRAM
Documentation - Opening documentation
- http://www.cs.wpi.edu/Help/documentation-standard.html
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 !---------------------------------------------------------
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?
More Realistic Process
A typical testing process for a large program
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
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
Dostları ilə paylaş: |