Programming for Engineers
0107200
Introduction and Development Environment Setup
Dr. Naeem Odat
College of Engineering
Department of Computer and Communications Engineering
Dr. Naeem Odat Introduction and Development Environment Setup
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Concept of programming
Computer programming is important today because so much of our
world is automated. Humans need to be able to control the
interaction between people and machines. Since computers and
machines are able to do things so efficiently and accurately, we
use computer programming to harness that computing power.
Computer programs are collections of instructions that tell a
computer how to interact with the user, interact with the computer
hardware and process data.
Algorithm: is a step by step plan to solve a problem, or a detailed
set of steps we followed to solve a particular problem. It is a recipe
to do something.
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Example - find the queen
The problem: Find the queen of hearts in a deck of cards.
Constraints: Your algorithm should have sufficient details that any
processing agent can follow.
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Example - find the queen - possible solutions
The algorithm:
Look through the deck:
If you find the queen of hearts:
Say so.
The problem:
Not enough details.
Assumes the agent knows how to ”look” and ”find”
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Example - find the queen - possible solutions
The algorithm:
If the top card is the queen of hearts:
Say so.
Otherwise, if the second card is the queen of hearts:
Say so.
Otherwise, if the third card is the queen of hearts:
Say so.
.....
The problem:
You should know how many cards are there.
The algorithm is very long.
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Example - find the queen - possible solutions
The algorithm:
While there are more cards in the deck:
If the top card is the queen of hearts:
Say so and discard the queen.
Otherwise, disard the top card.
The problem. Nothing!
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Programming process
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Programming process- writing an algorithm
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Example
Find x y
First step:
We might try x = 3 and y = 4, getting an answer of 34 = 81.
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Second step:
Write down what you just did.
The algorithm is:
Multiply 3 by 3
You get 9
Multiply 9 by 3
You get 27
Multiply 27 by 3
You get 81
81 is the answer
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Third step:
Generalize Your Steps.
First attempt. Replace 3 by x.
Multiply x by 3
You get 9
Multiply x by 3
You get 27
Multiply x by 3
You get 81
81 is the answer
Look for a repetition pattern and the number of times it repeats.
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Third step:
Second attempt: generalize how many times to do the steps, as well
as what the steps are.
Start with n = 3
n = Multiply x by n
n = Multiply x by n
n = Multiply x by n
n is the answer
The steps are repeated y-1 times (x times)
Start with n = 3
Count from 1 to y-1 (inclusive), for each number you count:
n = Multiply x by n
n is the answer
substitute 3 by x
Start with n = x
Count from 1 to y-1 (inclusive), for each number you count:
n = Multiply x by n
n is the answer
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Fourth step: Test your algorithm
The primary purpose is to ensure our steps are actually right before
we proceed.
We test our algorithm with different values of the parameters than
the ones we used to design our algorithm.
We execute our algorithm by hand and compare the answer it
obtains to the right answer.
If they differ, then we know our algorithm is wrong.
What happens when y = 0
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Fourth step: Test your algorithm
One possible solution to the case of y=0
If y is 0 then
1 is the answer
Otherwise:
Start with n = x
Count from 1 to y-1 (inclusive), for each number you count:
n = Multiply x by n
n is the answer
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Fourth step: Test your algorithm
A better algorithm:
Start with n = 1
Count from 1 to y (inclusive), for each number you count:
n = Multiply x by n
n is the answer
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Exercise
Devise an algorithm to draw the following squares when N = 0, 1, 2, 3,
4, 5. Then generalize your algorithm by observing the pattern.
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
One possible solution
Count from N to 0 (inclusive), call each number you count ’y’ and
Count from 0 to y (inclusive), call each numer you count ’x’ and
if (x + y is multiple of 3)
then place place a blue square at (x, y)
otherwise place a red square at (x, y)
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Control structures (building blocks of an algorithm)
Sequence
Say so and discard the queen.
Selection. To make decision.
If the top card is the queen of hearts:
Iteration. Do something repeatedly
While there are more cards in the deck:
Dr. Naeem Odat Introduction and Development Environment Setup
Introduction
Development environment
For windows platform go to ”https://visualstudio.microsoft.com/”
Download the latest Community release of visual studio.
Run the downloaded file and follow the instructions to complete the
installation
Dr. Naeem Odat Introduction and Development Environment Setup