[go: up one dir, main page]

0% found this document useful (0 votes)
7 views20 pages

SDF Week2

Voici SDF-Week2

Uploaded by

Marouane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views20 pages

SDF Week2

Voici SDF-Week2

Uploaded by

Marouane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

3/10/2024

Software Development Fundamentals


Week 2

Dr. Loubna Mekouar

Note:
• Some of the slides of the course are based on the material provided
by the College of Technological Information, Zayed University, UAE.
• The copyrighted material belongs to their respective owners.

1
3/10/2024

Topics of Discussion
• Problem Definition to Problem Solving
• The IPO Model
• Understand simple development cycle:
• Analysis & Design
• Implement & Test
• Maintain

• Algorithms
• Learn to write algorithms

Problem Definition to Problem Solving


Analysis, Design, Coding, and Testing

2
3/10/2024

The IPO Model


• The fundamental architecture of a computer system rests on the
foundation of IPO Model.

• The Input, Process, Output (IPO) Model


• A computer processes input data to produce results/output.
• (I) Input - Data provided to the computer
• (P) Process- Actions taken on the input by the computer
• (O) Output - Results from the computer processing

• The model is also known as the IPO(S) model.


• What do you think ‘S’ stands for?

IPO(S) Model
• Input
• Computer systems include methods for accepting
data and instructions from inside and outside the INPUT
system
• Example of input devices include: Keyboard,
Mouse, Disk, and Network

• Process
• Based on instructions given, the computer systems PROCESS STORAGE
has the ability to process i.e., to change, and
transform data
• Basic data processing operations include:
• Arithmetic calculations
• Logical & Relational decisions
• Data manipulation, storage, & retrieval OUTPUT

3
3/10/2024

IPO(S) Model
• Output
• Computer systems have the ability to present
processed data in a form that is understood by the INPUT
users
• Example of output devices include: Screen/Monitor,
Printer, and Network

• Storage
• Computer systems have the ability to store data PROCESS STORAGE
and programs temporarily and permanently
• Random Access Memory (RAM) for short-term and
temporary storage
• Secondary storage devices like Hard Disk and USB
for long-term and permanent storage OUTPUT

Problem Solving
• Computers and associated programs are tools used to help in solving
scientific problems

• Steps for Problem Solving


• Analyze & Design:
• Clearly analyze and understand the requirement
• Design a sequential, step-wise approach to arrive at the solution
• Implement & Test
• Implement the designed steps in a programming language (ex. Python)
• Test the program for different input cases, to verify if all requirements are met
• Maintain
• Modify if the problem domain or requirement changes
• Modify to improve performance

4
3/10/2024

Analyze & Design


• As a first step towards problem solving, it is Problem: Add two numbers,
83 and 2.
required to:
• Clearly understand the problem and list out:
Input: Two integers that are
• Required INPUTS
given 83 and 2
• PROCESS to arrive at the solution – Write an Algorithm
Process: Addition (+)
• Expected results or OUTPUT for the input and process
Expected Output: 85

• An Algorithm Algorithm
• is a tool used to clearly understand and design the 1. Start
solution to a given problem. 2. Write 83+2
• is a step-by-step problem-solving process in which 3. Stop
a solution is arrived at, in a finite number of steps
and amount of time.
9

Implement & Test


• Once the Algorithm is
developed, it can be used to # Program in Python
guide a programmer to write a
computer program. # Add and Display Result
print(83 + 2)
• The programmer implements the
program using a programming
language like Python or Java.
// Program in Java
// Add and Display Result
• The program is then executed by public class AddNum {
the computer and the result is public static void main(String[] args){
displayed System.out.println(83+2);
}
• The result is verified with the }
required solution of the
problem.

10

10

5
3/10/2024

Maintain
• Problem requirements and applications can change and therefore the
programs can be altered or modified to adapt to the changes.

• Once the program is working well for a specified set of requirements,


then it could be modified for various reasons, like:
• To use a different set of inputs
• To use a different process
• Improving performance and efficiency (faster results in shorter time)
• Improving readability

11

11

Algorithms
Learn to write algorithms

12

12

6
3/10/2024

Al-Khwarizmi

13

13

Definition
• An algorithm is a finite sequence of steps performing a task such that,
each step is a clear and unambiguous instruction, which can be
executed in finite time.

• The sequence in which the steps are to be executed is clearly defined.


