Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
4 views

Introduction To Computer Programming

Uploaded by

SINAN ENGINS
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Introduction To Computer Programming

Uploaded by

SINAN ENGINS
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 76

Introduction to Computer Programming

Assoc. Prof. Özgür ZEYDAN


https://ozgurzeydan.com.tr/

1
Computer Programming
 A computer is a programmable machine. This means it can
execute a programmed list of instructions and respond to
new instructions that it is given.
 Computer Programming is the process of developing and
implementing various sets of instructions to enable a
computer to do a certain task.
 Programs are written to solve problems or perform tasks on
a computer.

2
Computer Programming
➢ Programmers translate the
solutions or tasks into a
language the computer can
understand.
➢ As we write programs, we must
keep in mind that the computer
will only do what we instruct it
to do.
➢ Because of this, we must be
very careful and thorough with
our instructions.
3
First Computer Programmer: Ada
Lovelace

Ada Lovelace is the first


person to develop an
algorithm for a machine.

4
Algorithm
➢ An algorithm is a list of
instructions, procedures, or
formulas used to solve a
problem.
➢ The word derives from the
name of the mathematician,
Mohammed ibn-Musa al-
Khwarizmi (El-Harezmî), (780
– 850).

5
Pseudocode
➢ Pseudocode is a computer programming language that
resembles plain English that cannot be compiled or
executed, but explains a resolution to a problem.

6
Source Code
➢ The source code consists of the programming statements
that are created by a programmer with a text editor or a
visual programming tool and then saved in a file.
➢ For example, a programmer using the C language types in
a desired sequence of C language statements using a text
editor and then saves them as a named file.
➢ This file is said to contain the source code.

7
Flowchart
➢ A flowchart is a formalized graphic representation of a logic
sequence, work or manufacturing process, organization
chart, or similar formalized structure.
➢ The purpose of a flow chart is to provide people with a
common language or reference point when dealing with a
project or process.
➢ Flowcharts use simple geometric symbols and arrows to
define relationships.

