Week 1 Introduction To Programming: CME111 Programming Languages I

Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

CME111 Programming Languages I

Week 1
Introduction to Programming

Assist. Prof. Dr. Caner ÖZCAN


Introduction

► Course Web Site: www.canerozcan.net

► Office Hours: Tuesday 15:00-17:00


Thursday 09:00-11:00
or appointment by email:
canerozcan@karabuk.edu.tr

• Textbooks:
Doç. Dr. Fahri Vatansever, “Algoritma Geliştirme ve Programlamaya
Giriş”, Seçkin Yayıncılık, 12. Baskı, 2015
Harvey Deitel, “C How to Program”, Pearson Education

2
Introduction

► Work hard and practice!

► Grading
▪ Midterm Exam: %40
▪ Final Exam: %60

► Study to learn, not for grade. Grade is already


won.

3
Term Topics

• Lecture 1- Basic Concepts and Algorithm


• Lecture 2- Variable and Operators
• Lecture 3- Control Structures
• Lecture 4- Repetition Structures
• Lecture 5- Algorithm Examples and Analysis-1
• Lecture 6- Algorithm Examples and Analysis-2
• Lecture 7- Introduction to C Programming and C Compiler
• Lecture 8- Basic Data Types of C and Input/Output Operations (printf,
scanf)
• Lecture 9- Control and Repetition Structures of C
• Lecture 10- Arrays
• Lecture 11- Character Arrays
• Lecture 12- Functions-1
• Lecture 13- Functions-2

4
What is Computer?

• A computer is a device capable of performing


computations and making logical decisions.
• Today’s supercomputers can perform trillions of
additions per second.
• A computer is comprised of various devices (such
as the keyboard, screen, mouse, disks, memory,
DVD, CD-ROM & processing units) that are
referred to as hardware.
• Computer programs that run on a computer are
referred to as software.
5
What is Computer?

•One of the earlier computing devices was the


abacus.

6
What is Computer?

• Advancements on computer technology chronologically:


– B.C. 500 Abacus
– 1642 Pascal's Mechanical Addition Machine
– 1827 Babbage's subtraction machine
– 1941 Binary Mechanical Calculator (Zuse)
– 1944 Decimal Electromechanic Calculator (Aiken)
– 1945-54 First Generation Vacuum Tubes and Beams
– 1955-64 Second Generation Transistors and Magnetic
Memories
– 1965-71 Third Generation Integrated Circuits
– 1971-90 Fourth Generation VLSI Circuits
– 1982 IBM Pc & MS-DOS
– 1984 MAC
– 1990’s Parallel Processors

7
What is Computer?

IBM MARK-I
8
What is Computer?

ENIAC- Electronic Numerical Integrator And Computer


9
Computer Organization

10
Data Storage Units

• All data in computer systems are stored in


electrical signals represented by binary 1 or 0.
• Each digit in binary system is called bit.
• Bit is not enough to express a quantity. We use
byte as basic memory unit.
– 1 byte = 8 bits
• Each character in computer system is represented
by 8 bits.
• Example: Character A is represented as 0100001
in binary. Each digit of this number is called bit.

11
Data Storage Units

• Data storage units are as follows from lowest


to highest: Bit, Byte ,KB(Kilo Byte), MB (Mega
Byte), GB (Giga Byte), TB (Tera Byte).
• 1 Byte=8 Bits
• 1 KB (Kilo Byte)=1024 Byte
• 1 MB (Mega Byte)=1024 KB
• 1 GB (Giga Byte)=1024 MB
• 1 TB (Tera Byte)=1024 GB
12
Programming Language

• Unlike human being, computers do not have a


functional brain. That is why we should give
commands to do something with computers.
• Programming Language: Formal computer
language designed to communicate
instructions to a machine, particularly
a computer.

13
Programming Language

[1]http://rigaux.org/language-study/diagram.html
What is program?

• There are variety of program types according to


purpose of their usage :
• System programs: Every program runs on an
operating system. Operating system provides
resources and environment for other softwares.
• Drivers: Programs that allows communication
between operating system and hardware.
• Applications: Programs that run on an operating
system for meeting users requirements.

15
Who is programmer?

• Programmer, is a person who writes computer


software.
• Programmer should know about platforms that is used
for developing programs.
• Programmers:
• Builder: Determines the necessary technologies
for writing the program.
• Developer: Person that writes programs.
• Analyst: Person who tries to find out error and
report them to coders during development
process.

16
Classification of Programming Languages

• Programming languages can be grouped


according to their levels which is a measure of
proximity for human perception.
• High level languages are close to human
perception whereas low level languages are close
to computer hardware.
• As level of programming language increase,
things get easier for a programmer.
• The higher programming language makes the
jobs easier but reduces the efficiency and
flexibility in general.
17
Classification of Programming Languages

18
Classification of Programming Languages

• Machine Language
– Natural language of a computer
– Consist of strings of numbers (mostly reduced to 1 & 0)
– Machine dependent
• Low Level Language (Assembly Language)
– English-like abbreviations to represent elementary operations.
– Assemblers were developed to convert assembly language
programs to machine language.

19
Classification of Programming Languages

• Machine language programming was simply too


slow and tedious for most programmers.
• Instead using the strings of numbers that
computers directly understand programmers
began using English-like abbreviations to
represent elementary operations.
• These abbreviations formed the basis of assembly
language.
• Assemblers were developed to convert assembly
language programs to machine language.
20
Classification of Programming Languages

