close

Enter

Log in using OpenID

Computer Programming – 1

embedDownload
Computer Programming I
-1Emel KURUOĞLU KANDEMİR, Ph.D.
Alper Vahaplar, Ph.D.
Dokuz Eylul University, Faculty of Sciences
Department of Computer Science
[email protected]
[email protected]
General Information on the Course
Course Code
BIL 2203
Course Name
Computer Programming I
Course Level
Undergraduate
Course Status
Compulsory
Language of
English
Instruction
Weekly Course Hours 2+2 (Theory+Application)
National Credit
2+2
ECTS Credit
5
2
1
Course Objective
• This course provides students who have
basic
knowledge
about
algorithm
development and computer-oriented problem
solving methodologies, to application
development and structured programming
concepts and design techniques.
3
Learning Outcomes of the Course Unit
1. Describing the syntax of the
language,
programming
2. Using control structures,
3. Writing computer program for an algorithm,
4. Developing function and procedure,
5. Debugging,
6. Developing applications for essential statistical
methods.
4
2
Assessment
Assessment Methods
Grading (%)
Midterm Exam
40%
Homework/Quiz
10%
Final Exam
50%
Students whose
average is less than
30 will not be
involved in BNS
5
Student Responsibilities
 Attendance to at least 75% for the lectures is an
essential requirement of this course and is the
responsibility of the student.
It is necessary that attendance to the lecture and
homework delivery must be on time.
Any unethical behavior that occurs either in
homeworks or exams will be dealt with as outlined
in school policy. You can find the undergraduate
policy at http://web.deu.edu.tr/fen
6
3
References
Textbook:
Cormen, T.H., Leiserson, C.E., Rivest, R.L., Stein,
C., Introduction to Algorithms, The MIT Press;
2nd edition, 2001.
Supplementary Book:
Koffman, B., Turbo Pascal, 5th Edition Update,
Addison-Wesley Longman, Inc., 1998
7
8
4
Computer Programming I
-1Emel KURUOĞLU KANDEMİR, Ph.D.
Alper Vahaplar, Ph.D.
Dokuz Eylul University, Faculty of Sciences
Department of Computer Science
[email protected]



[email protected]
Computers – Introduction
Introduction to Programming Languages
Essential Programming Elements
Computer Programming-1
10
5
Computer
Hardware
Software
11
Computer Programming-1
HARDWARE
Input Units
Output Units
Data Storage
Units
Other Elements
Keyboard
Monitor
Mouse
Printer
Scanner
Plotter
Optical Reader
Speaker
Memory:
RAM
ROM
Data:
Hard Disk,
Diskette,
CD, DVD
Mainboard
Video Card
Sound Card
Ethernet Card
Barkod
Reader
Fax-Modem
Microphone
Power Supply
Computer Programming-1
12
6

System Software
◦ Operating Systems (Windows, Linux, Unix, etc.)
◦ Drivers

Application software
◦
◦
◦
◦
◦
Office programs,
Games,
Web Browsers,
Antivirus programs,
etc.
Computer Programming-1

13
2600 (BC) – Abacus
◦ Simple addition and subtraction
Computer Programming-1
14
7

1621– Slide Rule
◦ Addition and subtraction to a constant.
Computer Programming-1

15
1623 – Calculating Clock
◦ First gear-driven calculating machine
Computer Programming-1
16
8

1642 – Pascalina Calculator
◦ Addition with “carry”, subtraction with “borrow”
Computer Programming-1

17
1671 – Leibniz Wheel
◦ Multiplication, Division, Square Root operations
Computer Programming-1
18
9

1801 – Weaving Loom, 1830 – Difference
Engine
◦ Punched Cards
Computer Programming-1

19
1937 – Mark-1
◦
◦
◦
◦
◦
First digital computer
Logarithm
Trigonometry
Slow
1 multiplication
5 sec.
Computer Programming-1
20
10



