Sunteți pe pagina 1din 18

5/8/2012

Week:
Lecture Date:

Course:
Instructor:
Topic:

11
18/04/2012

Computing Fundamental
Dr. Arif Mushtaq
Software Development Methods

Software Development Method




Programming is problem solving activity.

Problem solving methods are different in


different areas, e.g.:


Business students solve problems with systems


approach.

Engineering and science students use engineering &


science method

Programmers use software development method

5/8/2012

Computer Programming


Computer programming is not just programming


language syntax and using a development
environment.
At its core, computer programming is solving
problems.
We will follow structured methodology to
construct solutions for a given problem.

Software Development Method


1.

Specify the problem requirements

2.

Analyze the problem

3.

Design the algorithm to solve the problem

4.

Implement the algorithm

5.

Test and verify the completed program

6.

Maintain and update the program

5/8/2012

Software Development Method


1. Specify the requirements
2. Analyze the problem


Decomposition

3. Design the algorithm




Flowcharting

Pseudocode

Problem Solving Methodology


2. Analyze the problem


Decomposition it involves five steps

1.

Indentify all of the nouns in the requirements (inputs and


outputs)

2.

Eliminate redundant or irrelevant information

3.

Identify all of the verbs in the requirements (processing)

4.

Link inputs, processes and outputs

5.

Use external knowledge to complete your solution

5/8/2012

Example


Problem statement


Given the 3 dimensions of a box (length, width,


and height), calculate the volume.

Decomposition step (on white board)

Example
3. Design the algorithm
 a. Flowcharting - Flowcharting is a graphical way of
depicting a problem in terms of its inputs, outputs, and
processes.

5/8/2012

Example


Since
our
processing is
complete, we
should display
the output for
the user.

Example
3. Design the algorithm
 b. Pseudocode


Pseudocode involves writing down all of the major steps used in


the program as depicted in flowchart.
Basic elements of Pseudocode are;

It is important to note that each time you compute a value that you will need later,
it is necessary to store it even if you will need it right away.

5/8/2012

Example Flowchart and Pseudocode

Exercise


Work through the three steps of decomposition,


flowcharting, and pseudocode for the following
example.

You have a store that sells apples and oranges. Apples are
Rs. 10 each and oranges are Rs. 5 each. Your program
should get from the user the number of apples and
oranges and output the total amount of money.

5/8/2012

Solving Problems with Solutions Requiring


Selection


In previous exercise, we have solved problems with solutions which


were strictly linear in nature, or sequential.
From the start to the end of our pseudocode (or flowchart), each line (or
figure in the flowchart) is executed once, in order.
What happens if a problem requires a solution that has alternate paths
through the pseudocode depending on the input?
Consider the following problem:
Write a program that will accept as input from the user, an answer to the
following
question: Is it raining? If it is raining, tell the user to get an umbrella.
Currently, we have not covered anything in problem solving that can
help us handle conditions like If it is raining.
There is a concept known as logical decision-making

Decomposition - When to use logical


decision-making


Whenever you would need to make a real-world decision


(such as whether or not to tell the user to bring an
umbrella), you will need to implement a logical decision
making structure in your solution to the problem





Conditions may be simple;


Condition: If it is raining
Action: Tell the user to get an umbrella

5/8/2012

Decomposition logical decision making




Sometimes, conditions are difficult; For example,


Based on the temperature, either tell the user to bring a heavy jacket
(colder than 10 degrees), light jacket (between 10 and 25 degrees), or
no jacket at all.
Condition: If the temperature is less than 10 degrees
Action: Tell user to bring a heavy jacket
Condition: If the temperature is between 10 and 25 degrees
Action: Tell user to bring a light jacket
Condition: If the temperature is greater than 25 degrees
Action: Tell user not to bring any jacket

Decomposition - logical decision making




It may be helpful to make a quick sketch of all of the


decisions you will need in your program before you go
any further.
For example;