• Medium Level Languages


– Close to both human and computer
– Easy like high level languages, flexible like low level languages.
– Generally used for system programming.
– C is a medium level language.
• High Level Languages
– To speed the programming task
– Compilers convert high level language programs into machine language.
– Code similar to everyday English
– Interpreter programs developed to execute high level languages without need
of compiling

21
Classification of Programming Languages

•Very High Level languages allows to write


programs almost visually using some tools.
•Languages such as C# and Visual Basic are used
very often on Windows systems.
•Very high level languages are also called
declarative languages.
•Languages that is used to manage database
systems can be put in this group.

22
Compilers and Interpreters

• Translator programs that convert high level language


programs into machine language are called compilers.
• High level languages allow programmer to write instructions
that look almost like everyday English and contain commonly
used mathematical notations.
• Interpreter programs were developed to execute high-level
language programs without the need for compiling them into
machine language.
• Although compiled programs run faster than interpreted
programs, interpreters are popular in program development
environments.

23
Compilers and Interpreters

• Compilers firstly controls the written code.


• If code has errors, compiler stops process.
• When all errors are removed from code, compiler converts
the code into machine code (exe file)
• Interpreters execute code row by row instead of compiling it
totally.

24
Computers - Review

25
Why programming is important? Review

26
Problem and Problem Solving

• The idea of achieving an automation or


solving a scientific computation using
computers is called a problem.
• It is essential to have a thorough
understanding of the problem and a carefully
planned approach to solving the problem.
• A problem may have more than one solution.
In this case we should find an optimal solution
with computers.

27
Algorithm

• Algorithm: A procedure for solving problem in


terms of
– The action to be executed
– The order in which these actions are to be executed..
– All steps should be decisive. Nothing should be related
with chance.
– Algorithm should end in a finite step.
– Algorithms should handle all possible cases.
• Algorithms are expressed with pseudo codes or
flow charts.

28
Algorithm

29
Pseudo Code

• Pseudo code is an artificial and informal language


that helps developing algorithms.
• Pseudo code is similar to everyday English;
– Convenient
– User friendly
– Not an actual programming language.
• Not executed on computers.
• They help you think out a program before
attempting to write it.
• Only consist of action statements.

30
Pseudo Code

• Basic pseudo code commands

• Start : It indicates that the program has started.


• End : It indicates that the program has finished.
• Read : It is written for user input.
• Print : It is written to show users the information or results.
• If … Else … : It used in the change of flow according to the
conditions.

31
Flow charts

• Flowchart is a graphical representation of an


algorithm or of a portion of an algorithm.
• Flowcharts are drawn using certain special
purpose symbols such as Rectangles,
Diamonds, Ovals, Small circles

Decision
Action Symbol Start/End
Symbol
Connector

32
Control Structures

• Researches have shown that programs could be


written without any go to statement in terms of only
three control structures, namely sequence
structure, the selection structure and repetition
structure.

Control Structures

Sequence Structure Selection Structure Repetition Structure

33
Control Structures

Sequence Structure
• Statements in a program
executed one after the other
in the order in which they are
written
• Unless directed otherwise the toplam = toplam +
Add grade to sum
computer automatically not
executes C statements one
after the other in the order in
which they are written. sayac = sayac + 1
• We use rectangle symbol also Increment counter
called action symbol, to
indicate any type of action
including a calculation or
input/output operation.

34
Control Structures (Sequence Structure)

• Example; if an aircraft wants to throw a missile


to a target, steps should be as follows.
• If steps are not followed in order, process will
fail.
– 1. Get the coordinates of the target
– 2. Get the current coordinate of aircraft
– 3. Perform calculation to hit the target.
– 4. Fire missile.

35
Control Structures

1. Refinement of the first step:

• a. Get coordinates from officer


• b. Be sure that target coordinates are valid.
• c. Store coordinates in memory.

• a. Refinement of sub step "a"


• i. Be sure of coordinates
• ii. Control whether target is the range of missile.
• iii. Control whether target is friend area or not.

36
Algorithm

• Basically, algorithms have three main parts :

• Input: Data that computer will work on is put by a


user.

• Process: Computer processes data.

• Output: Computer shows results in a way that


people can understand.

37
Algorithm

• Input: Final algorithm:


• a. Get product name. 1. Start.
• b. Get amount of product.
2. Get product name.
• c. Read price of product
from a 3. Get amount of product.
file 4. Read price of product from a
• Process: file
• a. Calculate the total price
of the product 5. Calculate the total price of the
• b. Give discount product
6. Give discount
• Output: 7. Print final price
• a. Print final price
8. End
38
Flow chart

39
Pseudo Code

40
Algorithm

41
References

• Doç. Dr. Fahri Vatansever, “Algoritma


Geliştirme ve Programlamaya Giriş”, Seçkin
Yayıncılık, 12. Baskı, 2015
• J. G. Brookshear, “Computer Science: An
Overview 10th Ed.”, Addison Wisley, 2009
• Kaan Aslan, “A’dan Z’ye C Klavuzu 8. Basım”,
Pusula Yayıncılık, 2002
• Paul J. Deitel, “C How to Program”, Harvey
Deitel.

42

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy