0% found this document useful (0 votes)
25 views40 pages

2.+Business+Information+Systems+ +algorithms

The document outlines the course structure for Business Information Systems, focusing on programming basics, algorithms, and Python programming. Key topics include input/output processes, operating systems, data types, control structures, and file handling, along with practical exercises to reinforce learning. It emphasizes the importance of algorithms in programming and provides examples of flow charts for various programming tasks.

Uploaded by

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

2.+Business+Information+Systems+ +algorithms

The document outlines the course structure for Business Information Systems, focusing on programming basics, algorithms, and Python programming. Key topics include input/output processes, operating systems, data types, control structures, and file handling, along with practical exercises to reinforce learning. It emphasizes the importance of algorithms in programming and provides examples of flow charts for various programming tasks.

Uploaded by

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

Business Information Systems -

WPO
Academic year 2022 – 2023
Alessandro Marchese
Course overview (WPO’s):

1. Introduction
2. Basic concepts in programming
1. Input
2. Output
3. Operating systems
3. Algorithms
4. Programming with Python
1. Data types and operators
2. Data structures
3. Conditions and iterations (if, for and while loops)
4. Functions
5. Reading and writing files
6. Exercises (all of the above combined)

Overview
● Input → Algorithm/Program → Output

● OS: Dynamically allocates CPU and Memory to


different programs on machine ~ Decides what to
run when

This happens seemingless so we will not have to


worry about this

Basics
Course overview (WPO’s):

1. Introduction
2. Basic concepts in programming
1. Input
2. Output
3. Operating systems
3. Algorithms
4. Programming with Python
1. Data types and operators
2. Data structures
3. Conditions and iterations (if, for and while loops)
4. Functions
5. Reading and writing files
6. Exercises (all of the above combined)

Overview
Revisiting the concept of “algorithm”

Formal The sequence of steps


should be clear
definition:
An algorithm is an ordered sequence of
Each step must be unambiguous, executable steps that
written in such a way Each step should be
that only one
describe a finite / ending process possible (divide by zero,
interpretation is determine number of stars
possible in universe)

A clear stop condition must


be present (process must
stop after finite time)

Algorithms
Informal example: a recipe
Automating algorithms
Given algorithms are ordered and unambiguous,
they are very convenient for automating repetitive
and complex problems

🡺 Higher efficiency / productivity


🡺 Less repetitive tasks for humans (e.g. tail
division)

• Computer = ideal for automation

• Computer, however, can only execute instructions


that the computer can "understand”
🡺 Programming
🡺 Converting to binary code
Algorithms
Steps in programming (See slides HOC for more
details):

1. Problem definition: input, output and the


relationship
2. Solution strategy: division into sub-problems
3. Steps in programming: Flow Chart, Block
diagram, Pseudo Code…
4. Programming (e.g. in Python)
5. Compiling
6. Testing
7. Documenting
8. Maintenance

Algorithms
Basic Figures - Flow chart :

- Process

- Input / Output I O

- Choice

- Begin / End Begin End

- Comments

- Sub-process
(procedure)

Algorithms
Sequence, selection and iteration in Flow chart :

1. Sequence
An algorithm is a sequence of commands that are executed consecutively.

Consequently, the sequence of commands is crucial.

That sequence can be interrupted by a selection or an iteration.

Algorithms
Sequence, selection and iteration in Flow chart :

2. Selections (conditional assignments – If… Then…(Else))

In Flow Chart / Organigram: Rhombus (Choice)

2 types:
Type I: If … Then …
– If condition is met: execute what is defined by program after 'Then'
statement
– If condition is not met: do nothing concrete (= skip 'Then' statement)

When to use? When you want to run part of your program/algorithm


only if a certain condition is met

Algorithms
Sequence, selection and iteration in Flow chart :

Type I: example

Algorithms
Sequence, selection and iteration in Flow chart :

Type II: If … Then … Else…


– If condition is met: execute what is defined by program after 'Then'
statement
– If condition is not met: specify what program does if condition is not met

When to use? When you want to run part of your program/algorithm only if
a certain condition is met and run another part of your program /
algorithm if the condition is not met

(Type III: Case = nested If’s = combination of several Type I or / and II)

Algorithms
Sequence, selection and iteration in Flow chart :

Type II: example

Algorithms
Sequence, selection and iteration in Flow chart :

CAUTION: Always define unambiguously!

A programmer's partner says to him/her:

"Please go to the store and buy a bottle of milk, and if they have eggs, bring
six.“

Consequence?

Programmer takes six bottles of milk

N.B.: the action (statement) of a selection / iteration can itself also be


a sequence of actions

Algorithms
Sequence, selection and iteration in Flow chart :

3. Iterations (Repeat assignment or loop – while / repeat / for)

In Flow Chart : combination of a rhombus (Choice) and rectangle (process)


– sequence / order depends on Type of iteration

I O

Algorithms
Sequence, selection and iteration in Flow chart :

3 types
Type I: While: Execute as long as the condition is met

When to use? If you want


to run part of your
program/algorithm as
long as a condition is met

i.e., the statement can be


executed 0 or more times,
whereas with the 'if'
statement, the 'Then'
statement is executed only
once if the condition is met

Algorithms
Sequence, selection and iteration in Flow chart :

NOTE: Make sure that the set condition is not always true 🡺
stuck in repeat / loop

A programmer goes to the supermarket. His/Her partner


says to him, "While you are out, bring some milk.“

Consequence?

He never came home.

Algorithms
Sequence, selection and iteration in Flow chart :

3 types
Type II: Repeat: Execute until condition is met

• When to use? If you want to


execute part of your program /
algorithm as long as a certain
condition is not met
• i.e. if that part of your program
must be executed at least once

Algorithms
Sequence, selection and iteration in Flow chart :