• The process is guaranteed to stop in finite time.
• After a finite number of steps have been executed.
• The process (hence the algorithm) has a purpose.
• There is an input to the process and an output from the process.

14

14

7
3/10/2024

Class Work
• Problem: Write an algorithm to display a message “Hello, How are
you?”
• Inputs: None (the problem has no unknowns)
• Output: “Hello, How are you?”

• Algorithm
1. Start
2. Write “Hello, How are you?”
3. Stop

15

15

Class Work
• Problem: Write an algorithm to determine and display the sum of 8
and -2. (Assuming that 8 and -2 are numbers)
• Inputs: None (the problem has no unknowns)
• Output: 6

• Algorithm
1. Start
2. Write 8 + (-2)
3. Stop

16

16

8
3/10/2024

Class Work
• Problem: Write an algorithm to ask someone’s name and welcome
the person.
• Inputs: One unknown input, <name>
• Output: “Hello ” <name> “ nice to meet you.”

• Algorithm
1. Start
2. Read uName
3. Write “Hello ” + uName + “ nice to meet you.”
4. Stop

17

17

Read/Write statements and Variables


• Read/Write statements
• Write is a command/instruction given to the computer
• “+” is a command given to the computer
• The computer executes a Write statement after completing the arithmetic
operations.
• Read is command given to the computer
• The computer waits after the Read statement for the user to enter a value.

• Variables: ex. uName


• Variables are memory locations that store information for the duration of the
program execution
• When a variable is created some space in memory is reserved.
• The user input is stored in the variable or the variable can be assigned a value
within the program

18

18

9
3/10/2024

Class Work
• Problem: Write an algorithm to determine and display the sum of any two
numbers.
• Inputs: Two unknown numbers, <iNum1> & <iNum2>
• Output: Sum of the two numbers given by user

• Algorithm
1. Start
2. Write “Enter first number: ”
3. Read iNum1
4. Write “Enter second number: ”
5. Read iNum2
6. iResult = iNum1 + iNum2
7. Write “Sum is: ” + iResult
8. Stop
19

19

Assignment Statement
• Observe the sequence of instructions. If the particular sequence is not
followed, the output would be different.

• The variable names represent locations in memory where the data is stored

• To evaluate an assignment statement: Q=f(x)


• Evaluate the "right side" of the expression (to the right of the equal
sign).
• Place the computed result into the variable that is on the left of the
equal sign.

• Write similar algorithms in class


• For subtraction, multiplication, and division

20

20

10
3/10/2024

Class Work
• Problem: Write an algorithm to determine and display the square and cube of a
number.
• Inputs: An unknown number <iNum1>
• Output:
• Square of iNum1
• Cube of iNum1

• Algorithm
1. Start
2. Write “Enter a number: ”
3. Read iNum1
4. iSquare = iNum1 * iNum1
5. iCube = iNum1 * iNum1 * iNum1
6. Write “Square is: ” + iSquare
7. Write “Cube is: ” + iCube
8. Stop

21

21

Class Work
• Problem: Write and algorithm to determine and display the average
of 3 numbers.
• Inputs: Three unknown numbers <iNum1> , <iNum2> , <iNum3>
• Output: Average of 3 numbers

• Algorithm
1. Start
2. Write “Enter 3 numbers: ”
3. Read iNum1, iNum2, iNum3
4. iAverage = (iNum1 + iNum2 + iNum3) / 3
5. Write “Average is: ” + iAverage
6. Stop

22

22

11
3/10/2024

Class Work
• Problem: Write an algorithm to determine and display the area of a
triangle where the base and height is given by the user. Ensure to
show the result as “Area = nnn”.

• Inputs: ?
• Output: ?

• Algorithm: Complete the algorithm and walkthrough with different


inputs to check the validity of the algorithm.

23

23

Review
• Write an ALGORITHM to determine the selling price of an item in a
shop where everything is sold at 10% discount. Your algorithm must
finally display the cost, the discount amount, and the final selling
price.

24

24

12
3/10/2024

Class Work
• What would be the output of the following algorithm?
• Algorithm
1. Start
2. iNum1 = iNum2 = iNum3 = 0
3. iNum1 = 3
4. iNum2 = iNum1 * 4
5. iNum1 = iNum2
6. iNum3 = iNum3 + iNum2 + iNum1
7. Write iNum1
8. Write iNum2
9. Write iNum3
10. Stop

25

25