5/8/2012

Flowcharting-logical decision making




After we have made quick sketches of all of the


decisions in our program, we can immediately move on
to flowcharting.
Drawing a flowchart for a program containing logical
decisions is quite helpful, as it helps the programmer see
the big picture how all of the decisions interact and
affect each other.
For decision-making, we use the diamond notation.

Flowcharting-logical decision making


Full
Flowchart
of raining
example;

5/8/2012

Pseudocode logical decision making




The pseudocode for decision making brings us much


closer to the actual implementation of this construct in
our programming.

Most decisions will begin with the operative word if.

The general structure of a decision should make


sense in your mind; if it is raining, get an umbrella.

The pseudocode for our example is below, matched with


our flowchart for clarity

Pseudocode logical decision making

10

5/8/2012

Pseudocode logical decision making




Modified example:
If it is raining, tell the user to get an umbrella. Otherwise,
say it is sunny.
The extension of this concept in our flowchart is simply do
something with the no branch.
In pseudocode, we add the else, or condition not true,
case.
If it is raining, tell user to get an umbrella else tell
the user that it is sunny.
Flowchart and pseudocode for the modified example is
given next.

Pseudocode logical decision making

11

5/8/2012

Exercise


Work through the three steps of decomposition,


flowcharting, and pseudocode for the following
example.

Given 2 numbers, determine whether or not their sum is


greater than 100.

Week:
Lecture Date:

Course:
Instructor:
Topic:

12
08/05/2012

Computing Fundamental
Dr. Arif Mushtaq
Software Development Methods

12

5/8/2012

Conditions







Most programming languages provide the following


relational operators (sometimes with slightly different
syntax) to make mathematical comparisons between
data within the conditions:
> greater than
< less than
>= greater than/equal to
<= less than/equal to
== equal to
!= not equal to
Also, the following logical operators (or similar) are
usually provided:
&& and
|| or
! not

Conditions


All conditions in computer programming must evaluate to


a Yes/No (or True/False) question.
For instance, we cannot have a condition which branches
like:

13

5/8/2012

Conditions


Computers only understand two things: 0 and 1 (true and false)

We can rewrite all conditions of previous example into a string of


Yes/No questions.

Notice that the > 16 case does not appear in the conditional
expression. Because of this obvious consequence, our flowchart
and pseudocode do not have to explicitly state the final case.
This is known as the default case.

Conditions


If neither of the previous if statements are true, the else is


executed by default.

This if/else chain is mutually exclusive. In other words, if


one condition is true, none of the following conditions are
tested.

14

5/8/2012

Exercise


Write a program that ask the user about


his/her age and then behaves as the
following;
Age< 16 too young to drive
Age = 16 better clear the road
Age > 16 you are getting pretty old

Conditions-Example

15

5/8/2012

Exercise 1
Write down an algorithm for each of the following
problems:1. Find the average of four numbers.
2. Change the time in seconds to minutes.
3. Find the product of two numbers (this
means to multiply the two numbers).
4. Find the difference between two numbers.

Exercise 2
Write a program that tells the user what type of movie they
can attend based on their age, if they are with their
parents, and their amount of money.
 Under 13:
G
 Under 13 w/ parent:
G, PG
 13 and Over and Under 16:
G, PG
 Under 16 w/ parent:
G, PG, R
 16 and Over:
G, PG, R
 Morning:
$7.50
 Evening:
$10.50

16

5/8/2012

Exercise 2 quick sketches

Morning

Morning

Exercise 3
Write a program that will take as input the users bank
account balance, the type and level of account they have.
Based on this information and the below rate table,
determine the interest rate they are receiving.

17

5/8/2012

Exercise- 3 Quick Sketch

Exercise-4
Write a program that will take as input the type of
restaurant the user ate at, the cost of the meal, the number
of people in his/her party, and how good the service was.
 Determine the dollar amount of the tip:

18

S-ar putea să vă placă și