1946 – ENIAC (Electrical Numerical Integrator And
Computer)
Military use
Can perform
◦ 5000 addition
◦ 385 multiplication
◦ 38 sqr-root



18000 vacuum tubes
30 tons
167 m2
Computer Programming-1



21
1970 – IBM mainframes (3090, 7090, 360, 370)
1971 – First Microprocessor – 4004 – Intel
1976 – APPLE - Steve Wozniak and Steve Jobs
Computer Programming-1
22
11









1980 – IBM PC (Personal Computer)
Microprocessor
8086
80286
80386
80486
80586 (Pentium)
PII, PIII, PIV…
Core2 Duo, i5, i7,…
23
Computer Programming-1
 2013
 Core 4 Quad - i7







2.66GHz or AMD
Phenom II X2 555
4 GByte RAM
1 TByte Hard Disk
22 ‘‘ LCD Monitor
1 Gbyte Display
Adapter
Wireless Modem
Blu-Ray Disc
Windows 7 or Mac
OS X Lion
Computer Programming-1
 2008…
 1993…
 Core2 Duo 2.4 GHz
 80386 DX 40 MHz
 1 GByte RAM
 512 KByte RAM
 320 GByte Hard
 100 MByte Hard

 14 ‘‘ CRT Monitor




Disk
19 ‘‘ TFT Monitor
512 Mbyte Display
Adapter
Wireless Modem
DVD-RW
Windows Vista or
XP
Disk
 32 KByte Display
Adapter
 56 Kbit/sn Modem
 Floppy Disk Driver
 MS DOS + Windows
3.1
24
12

How does a computer use to operate?
◦ Electricty

What is the language of computer?
◦ Binary System (0 or 1)
◦ Why?

Bit (Binary digit)
0
0
0
0
0
0
0
0
8 Bit = 1 Byte
Computer Programming-1







25
(00000001)2 = ( 1 )10
(00000010)2 = ( 2 )10
(00000100)2 = ( 4 )10
(00000101)2 = ( 5 )10
(00000111)2 = ( 7 )10
(11111111)2 = (255 )10
(10000000)2 = (128 )10
Computer Programming-1
26
13





1 Byte = 8 bits
210 Bytes = 1024 Bytes = 1 KiloByte = 1 KByte
220 Bytes = 1024 KBytes = 1 MegaByte = 1 MByte
230 Bytes = 1024 MBytes = 1 Giga Byte = 1 GByte
240 Bytes = 1024 GBytes = 1 Terra Byte = 1 TByte
Computer Programming-1



27
24 Bit
3 Byte = ????
5 MByte = 5120
???? Kbyte
10 Mbyte = 10x1024x1024x8
??????
Bit
Bit
Computer Programming-1
28
14

ASCII and binary characters
Text
ASCII
Binary
A
65
01000001
a
97
01100001
µ
181
10110101
Computer Programming-1




29
Algorithm, named after the 9th century scholar
Ebu Abdullah Muhammed bin Musa elHarezmi.
“An algorithm is;
any well-defined computational procedure that
takes some value, or set of values, as input and
produces some value, or set of values, as output.
An algorithm is thus a sequence of computational
steps that transform the input into the output.”
Computer Programming-1
30
15






Finiteness (Sonluluk)
Definiteness (Kesinlik, açıklık)
Valid Input / Output (Geçerli Giriş/Çıkış, Sonuç)
Effectiveness (Etkinlik)
Infallibility (Yanılmazlık, şaşmazlık)
Performance (Performans)
Computer Programming-1

31
Problem: Make menemen for 1 person
◦
◦
◦
◦
◦
◦
◦
◦
Take 2 eggs
Take a spoon of margarine
Wash a tomatoe and cut into pieces
Wash a pepper and cut into slices
Put all in a saucepan
Burn the oven under the saucepan
Add some salt and black pepper
Until the desired stiffness is acquired
 Stir all with a spoon
◦ Turn off the oven
Computer Programming-1
32
16