3 types
Type II: Repeat: Execute until condition is met

• Can be rewritten as Type I

Algorithms
Sequence, selection and iteration in Flow chart :

NOTE: Make sure that the set condition is always met at


some point 🡺 stuck in repeat / loop

While the stone is not on top of the mountain, Sisyphus


pushes the stone towards the top of the mountain BUT the
stone automatically rolls down 10m before the top.

Consequence?

Stone never reaches the top →


Sisyphus pushes the stone for ever

Algorithms
Sequence, selection and iteration in Flow chart :

3 types
Type III: For: Execute x amount of times

When to use?
• If you want to run part of your
program/algorithm a specific number of times
• i.e. you know in advance how many times it
must be performed

This type is not predefined in Flow Charts

Algorithms
Sequence, selection and iteration in Flow chart :

3 types
Type III: For: Execute x amount of times

• Can be written as Type I

Algorithms
Sequence, selection and iteration in Flow chart :

NOTE:
● If x is a fixed amount of times 🡺 no infinite loop is
possible
● If x gets changed during looping 🡺 infinite loop is
possible
● Forget to count 🡺 infinite loop

Do 10 push-ups but for every push-up you do you are going to do one more.
→ 10 becomes 11, then 12, then 13, …

Algorithms
Exercise 1

Use a flow chart to represent the program that determines the state of the weather based
on a criterion: the temperature. The user should first submit today's temperature (T) and
the program will give the following results:

• If 15 <= T < 20: Reasonable weather today


• If 20 <= T < 25: Nice weather today
• If 25 <= T: Wonderful weather today
• If T < 15: Horrible weather today

Always write out these results as text.

Tip: nested if

Exercices
Potential solution exercise 1

O O

Exercices
Exercise 2

Exercise 2.1
Design a Flow Chart for the algorithm representing the sum of the first 5 natural numbers
(Consider 0 to be the first natural number).

Exercise 2.2
Also design a Flow Chart for the same algorithm, but ask for input from the user about the
amount of natural numbers the algorithm should sum / add up: if the user enters, e.g., 12,
the algorithm should display the sum of the first 12 natural numbers (Consider 0 to be the
first natural number).

Tips:
• while or repeat
• First define a ‘counter’ (= initialisation)

Exercices
Potential solution exercise 2.1

Exercices
Potential solution exercise 2.2

Exercices
Exercise 3

The country Economania has coins and notes of 1, 5, 10, 100 en 500 Econos.

In the National Bank of Economania, employees are trained to hand out as few coins and
notes as possible, i.e. they try to:
• use as much notes of 500 Econos as possible; then
• use as many notes of 100 Econos as possible; etc.

For example, if you want to give someone 468 Econos, you will give them four notes of
100, six notes of 10, one note of 5 and three coins of 1, for a total of 14 notes and coins.

Design a flow chart for the algorithm that calculates how many notes and coins
employees should spend for any amount.

Tip: nested while loops

Exercices
Potential solution exercise 3

Exercices
Exercise 4

The taxable income of residents in Economania is taxed in 'brackets'. The income


brackets and corresponding tax rates are defined as follows:

Income brackets Marginal tax rate


Up til 10.000 Econos per year 0%
Up til 30.000 Econos per year 10 %
Up til 100.000 Econos per year 25 %
More than 100.000 Econos per year 40%

** More info on how tax brackets work exactly on the next slide

Design a flow chart for the algorithm that calculates how much tax a resident has to pay
when he/she enters his/her taxable income.

Exercices
Exercise 4 – Background on tax brackets
The system of tax brackets means that taxable income is
divided into brackets. A certain tax rate is applied to each
bracket.
Suppose you have a taxable income of 127,000 Econos in
Econlandia, your tax will be calculated as follows:
• Income below 10.000 Econos = 10.000 * 0% = 0 Econo in
taxes
• Income between 10.000 and 30.000 Econos = 20.000 *
10% = 2.000 Econo in taxes
• Income between 30.000 and 100.000 Econos = 70.000 *
25% = 17.500 Econos in taxes
• Income above 100.000 Econos = 27.000 * 40% = 10.800
Econos in taxes

Total tax
= 0 + 2000 + 17.500 + 10.800 Econos
= 30.300 Econos

Tip: Sequential type I if / while loops / ...


Exercices
Potential solution exercise 4 (continued on the next slide)

Exercices
Potential solution exercise 4 (continued on the next slide)

Exercices
Potential solution exercise 4

Exercices
Exercise 5 (Homework)

Design the algorithm using a flow chart that calculates the quotient of a natural number
consisting of 3 digits (= dividend) and a natural number of 2 digits (= divisor) (i.e., the flow
chart for a tail division).

For an explanation of a long division, see:


https://www.youtube.com/watch?v=eIUoIhfupuA

The quotient must be an integer and your algorithm should also display the residual value.

Exercises
Exercise 5 (Homework) - Continued

Steps:
• Step 1 : Problem definition : input (dividend and divisor), output (quotient) and the
relationship.
• Step 2 : Solution strategy : Divide the main problem into smaller actions you can
solve. In this specific case, you need to write down in words the different actions
you need to perform for the execution of a long division from start to finish :
• Execute a long division (following the instructions in the assignment) and try
to identify every action you perform (in your mind) and write them down.
• Try to perceive every action you identify either as a statement, either as an
input or an output, either as a choice (in order to construct a selection or an
iteration) in the flow chart.
• If you cannot convert one of your actions into one of these basic stuctures,
you need to divide this action into smaller actions until you are able to do so.
• Step 3 : Convert the words you wrote down in step 2 into a flow chart.

Exercises
Potential solution exercise 5

Exercises
Potential solution exercise 5 - Continued

O
O

Exercises

You might also like