Define the problem (Analysis)

Download Report

Transcript Define the problem (Analysis)

Software Development
1. Define the problem (Analysis)
2. Plan the solution
3. Code
4. Test and debug
5. Maintain and Document
sw development
1
Code
• Write program in a specified language
• editor - key in- create source program
– .cpp (if c++ is the language)
• compiling - create object program
– Syntax error
– .obj
• link - create executable
– .exe
• Run
– Logic errors
• Lab #1
sw development
2
Problem Analysis
•
1.
2.
3.
4.
5.
Problems: Take one of the following tasks and write a set
of instructions(a solution) so complete that another
person could perform the task without asking questions
Make a cup of cocoa
Sharpen a pencil
Decide which number is the largest from a group of
three numbers
Start a car(include directions regarding what to do if the
car does not start
Buy a soda from the soda machine
sw development
3
Problem Solving
• Identify, understand the problem
• Obtain additional information
• Read and reread to obtain additional
information
• Alternatives
• List instructions that enable you to solve the
problem by the selected method
sw development
4
Problem Solving
• Some problems require a series of actions or an
algorithmic colution
– Exa. solving a complicated calculus program
– Alphabetizing 10,000 names
• Other problems require reasoning built on
knowledge and experience – heuristic solution
• Computers are better at algorithmic solutions
• Problems with problem solving
– Define problem incorrectly
– Don't identify a sufficient list of alternatives
sw development
5
Analysis of the Problem
1. Determine what is given - input
=>nouns, adjectives
2. Determine what is required - output
=>nouns, adjectives
3. Determine the transformations
needed(processing)
-actions needed to produce the required output
=>verbs, adverbs
sw development
6
Example 1:
Read three numbers, add them together and print the total.
Read three numbers, add them together and print the total.
Input
Processing
Output
Read three numbers
total
number_1
Add numbers together
number_2
Print total number
number_3
sw development
7
Example 2:
Write a program to prompt the operator for the maximum and
minimum temperature readings on a particular day, accept those
readings as integers, and calculate and display on the screen the
average temperature.
Input
max_temp
Processing
Output
Prompt for temps
avg_temp
Calculate average
min_temp
Display average
sw development
8
Structured Programming
• Control structures
– sequence
– selection or IF-THEN-ELSE
– repetition or looping
– subprograms
• Top Down Design
• Modularity
sw development
9
Design/Plan the solution
• Algorithm – a step by step procedure for solving
a problem
• All programs are implementations of algorithms
– subtasks - hierarchy chart
– logic
• flowcharts
• pseudocode
– test solution for correctness - trace
sw development
10
Algorithm
• Algorithm – set of steps that defines how a
task is performed
• Program – set of instructions written in
appropriate language
– Correctness
– efficiency
sw development
11
Pseudocode
• structured concise English statements used
to state operations
• language independent,no standard
• use words and phrases that are in line with
basic computer operations
sw development
12
Pseudocode
1. Write statements in simple English
2. Write each instruction on a separate line.
3. Use keywords and indentation for control
structures.
4. Write instructions from top to bottom,
with only one entry and one exit.
sw development
13
Pseudocode
1.
Input - receiving information
• keywords - read, get
• Read - receive information from a record on a file
• Get - receive information from the keyboard.
• Read student_name
• Get system_date
• Read number_1,number_2
• Get tax_code
• use one verb followed by one or more nouns
sw development
14
Pseudocode
2. Output
– putting information out
• put, output,display - screen
• print - printer
• write - file
–
–
–
–
–
Print smaller.
Print 'Program Completed'
Write customer_record to file
Output total_tax
Display 'End of Data'
sw development
15
Output continued
• Labels
– Print 'label' or
Print "label"
• statement inside quotes is printed as it appears
– Print 'x'
• Yields
// if x = 5
x
– Print x
• yields
5
– Print 'X = ' and x
• yields:
X=5
sw development
16
Pseudocode
3. Arithmetic
• use name of the operation or algebraic symbol
• add,subtract,multiply, divide, exponentiation
• + - * / **
• x = algebraic expression
–
–
–
–
count = count + 1
net pay = hourly_pay_rate * hours_worked
sales_tax = cost_price * 0.10
sales_tax = price * tax_rate
sw development
17
Pseudocode
4. Assignment - place information into a storage
location
• Initialize, Set - give variable initial value
• Save,Store - save info for later
• =
//preferred
y = 3 note: does not mean equality
– could involve calculation:
– area = length * width
sw development
18
Assignment
• Examples
–
–
–
–
–
–
counter = 0
Initialize counter to zero
Set count to 1
Initialize tot_accums to 0
Set upper_limit to 100
total_price = cost_price + sales_tax
sw development
19