Problem: Make a car move
◦
◦
◦
◦
◦
◦
◦
◦
◦
◦
◦
◦
◦
Open the left front door with related key,
Sit on the driver’s seat
Put the key in the key plug
Adjust the driver’s seat
Adjust the rearview mirror, left and right mirrors
Get the gear shift to neutral position in the middle
Put your left foot on the clutch pedal
Turn on the key until the engine starts
Get the gear shift to 1 (upper left side)
Press on gas pedal with your right foot gently
Check the traffic by the mirrors
If is set, drop down hand brake
Slowly pull up your left foot from the clutch pedal
Computer Programming-1






33
Write an algorithm for finding the sum of two
numbers.
Steps:
1. input x
2. input y
3. sum = x + y
4. output sum
Computer Programming-1
34
17



There are two commonly used tools to help
to document the algorithm.
Flowcharts
Pseudocode
Computer Programming-1



35
A flowchart is a graphical representation of an
algorithm.
Pseudocode is a generic way of describing an
algorithm
without
use
of
any
specific
programming language syntax.
Generally, flowcharts work well for small problems
but Pseudocode is used for larger problems.
Computer Programming-1
36
18



Manuel Input
(Veri Girişi)

(Output,
Document)
(Çıkış)

Başlangıç veya bitişi
ifade eder.
Kullanıcı tarafından
veri girileceğini
gösterir.
Kullanıcıya veya
ekrana mesaj
verileceğini belirtir.

(Output, screen)
(Çıkış)

BİL2007 Bilgisayar Mimarisi
Computer Programming-1
Terminator
(Sonlandırıcı)
37
Alper VAHAPLAR

Process (İşlem)


Decision (Karar )

Hesaplama yapıldığı
veya veri işleme
sürecini belirtir.
Bir karşılaştırma,
koşul ve sonucunda
karar verileceğini
ifade eder.
38
19


Connector
(Bağlayıcı)

Arrows,
Directions
(Oklar)

Bir akış şemasının
farklı kısımlarının
bağlanması için
kullanılır.
Algoritmanın akış
yönünü gösterir.
39
Computer Programming-1
Akış Şemaları
Algoritma :
1. Kullanıcı yarıçapı (r) ve
yüksekliği (h) girsin.
2. Silindirin hacmini bulun.
Hacim=  r2  h
3. Silindirin hacmini ekrana
yazdırın.
Akış şeması :
Başlangıç
r, h
Hacim=  r2  h
Hacim
Bitiş
Computer Programming-1
40
20

Compute the sum of two numbers.
Pseudocode:
Flow Chart

Start

Read X, Y

SumX+Y
Sum=X+Y

Write Sum
Sum

Stop
Stop

Start
X,Y
Computer Programming-1








41
All necessary requirements should be listed out in logical
order.
The flowchart should be clear.
The usual direction of the flow is from left to right or top to
bottom.
Only one flow line should come out from a process symbol.
Only one flow line should enter a decision symbol but two
or three flow lines should leave the decision symbol.
Only one flow line is used in conjunction with terminal
symbol.
Use connector symbols to reduce the number of flow lines.
Flowchart must has a logical start and finish.
Computer Programming-1
42
21


Verilecek değerler için kişinin Vücut Kitle
Endeksini (Body-Mass Index – BMI)
hesaplayan algoritmayı yazınız ve akış
şemasını çiziniz.
BMI = Ağırlık (kg) / [Uzunluk (m)]2
1. Başla
2. Ağırlık, Boy al
3. BMI = Ağırlık/(boy*boy)
4. BMI yazdır
5. Bitir
43
Computer Programming-1
Başlangıç
BMI
Ağırlık, Boy
BMI = Ağırlık / Boy
Computer Programming-1
2
Bitiş
44
22
Akış Şemaları
Akış Şeması :
Algoritma :
1. Kullanıcı iki sayı
girsin.
2. İki sayıdan büyük
olanı bulun.
3. Bulunan sayıyı
ekrana yazdırın.
Başlangıç
x, y
Doğru
x>y Yanlış
x
y
Bitiş
Computer Programming-1





