0% found this document useful (0 votes)
62 views

Problem Analysis

This document provides an introduction to programming and problem solving concepts including: 1. The IPO (Input, Process, Output) model for describing the fundamental architecture of computer systems. It also describes the IPO(S) model which includes Storage. 2. Steps for problem solving such as analysis and design, implementation and testing, and maintenance. 3. Definition of algorithms as finite sequences of unambiguous instructions to solve problems within a finite time. 4. Examples of writing algorithms to solve simple problems like displaying messages, calculating sums, and determining averages.

Uploaded by

Osha Al Mansoori
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
62 views

Problem Analysis

This document provides an introduction to programming and problem solving concepts including: 1. The IPO (Input, Process, Output) model for describing the fundamental architecture of computer systems. It also describes the IPO(S) model which includes Storage. 2. Steps for problem solving such as analysis and design, implementation and testing, and maintenance. 3. Definition of algorithms as finite sequences of unambiguous instructions to solve problems within a finite time. 4. Examples of writing algorithms to solve simple problems like displaying messages, calculating sums, and determining averages.

Uploaded by

Osha Al Mansoori
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

12/09/2021

1 Introduction to Programming and Problem Solving


SWE-225
2 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
‣ PyCharm - Install the Python programming environment and
practice basic syntax
3 Problem Definition to Problem Solving
Analysis, Design, Coding, and Testing
4 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?
5 IPO(S) Model
‣ Input
‣ Computer systems include methods for accepting data and
instructions from inside and outside the system.
‣ Example of input devices include: Keyboard, Mouse, Disk, and
Network
‣ Process
‣ Based on instructions given, the computer systems has the
ability to process i.e., to change, and transform data
‣ Basic data processing operations include:
‣ Arithmetic calculations
‣ Logical & Relational decisions

1
‣ Arithmetic calculations
‣ Logical & Relational decisions
‣ Data manipulation, storage, & retrieval
6 IPO(S) Model
‣ Output
‣ Computer systems has the ability to present processed data in a
form that is understood by the users
‣ Example of output devices include: Screen/Monitor, Printer, and
Network
‣ Storage
‣ Computer systems has the ability to store data 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
7 Problem Solving
‣ Computers and associated programs are tools used to help in
solving scientific problems
‣ Steps for Problem Solving
‣ Analyse & Design:
‣ Clearly analyse and understand the requirements
‣ 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
8 Analyse & Design
1 ‣ As a first step towards problem solving, we need to:
‣ Clearly understand the problem and list out:
‣ Required INPUTS
‣ PROCESS to arrive at the solution – Write an Algorithm
‣ Expected results or OUTPUT for the input and process
‣ An Algorithm

2
1

‣ Expected results or OUTPUT for the input and process


‣ An Algorithm
‣ is a tool used to clearly understand and design the solution to a
given problem.
‣ is a step-by-step problem-solving process in which a solution is
arrived at, in a finite number of steps and amount of time.
2 ‣ Problem: Add two numbers, 83 and 2.
‣ Input: Two integers that are given 83 and 2
‣ Process: Addition (+)
‣ Expected Output: 85

‣ Algorithm
1. Start
2. Write 83+2
3. Stop
9 Implement & Test
‣ Once the Algorithm is developed, it can be used to guide a
programmer to write a computer program.
‣ The programmer implements the program using a programming
language like Python or Java.
‣ The program is then executed by the computer and the result is
displayed
‣ The result is verified with the required solution of the problem.
10 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 Algorithms
Learn to write algorithms
12 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.
11

12

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 a 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.
13 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
14 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
15 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 name
3. Write “Hello ” + name + “ nice to meet you.”
4. Stop
16 Class Work
‣ Problem: Write an algorithm to determine and display the sum of
any two numbers.
16
‣ Problem: Write an algorithm to determine and display the sum of
any two numbers.
‣ Inputs: Two unknown numbers, <number1> & <number2>
‣ Output: Sum of the two numbers given by user
‣ Algorithm
1. Start
2. Write “Enter first number: ”
3. Read number1
4. Write “Enter second number: ”
5. Read number2
6. result = number1 + number2
7. Write “Sum is: ” + result
8. Stop
17 Class Work
‣ Problem: Write an algorithm to determine and display the square
and cube of a number.
‣ Inputs: An unknown number <number1>
‣ Output:
‣ Square of number1
‣ Cube of number1
‣ Algorithm
1. Start
2. Write “Enter a number: ”
3. Read number1
4. square = number1 * number1
5. cube = number1 * number1 * number1
6. Write “Square is: ” + square
7. Write “Cube is: ” + cube
8. Stop
18 Class Work
‣ Problem: Write and algorithm to determine and display the
average of 3 numbers.
‣ Inputs: Three unknown numbers <number1>, <number2>,
<number3>
‣ Output: Average of 3 numbers
‣ Algorithm
1. Start
2. Write “Enter 3 numbers: ”
3. Read number1, number2, number3