Class Work
• What would be the output of the following algorithm?
• Algorithm
1. Start
2. iNum1 = iNum2 = iNum3 = iNum4 = 0
3. iNum1 = 2
4. iNum2 = iNum1 * 2
5. iNum3 = iNum2 + iNum1 * 4
6. iNum4 = (iNum2 + iNum1) * 4
7. Write iNum1
8. Write iNum2
9. Write iNum3
10. Write iNum4
11. Stop

26

26

13
3/10/2024

Home Work
• Problem: Write an algorithm to evaluate the expression:
f(x) = 15x2 + 4x + 2.

• Inputs: ?
• Output: ?

• Algorithm: Complete the algorithm and walkthrough with different inputs


to check the validity of the algorithm.

• Note: Arithmetic Operator Precedence


• ()
• */
• +-

27

27

Algorithms to Programs
Basic Python statements

28

28

14
3/10/2024

Learning Python
• Write an algorithm to display • Python
a message. # Print a String
#

• Algorithm print("Hello how are you?")


1. Start
2. Write “Hello, How are you?”
3. Stop

29

29

Learning Python
• Write an algorithm to add • Python
two numbers, 8 and -2 # Addition
#
• Algorithm print(8 + (-2))
1. Start
2. Write 8 + (-2)
3. Stop

30

30

15
3/10/2024

Learning Python
• Write an algorithm to ask someone’s name and greet her/him.
• Algorithm
1. Start
2. Write “Enter name: ”
3. Read uName
4. Write “Hello ” + uName + “ nice to meet you.”
5. Stop

• Python
# Reading user input
#
uName = input("Enter name: ")
print("Hello "+uName+" nice to meet you.")

31

31

Learning Python
• Write an algorithm to add any • Python
two numbers given by user. # Add two numbers given by user
#

• Algorithm
1. Start
2. Write “Enter first number: ”
3. Read iNum1
4. Write “Enter second number: ”
5. Read iNum2
6. iResult = iNum1 + iNum2
7. Write “Sum is: ” + iResult
8. Stop

32

32

16
3/10/2024

Learning Python
• Write an algorithm to • Python
determine and display the # Program to find square and cube of
square and cube of a a user given number
#
number.
• Algorithm
1. Start
2. Write “Enter a number: ”
3. Read iNum1
4. iSquare = iNum1 * iNum1
5. iCube = iNum1 * iNum1 * iNum1
6. Write “Square is: ” + iSquare
7. Write “Cube is: ” + iCube
8. Stop

33

33

Learning Python
• Write and algorithm to determine • Python
and display the average of 3 # Program to find average of
numbers. three numbers
#

• Algorithm
1. Start
2. Write “Enter 3 numbers: ”
3. Read iNum1, iNum2, iNum3
4. iAverage = (iNum1 + iNum2 + iNum3) / 3
5. Write “Average is: ” + iAverage
6. Stop

34

34

17
3/10/2024

Learning Python
• Python

Refer to the algorithm completed earlier and write a


python program to determine and display the area of a
triangle where the base and height is given by the user.
Ensure to show the result as “Area = nnn”.

35

35

Learning Python
• Algorithm • Python
1. Start Convert the algorithm into a Python
2. iNum1 = iNum2 = iNum3 = 0 program and verify the results.
3. iNum1 = 3
4. iNum2 = iNum1 * 4
5. iNum1 = iNum2
6. iNum3 = iNum3 + iNum2 + iNum1
7. Write iNum1
8. Write iNum2
9. Write iNum3
10. Stop

36

36

18
3/10/2024

Learning Python
• Algorithm • Python
1. Start
2. iNum1 = iNum2 = iNum3 = iNum4 = 0 Convert the algorithm into
3. iNum1 = 2 a Python program and verify
the results
4. iNum2 = iNum1 * 2
5. iNum3 = iNum2 + iNum1 * 4
6. iNum4 = (iNum2 + iNum1) * 4
7. Write iNum1
8. Write iNum2
9. Write iNum3
10. Write iNum4
11. Stop

37

37

Learning Python
• Problem: Write a python program to evaluate the expression:
f(x) = 15x2 + 4x + 2.

• Inputs: ?
• Output: ?

38

38

19
3/10/2024

In Summary
• The IPO(S) model describes how problems are solved by computers

• The different stages of problem solving


• Analysis and Algorithm Design
• Implementation and Testing
• Maintenance

• Algorithms are step-by-step process to solve a given problem.


• Read/Write
• Assignment statements
• Variables
• Precedence of Arithmetic Operators
39

39

20

You might also like