45
Write an algorithm and draw the flowchart for
finding the average of three numbers.
Write an algorithm and draw the flowchart for
finding the largest number out of two
numbers.
Write an algorithm to write numbers between
1-10.
Write an algorithm to add 25 numbers.
Write an algorithm to find mean value of N
numbers.
◦ if the number is equal to zero write the result and
then stop.
Computer Programming-1
46
23






Design an algorithm and the corresponding
flowchart for:
finding the sum of odd numbers between 10
and 50.
finding the smallest value of N numbers
between 1 and 100.
computing the n!
calculating roots of a quadratic polynomial
(ax2 + bx + c = 0)
finding the largest number which divides two
integers m,n (greatest common divisor)
47
Computer Programming-1
Örnek: Katsayıları verilen ikinci dereceden bir
denklemin reel hesaplayan algoritmayı yazınız.
2
ax + bx + c = 0
1. a, b ve c değerlerini al
2.  değerini hesapla ( = b2 - 4 a c)
3. Eğer  < 0 ise “Reel kök yok” mesajı ver
4. Eğer  = 0 ise x1,2 = -b/2a
5. Eğer  > 0 ise

6. Bitir.
Computer Programming-1
b Δ
2a
b Δ
x2 
2a
x1 
48
24
Başlangıç
x1   b    2a
a, b, c
 = b24ac
Doğru
<0
Kök
Yok!!!
x 2   b    2a
Yanlış
=0
Yanlış
x1 , x2
Doğru
x1,2 = -b/2a
X1,2
Bitiş
Computer Programming-1

1.
2.
3.
4.
5.
1’den 10’a kadar
sayıları yazdıran
algoritma
Sayaç  1
Sayaç’ı yaz.
Sayaç  Sayaç + 1
Sayaç 11’den küçük
ise 2. adıma git.
Bitir.
Computer Programming-1
49
Başlangıç
Sayaç1
Sayaç
SayaçSayaç+1
Doğru
Sayaç<11
Yanlış
Bitiş
50
25
Başlangıç
Toplam  0

1.
2.
3.
1’den 50’ye kadar olan
Sayı  1
sayıların toplamını bulan
Doğru
algoritmayı yazınız.
Sayı51
Toplam  0
Yanlış
Sayı  1
Toplam  Toplam+Sayı
Sayı 51’den küçük olduğu
Toplam
sürece
i.
ii.
4.
5.
Toplam  Toplam + Sayı
Sayı  Sayı + 1
Sayı Sayı+1
Toplam’ı yazdır
Bitir.
Bitiş
51
Computer Programming-1
N
x
i 1
N

i

x 1  x 2  ...  x N
?
N
Kullanıcının gireceği N adet verinin
ortalamasını bulup ekrana yazdırın. Veri
sayısını belirleyen N, kullanıcı tarafından
girilecektir.
Computer Programming-1
52
26
1. Kullanıcı N değerini girsin.
2. Toplam  0
3. Sayaç  0
4. Kullanıcı bir Sayı girsin.
5.Toplam  Toplam + Sayı
6. Sayaç  Sayaç + 1
7. Eğer Sayaç < N ise 4. adıma git.
8. Ortalama  Toplam / N
9. Ortalamayı ekrana yazdır.
10. Bitir.
53
Computer Programming-1
Başlangıç
N
Toplam  0
Sayaç  0
Sayı
Sayaç Sayaç+1
Doğru
SayaçN
Yanlış
Ortalama  Toplam / N
Ortalama
Toplam  Toplam+Sayı
Bitiş
Computer Programming-1
54
27
Author
Document
Category
Uncategorized
Views
0
File Size
2 102 KB
Tags
1/--pages
Report inappropriate content