19
2. Write “Enter 3 numbers: ”
3. Read number1, number2, number3
4. average = (number1 + number2 + number3) / 3
5. Write “Average is: ” +average
6. Stop
19 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.
20 Class Work
‣ What would be the output of the following algorithm?
‣ Algorithm
1. Start
2. number1 = number2 = number3 = 0
3. number1 = 3
4. number2 = number1 * 4
5. number1 = number2
6. number3 = number3 + number2 + number1
7. Write number1
8. Write number2
9. Write number3
10. Stop
21 Class Work
‣ What would be the output of the following algorithm?
‣ Algorithm
1. Start
2. number1 = 0
3. number2 = 0
4. number3 = 0
5. number4 = 0
6. number1 = 2
7. number2 = number1 * 2
8. number3 = number2 + number1 * 4
9. number4 = (number2 + number1) * 4
10. Write number3

22
9. number4 = (number2 + number1) * 4
10. Write number3
11. Write number4
12. Stop
22 Class 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.
23 PyCharm
An IDE for writing Python Programs
24 Download Python 3
‣ Navigate to https://www.python.org/ on your browser.
‣ Click on downloads in the menu and click on Python 3.x
25 Download Python 3
‣ Click on downloads in the menu and click on Python 3.x
‣ Once downloaded, install the package.
26 Download IDE
‣ Navigate to https://www.jetbrains.com/pycharm/ on your browser
27 Community Version – Open Source
28 Download and Install
29 Add to Applications
30 Start PyCharm
‣ Open the PyCharm application
‣ Create a New Project
31 MyFirstProject
32 MyFirstProject
33 Create a Python File
34 Write a Run a Python Program
35 Algorithms to Programs
Basic Python statements
36
1
33

34

35
Basic Python statements
36 Learning Python
1 ‣ Write an algorithm to display a message.
‣ Algorithm
1. Start
2. Write “Hello, How are you?”
3. Stop
2 ‣ Python

# Print a String

def main():
print("Hello how are you?”)

main()
37 Learning Python
1 ‣ Write an algorithm to add two numbers, 8 and -2
‣ Algorithm
1. Start
2. Write 8 + (-2)// 6
3. Write (“8+(-2)”//8+(-2))
4. Stop
Add 8+(-2)
Between ”” print as it is
2 ‣ Python

# Addition

def main():
print(8 + (-2))
print("8 + (-2)”)

Main()

The result for the first one is 6


And second is
8 + (-2)
38
1
And second is
8 + (-2)
38 Learning Python
1 ‣ Write an algorithm to ask someone’s name and greet her/him.
‣ Algorithm
1. Start
2. Write “Enter your name"
3. Read name
4. Write “Hello ” + name + “ nice to meet you.”
5. Stop
2 ‣ Python

# Reading user input

def main():
name = input("Enter name: ")
print("Hello “ + name + “ nice to meet you.”)

Main()
The output:

Enter name: osha


Hello osha nice to meet you.
39 Learning Python
1 ‣ Write an algorithm to add any two numbers given by user.
‣ Algorithm
1. Start
2. Write “Enter first number: ”
3. Read number1
4. Write “Enter second number: ”
5. Read number2
6. result = number1 + number2
7. Write “Sum is: ” + result
8. Stop
2 ‣ Python
‣ # Add two numbers given by user

number1 =int(input("enter first number"))
2


number1 =int(input("enter first number"))
number2 = int(input("enter second number"))
result= number1 + number2
print("sum is", result)

‣ The output is
‣ enter first number 3
‣ enter second number 5
‣ sum is 8
‣ OR
‣ number1 =int(input("enter first number"))
number2 = int(input("enter second number"))
print(number1+number2)
print("number1+number2")
result= number1 + number2
print("sum is", result)
‣ Output:
‣ enter first number4
‣ enter second number5
‣ 9
‣ number1+number2
‣ sum is 9
40 Learning Python
1 ‣ Write an algorithm to determine and display the square and cube
of a number.
‣ Algorithm
1. Start
2. Write “Enter a number: ”
3. Read number1
4. square = number1 * number1
5. cube = number1 * number1 * number1
6. Write “Square is: ” + square
7. Write “Cube is: ” + cube
8. Stop
2 ‣ Python
‣ # Program to find square and cube of a user given number

number1= int(input("enter a number:"))
square= number1*number1
cube= number1*number1*number1
2

square= number1*number1
cube= number1*number1*number1
print("square is", square)
print("cube is", cube)
‣ Output:
‣ enter a number:3
‣ square is 9
‣ cube is 27
41 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
‣ Install PyCharm IDE and run a python program
‣ Exercise basic Python syntax

You might also like