8
Programming Languages
➢ Computer programming is almost always done by means of
Programming Language.
➢ There exists 8945 programming languages in the world
(https://hopl.info).
➢ Some of them are known by only their developers!

➢ For further information:


http://en.wikipedia.org/wiki/List_of_programming_languages

9
Programming Languages

10
History of Programming Languages

11
12
Programming Language Generations
➢ 1GL or first-generation language was (and still is) machine
language or the level of instructions and data that the
processor is actually given to work on.

➢ 2GL or second-generation language is assembler


(sometimes called "assembly") language.

13
Programming Language Generations
➢ 3GL or third-generation language is a "high-level"
programming language, such as PL/I, C, or Java. A
compiler converts the statements of a specific high-level
programming language into machine language. A 3GL
language requires a considerable amount of programming
knowledge.

➢ 4GL or fourth-generation language is designed to be closer


to natural language than a 3GL language. Languages for
accessing databases are often described as 4GLs.

14
Programming Language Generations
➢ 5GL or fifth-generation language is programming that uses
a visual or graphical development interface to create source
language that is usually compiled with a 3GL or 4GL
language compiler. Microsoft, Borland, IBM, and other
companies make 5GL visual programming products for
developing applications in Java, for example. Visual
programming allows you to easily envision object-oriented
programming class hierarchies and drag icons to assemble
program components.

15
Machine Code (machine language)
➢ Machine code, also known as machine language, is the
elemental language of computers, comprising a long
sequence of binary digital zeros and ones (bits).
➢ Sometimes referred to as machine code or object code,
machine language is a collection of binary digits or bits that
the computer reads and interprets. Machine language is the
only language a computer is capable of understanding.

16
Machine Code

17
Assembly Language
➢ Sometimes referred to as assembly or ASL, assembly
language is a low-level programming language used to
interface with computer hardware.
➢ Assembly language uses structured commands as
substitutions for numbers allowing humans to read the
code easier than looking at binary. Although easier to read
than binary, assembly language is a difficult language and
is usually substituted for a higher language such as C.

18
Low-level Languages
➢ Low-level languages have the advantage that they can be
written to take advantage of any peculiarities in the
architecture of the central processing unit (CPU).
➢ Thus, a program written in a low-level language can be
extremely efficient, making optimum use of both computer
memory and processing time.
➢ However, to write a low-level program takes a substantial
amount of time, as well as a clear understanding of the inner
workings of the processor itself. Therefore, low-level
programming is typically used only for very small programs, or
for segments of code that are highly critical and must run as
efficiently as possible.

19
High-level Languages
➢ High-level languages permit faster development of large
programs. The final program as executed by the computer is
not as efficient, but the savings in programmer time generally
far outweigh the inefficiencies of the finished product.
➢ This is because the cost of writing a program is nearly constant
for each line of code, regardless of the language.
➢ Thus, a high-level language where each line of code translates
to 1-0 machine instructions costs only one tenth as much in
program development as a low-level language where each line
of code represents only a single machine instruction.

20
First High-Level Language

21
Programming Language Popularities

https://www.tiobe.com/tiobe-index/ 22
Compiler
➢ A compiler is a special program that processes statements
written in a particular programming language and turns
them into machine language or "code" that a computer's
processor uses.

➢ After you write a program, your source language


statements are compiled into machine code that is stored
as an executable file.

➢ Scripting languages like Perl and PHP do not need to be


compiled.
23
Compiler

http://www.learncpp.com/cpp-tutorial/02-introduction-to-programming-languages/

24
Structured Programming (modular programming)
➢ Structured programming (sometimes known as modular programming) is a
subset of procedural programming that enforces a logical structure on the
program being written to make it more efficient and easier to understand and
modify. Certain languages such as Ada, Pascal, and dBASE are designed with
features that encourage or enforce a logical program structure.
➢ Structured programming frequently employs a top-down design model, in which
developers map out the overall program structure into separate subsections.
➢ Program flow follows a simple hierarchical model that employs looping
constructs such as "for“, "repeat“, and "while" Use of the "Go To" statement is
discouraged.
➢ Structured programming was first suggested by Corrado Bohm and Guiseppe
Jacopini. The two mathematicians demonstrated that any computer program
can be written with just three structures: decisions, sequences, and loops.

25
Object-Oriented Programming (OOP)
➢ Object-oriented programming (OOP) is a programming
language model organized around "objects" rather than
"actions" and data rather than logic.
➢ Historically, a program has been viewed as a logical
procedure that takes input data, processes it, and produces
output data.

26
Classification of Programming Languages

➢ Procedure-oriented programming
➢ COBOL, FORTRAN, Pascal and C

➢ Object oriented programming


➢ Objective C, C++, Java, and PHP

27
Integrated Development Environment (IDE)
An IDE or Integrated Development Environment is a software
program that is designed to help programmers and
developers build software.
Most IDEs include:
➢a source code editor

➢a compiler

➢build automation tools

➢a debugger

28
Debugger
➢ A special program used to find errors (bugs) in other
programs. A debugger allows a programmer to stop a
program at any point and examine and change the values
of variables.

➢ https://www.webopedia.com/definitions/debugger/

29
Graphical User Interface (GUI)
➢ A GUI is a graphical (rather
than purely textual) user
interface to a computer.
➢ Elements of a GUI include
textboxes, buttons, pulldown
menues, list and combo boxes

30
DEV C++ IDE

31
DEV C++ IDE download page

http://dev-cpp.com
32
Visual Studio Community

https://visualstudio.microsoft.com/tr/free-developer-offers/
33
Software Development Languages
➢ C
➢ C++ (C-plus-plus)
➢ C# (C-Sharp)
➢ Python

34
Web Languages
➢ HTML (Hyper Text Markup Language)
➢ XML (Extensible Markup Language)
➢ Javascript
➢ VBScript
➢ PHP (Hypertext Preprocessor)
➢ Java
➢ ASP (Active Server Pages)

35
Important People in Computer Programming

36
Important People in Computer Programming

37
Algorithms
Pseudocode
Flowcharts
Assoc. Prof. Özgür ZEYDAN
https://ozgurzeydan.com.tr/

38
Why do we have to learn computer programming?
➢ Computers can make calculations at a blazing speed
without any error as compared to the humans.
➢ Example: calculate the prime numbers until 121.
➢ How long does it take?
➢ Do you do any error?
➢ Prime numbers: 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37,
41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103,
109, 113
➢ Such a problem is so easy for a computer…
39
Calculate the prime numbers until 121

http://en.wikipedia.org/wiki/File:Sieve_of_Eratosthenes_animation.gif
40
Performing a Task on The Computer
➢ The first step in writing instructions to carry out a task is to
determine what the output should be—that is, exactly what
the task should produce.
➢ The second step is to identify the data, or input, necessary
to obtain the output.
➢ The last step is to determine how to process the input to
obtain the desired output, that is, to determine what
formulas or ways of doing things can be used to obtain the
output.
41
A pictorial representation of problem-solving

42
Program Development Cycle
1. Analyze: Define the problem.
◼ Be sure you understand what the program should do, that is,
what the output should be. Have a clear idea of what data (or
input) are given and the relationship between the input and the
desired output.
2.Design: Plan the solution to the problem.
◼ Find a logical sequence of precise steps that solve the problem.
Such a sequence of steps is called an algorithm. Every detail,
including obvious steps, should appear in the algorithm.

43
Program Development Cycle
3. Choose the interface: Select the objects.
◼ Determine how the input will be obtained and how the output will be
displayed. Then create appropriate commands to allow the user to
control the program.
4. Code: Translate the algorithm into a programming language.
◼ Coding is the technical word for writing the program.
5. Test and debug: Locate and remove any errors in the program.
◼ Testing is the process of finding errors in a program, and
debugging is the process of correcting errors that are found. (An error
in a program is called a bug.)

44
Program Development Cycle
6. Complete the documentation: Organize all the material
that describes the program.
◼ Documentation is intended to allow another person, or the
programmer at a later date, to understand the program.
Internal documentation consists of statements in the program
that are not executed, but point out the purposes of various
parts of the program.
◼ Documentation might also consist of a detailed description of
what the program does and how to use the program (for
instance, what type of input is expected).
◼ For commercial programs, documentation includes an
instruction manual.
◼ Other types of documentation are the flowchart and pseudocode.

45
46
47
Programming Tools
➢ Tools used to convert algorithms into computer programs:
◼ Pseudocode: An informal high-level description of the operating
principle of a computer program. It uses the structural
conventions of a programming language, but is intended for
human reading rather than machine reading.
◼ Flowcharts: Graphically depict the logical steps to carry out a
task and show how the steps relate to each other.

48
Pseudocode vs Flowcharts
➢ Artificial and Informal language ➢ A graphical way of writing
➢ Helps programmers to plan an pseudocode
algorithm ➢ Rounded rectangle – terminal
➢ Similar to everyday English ➢ Parallelogram – input / output
➢ Not an actual programming ➢ Rectangle – actions
language ➢ Diamonds – decision /
conditional
➢ Circles – connector

49
Flowchart Symbols

50
Example Pseudocode
Start Start - Terminal
Read A, B Read A, B – Input
Calculate C = A*B Calculate C = A*B - Action
Display C Display C - Output
Stop Stop - Terminal

51
Example Flowchart

Start Terminal.
Start Program start
here

Read A Input.
Read B Enter values for
A and B

Calculate Resut
C=A*B Process

Display the
Result C Output

Stop Terminal
Stop Program end
here
52
User Friendly Pseudocode
Start
Use variables A,B and C
Display “write two numbers”
Read A, B
Calculate C = A*B
Display “multiplication of numbers” , C
Stop

53
Question ???

54
Structured Programming
➢ Structured programming was first suggested by Corrado Bohm
and Guiseppe Jacopini. The two mathematicians demonstrated
that any computer program can be written with just three
structures: sequences, decisions, and loops.
➢ Sequences: one command is executed after previous one.
➢ Decisions (selections): statement(s) is (are) executed if certain
condition gives TREU or FALSE value.
➢ Loops (repetition): statement(s) is (are) executed repeatedly
until certain condition gives TREU or FALSE value.

➢ Corrado; B. and Jacopini, G. (May 1966). "Flow Diagrams,


Turing Machines and Languages with Only Two Formation
Rules". Communications of the ACM 9 (5): 366–371.

55
Sequences

Ref: Deitel P J (Ed.) (2010) C How


to Program, 6th Edition, Prentice
Hall

56
Decisions (selections)
➢ Three selection structure in C
programming:
◼ If
◼ If – else
◼ Switch

Ref: Deitel P J (Ed.) (2010) C How


to Program, 6th Edition, Prentice
Hall

57
Decisions
(selections)

Ref: Deitel P J (Ed.) (2010) C How


to Program, 6th Edition, Prentice
Hall
58
Loops (repetition)
➢ Three repetition structure
in C programming:
◼ While
◼ Do – while
◼ For

Ref: Deitel P J (Ed.) (2010) C How


to Program, 6th Edition, Prentice
Hall
59
Loops (repetition)

Ref: Deitel P J (Ed.) (2010) C How to Program, 6th Edition, Prentice Hall
60
Pseudocode and Flowchart for a Decision Structure

61
Example - 2
➢ Write an algorithm to determine a student’s average grade
and indicate whether he is successful or not.
➢ The average grade is calculated as the average of mid-term
and final marks.
➢ Student will be successful if his average grade is grater or
equals to 60.

62
Pseudocode
➢ Start
➢ Use variables mid term , final and average
➢ Input mid term and final
➢ Calculate the average by summing mid term and final
and dividing by 2
➢ if average is below 60
Print “FAIL”
else
Print “SUCCESS”
➢ Stop

63
Detailed Algorithm
➢ 1. Step: Input mid-term and final
➢ 2. Step: average = (mid-term + final)/2
➢ 3. Step: if (average < 60) then
Print “FAIL”
else
Print “SUCCESS”
endif

64
Flowchart
START

Input
mid-term, final

average = (mid-term + final)/2

N Y
If
average<60

PRINT PRINT
“SUCCESS” “FAIL”

STOP

65
Nested If
➢ Simply, if structure in if structure
➢ Example - 3: Both final and average grades must be grater than
or equals to 35 for curve calculation in BEU.
➢ if (final >= 35) then
{ if (average >= 35) then
execute curve calculation commands
endif }
else
Print “FF grade”
endif

66
Pseudocode and Flowchart for a Loop

67
Example - 4
➢ Write an algorithm which calculates the average exam
grade for a class of 5 students.
➢ What are the program inputs?
◼ the exam grades
➢ Processing:
◼ Find the sum of the grades;
◼ count the number of students; (counter controlled)
◼ calculate average grade = sum of grades / number of
students.
➢ What is the program output?
◼ the average exam grade

68
Pseudocode
➢ Start
➢ Use variables total, counter, grade, average
➢ Initialize total = 0
➢ Initialize counter = 1
➢ While (counter <= 5)
➢ Input grade
➢ Calculate total = total + grade
➢ Calculate counter = counter + 1
➢ End-while
➢ Calculate average = total / 5
➢ Display average
➢ Stop

69
Flowchart

70
Example - 5
➢ Write an algorithm which calculates the average exam
grade for a class of unknown number of students.
➢ What are the program inputs?
◼ the exam grades
➢ Processing:
◼ Find the sum of the grades till sentinel value is given; for
example -99 to break loop (sentinel controlled)
◼ calculate average grade = sum of grades / number of
students.
➢ What is the program output?
◼ the average exam grade

71
Pseudocode
➢ Start
➢ Use variables total, counter, grade, average
➢ Initialize total = 0
➢ Initialize counter = 0
➢ While (grade != -99)
➢ Input grade
➢ Calculate total = total + grade
➢ Calculate counter = counter + 1
➢ End-while
➢ Calculate average = total / counter
➢ Display average
➢ Stop

72
Example - 6
➢ Write an algorithm which calculates the average
exam grade for a class of unknown number of
students.
➢ This time, the number of students have been asked
at the beginning of the program.
➢ Use counter controlled structure.

73
Pseudocode
➢ Start
➢ Use variables total, counter, grade, average, number_of_students
➢ Initialize total = 0 , number_of_students = 0 , counter = 1
➢ Display “write number of students”
➢ Input number_of_students
➢ While (counter <= number_of_students)
➢ Input grade
➢ Calculate total = total + grade
➢ Calculate counter = counter + 1
➢ End-while
➢ Calculate average = total / number_of_students
➢ Display average
➢ Stop

74
Question
➢ Draw a flowchart for example – 6.

75
Fatal Error – Memorizing
➢ Do not memorize any of
the codes in programming.
➢ Read and try to understand
what is given and what is
asked in the question, then
write your own codes.

76

You might also like