Lecture 01 & 02 Computer Programming

Similar documents
SKILL AREA 304: Review Programming Language Concept. Computer Programming (YPG)

Lecture 03 & 04 Computer Programming

Game keystrokes or Calculates how fast and moves a cartoon Joystick movements how far to move a cartoon figure on screen figure on screen

BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1

C++ Programming Language Lecture 2 Problem Analysis and Solution Representation

Outline. Program development cycle. Algorithms development and representation. Examples.

CS187 - Science Gateway Seminar for CS and Math

INFS 214: Introduction to Computing

Programming Languages and Program Development Life Cycle Fall Introduction to Information and Communication Technologies CSD 102

Algorithms and Programming Languages

Introduction to Programming: Variables and Objects. HORT Lecture 7 Instructor: Kranthi Varala

Outline. Introduction to Programming (in C++) Introduction. First program in C++ Programming examples

Software Development. Integrated Software Environment

Objective: To learn meaning and concepts of programming. Outcome: By the end of this students should be able to describe the meaning of programming

Principles of Programming Languages. Lecture Outline

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2014 Euiseong Seo

Introduction to Problem Solving and Programming in Python.

CS354 gdb Tutorial Written by Chris Feilbach

Computer Components. Software{ User Programs. Operating System. Hardware

An Introduction to Python (TEJ3M & TEJ4M)

CS2900 Introductory Programming with Python and C++ Kevin Squire LtCol Joel Young Fall 2007

A Set Of Machine Language Instructions For A Program Is Called Source Code >>>CLICK HERE<<<

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

Chapter 1: Why Program? Computers and Programming. Why Program?

COMP108 Algorithmic Foundations

Computer Organization & Assembly Language Programming

Act like a code monkey Coding Basics

CS101 Introduction to Programming Languages and Compilers

CSE 374 Programming Concepts & Tools. Hal Perkins Fall 2015 Lecture 15 Testing

Programming Languages

Programming Languages

ALICE: An introduction to progamming

Chapter Twelve. Systems Design and Development

Low-Level Languages. Computer Programs and Programming Languages

Software. Software. Software. Program Language. Programs written for the ENIAC

LESSON 13: LANGUAGE TRANSLATION

AP Computer Science A: Java Programming

(0) introduction to the course. how to learn a programming language. (0) course structure

Program Abstractions, Language Paradigms. CS152. Chris Pollett. Aug. 27, 2008.

Compilers. Prerequisites

PLAGIARISM. Administrivia. Course home page: Introduction to Programming Languages and Compilers

Introduction to Programming Languages and Compilers. CS164 11:00-12:00 MWF 306 Soda

COMP 201: Principles of Programming

CSI32 Object-Oriented Programming

Chapter 2 Basic Elements of C++

Chapter 1. Preliminaries

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

Introduction Objectives: 1) differentiate between high-level, low-level, and machine language; 2) explain why it is necessary to translate a program

Contemporary Multilevel Machines

Exercises: Instructions and Advice

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

LECTURE 1. Overview and History

LECTURE 3. Compiler Phases

Programming Languages FILS Andrei Vasilateanu

Unit E Step-by-Step: Programming with Python

CSCI 3136 Principles of Programming Languages

Programming Fundamentals

S/W Programming & Languages

CS102 Unit 2. Sets and Mathematical Formalism Programming Languages and Simple Program Execution

C++ Programming Language Lecture 1 Introduction

1) What is the first step of the system development life cycle (SDLC)? A) Design B) Analysis C) Problem and Opportunity Identification D) Development

Chapter - 2 The Basics of Programming. Practical C++ Programming Copyright 2003 O'Reilly and Associates Page1

Discovering Computers Chapter 13 Programming Languages and Program Development

Overview. - General Data Types - Categories of Words. - Define Before Use. - The Three S s. - End of Statement - My First Program

Python for Analytics. Python Fundamentals RSI Chapters 1 and 2

Pioneering Compiler Design

Java Programming. Zheng-Liang Lu. Java 301 Summer Department of Computer Science & Information Engineering National Taiwan University

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

Lecture 03 Bits, Bytes and Data Types

Introduction. Arizona State University 1

Question No: 1 ( Marks: 1 ) - Please choose one One difference LISP and PROLOG is. AI Puzzle Game All f the given

LECTURE 5 Control Structures Part 2

CS240: Programming in C

General Concepts. Abstraction Computational Paradigms Implementation Application Domains Influence on Success Influences on Design

Java Programming. Zheng-Liang Lu. Java 308 Spring Department of Computer Science & Information Engineering National Taiwan University

Programming. leads to programming languages. leads to operating systems

COMP163. Introduction to Computer Programming. Introduction and Overview of the Hardware

Why do you need to know about programming? Programming is used to create the application / software you use everyday

Introduction to Programming

Computer Components. Software{ User Programs. Operating System. Hardware

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION

Unit 3. Operators. School of Science and Technology INTRODUCTION

Copyright 2005 Department of Computer & Information Science

Chapter 9: Dealing with Errors

COMP 122/L Lecture 1. Kyle Dewey

Principles in Programming: Orientation & Lecture 1. SWE2004: Principles in Programming Spring 2015 Euiseong Seo

Chapter 1: Introduction to Computers and Programming

PROBLEM SOLVING AND PYTHON PROGRAMMING

Text Input and Conditionals

Software. Programming Languages. Types of Software. Types of Languages. Types of Programming. Software does something

Introduction to Computer Programming Using FORTRAN 77

CMSC201 Computer Science I for Majors

Computer Programming-I. Developed by: Strawberry

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

AP Computer Science A

LANGUAGE TRANSLATORS. Workbook. etghallem. St. Aloysius College Computing

Lecture 1: Course Introduction

Lecture Programming in C++ PART 1. By Assistant Professor Dr. Ali Kattan

Computing and compilers

Discovering Computers 2008

Transcription:

Lecture 01 & 02 Computer Programming 15 Computer Systems Engineering Second Semester By: Mr. Ali Asghar Manjotho, Lecturer, CSE-MUET

Contents Computer programming (LL 02) Why programming? (LL 02) Instructions and Program (LL 02) Low level, High level and Middle level programming languages (LL 02) Source Code and Object Code (LL 02) Language Translators (LL 02) Compiler (LL 02) Interpreter (LL 02) Assembler (LL 02) Why language translators? (LL 02) Ali Asghar Manjotho, Lecturer CSE-MUET 2

Contents Difference between compiler and interpreter (LL 04) Bug and Debugging (LL 02) LL 02 = Learning Level 02 Understanding, LL 04 = Learning Level 04 Analysis Ali Asghar Manjotho, Lecturer CSE-MUET 3

Computer Programming Ali Asghar Manjotho, Lecturer CSE-MUET 4

Computer Programming It is the process of giving instructions (commands) to the computer to do a meaningful task. It is an act of teaching the computer on how to do a task. The art and science of creating instructions for a computer to follow. Creating a sequence of instructions to enable the computer to do something. Ali Asghar Manjotho, Lecturer CSE-MUET 5

Why Programming? Ali Asghar Manjotho, Lecturer CSE-MUET 6

Why Programming? Computer is just a dumb machine made up of different electronic components. It is like a box which cannot do anything by itself. It is the user who tells the computer what it has to do? If we need our computer to perform some task, we first have to teach the computer in detail how it will accomplish that task? Once the computer is taught about a particular task, it will completely obey it but cannot do anything that it is not taught to. Ali Asghar Manjotho, Lecturer CSE-MUET 7

Why Programming? Like the humans, we can teach the computer through communicating with it using a particular language. The language that computer understands is machine language, also called as binary language. Machine language is the language of 0s and 1s. We give detailed instructions to the computer to solve a particular task. Programming is the term that refers to teaching, instructing or giving commands to the computer. Ali Asghar Manjotho, Lecturer CSE-MUET 8

Why Programming? Programming is more about problem solving skills than writing the code itself. Programming teaches you how to understand, analyze and solve the problems. It enhances your analytical reasoning abilities and helps you cope with daily real life problems as well. Hence learning to program is important because it develops analytical and problem solving abilities. Ali Asghar Manjotho, Lecturer CSE-MUET 9

Programmer The person who gives the instructions (commands) to the computer is known as the programmer. A person who designs and writes computer programs. Ali Asghar Manjotho, Lecturer CSE-MUET 10

Instruction DO THIS! Ali Asghar Manjotho, Lecturer CSE-MUET 11

Instruction Instruction is any command given to the computer. For example: 1) Add two variables A and B 2) Display result 3) Read file Each of these is the individual instruction to the computer. Ali Asghar Manjotho, Lecturer CSE-MUET 12

Program NOW DO THIS! NOW DO THIS! NOW DO THIS! NOW DO THIS! NOW DO THIS! Ali Asghar Manjotho, Lecturer CSE-MUET 13

Program Program is a set (collection) of instruction to do a meaningful task. A sequence of instructions that are interpreted and executed by a computer. It can be made of a single or hundred of instructions. For example: In order to teach the computer on how to calculate average of three numbers? We need to give multiple instructions to the computer to do the task. Ali Asghar Manjotho, Lecturer CSE-MUET 14

Program Instruction 1: Get first number from the user and store it in A variable Instruction 2: Get second number from the user and store it in B variable Instruction 3: Get third number from the user and store it in C variable Instruction 4: Add A, B, C and store the result in SUM variable Instruction 5: Divide SUM by 3 and store result in AVG variable Instruction 6: Display AVG variable Instructions 1-6 are used to solve a single task. This collection of instruction is known as a program. Ali Asghar Manjotho, Lecturer CSE-MUET 15

Programming Language Ali Asghar Manjotho, Lecturer CSE-MUET 16

Programming Language A programming language is an artificial language designed to communicate instructions to a computer. A programming language is a notation for writing programs. A vocabulary and set of grammatical rules for instructing a computer to perform specific tasks. Ali Asghar Manjotho, Lecturer CSE-MUET 17

Programming Language Each language has a unique set of keywords (special words that it understands) and a special syntax (format) for organizing program instructions. There are many programming languages. For example: GW Basic C C++ JAVA Pascal COBOL Python C# Ali Asghar Manjotho, Lecturer CSE-MUET 18

Types of Programming Languages There are three types of programming languages: Ali Asghar Manjotho, Lecturer CSE-MUET 19

Low-Level Language Machine (Computer) Human (Programmer) LANGUAGE A language which is closer to machine (computer) Ali Asghar Manjotho, Lecturer CSE-MUET 20

Low-Level Language A low level language is one which is closer to the machine (computer). It is easier for machines to understand and difficult for humans to understand. It is faster in execution as compared to high and middle level languages. Ali Asghar Manjotho, Lecturer CSE-MUET 21

Low-Level Language Two of the types of low level languages are: Ali Asghar Manjotho, Lecturer CSE-MUET 22

It is one of the low level language. Machine Language It is the language of 0s and 1s. Machine languages are the only languages directly understood by the computers. While easily understood by computers, machine languages are almost impossible for humans to use because they consist entirely of numbers (0s and 1s). Ali Asghar Manjotho, Lecturer CSE-MUET 23

Machine Language It is the native language of the machines (computers). Here all the instructions are written as code of binary sequence. For example: In order to do addition, the code is: 10010001 In order to decrement a number by one, the code is: 11011011 In order to move data from one place to another, the code is: 10000111 Ali Asghar Manjotho, Lecturer CSE-MUET 24

Machine Language There are hundreds of instructions and each instruction has a binary code. Is it possible to remember all the codes of hundreds of instruction? Obviously not! Hence machine language almost impossible to understand. Ali Asghar Manjotho, Lecturer CSE-MUET 25

Machine Language Machine language program example: 10010010 11001010 01001010 11110101 00000101 00101000 11101010 10101010 Ali Asghar Manjotho, Lecturer CSE-MUET 26

Assembly Language Assembly language is same as machine language but uses English like words to represent individual operations. For example: Instead of binary codes it uses : ADD, MOV, SUB, INC Assembly language is also a low-level language. It is easier than the machine language but still it is very difficult to control a larger program using assembly. Ali Asghar Manjotho, Lecturer CSE-MUET 27

Assembly Language As assembly language contains English like words, which will not be understood by the computer (because it only understands 0s and 1s) A translator first converts the assembly language program into machine language program. Translator used with assembly language is called Assembler. Ali Asghar Manjotho, Lecturer CSE-MUET 28

Assembly Language Assembly language program example: MVI A, 05h MVI B, 9Ah ADD B INC A STA 8200h HLT Ali Asghar Manjotho, Lecturer CSE-MUET 29

High-Level Language Machine (Computer) Human (Programmer) LANGUAGE A language which is closer to human (programmer) Ali Asghar Manjotho, Lecturer CSE-MUET 30

High-Level Language A high level language is one which is closer to the human (programmer). It is easier for humans to understand and difficult for machines to understand. It is slower in execution as compared to low level languages. Ali Asghar Manjotho, Lecturer CSE-MUET 31

High-Level Language Like assembly language, it also uses English like words for the operations. For example: for, if, else, break, continue, while, include, using, import It is more easier than assembly language. Ali Asghar Manjotho, Lecturer CSE-MUET 32

High-Level Language Some of the high level programming languages are: GW Basic C++ JAVA Pascal COBOL Python C# Visual Basic J# Ruby PHP Ali Asghar Manjotho, Lecturer CSE-MUET 33

High-Level Language High level language program example: int main() { int a = 5; int b = 6; } if(a > b) cout<< First number is greater. ; else cout<< Second number is greater. ; Ali Asghar Manjotho, Lecturer CSE-MUET 34

Middle-Level Language Machine (Computer) Human (Programmer) LANGUAGE A language which is some how closer to machine as well as human Ali Asghar Manjotho, Lecturer CSE-MUET 35

Middle-Level Language A middle level language is one which is closer to machine (computer) as well as to human (programmer). A language that has the features of both low level and high level languages. More formally, a high level language that allows you to write low level programs in it is called as middle level language. Ali Asghar Manjotho, Lecturer CSE-MUET 36

Middle-Level Language Some of the middle level programming languages are: C IBM PL/S (Programming Language/Systems) BCPL (Basic Combined Programming Language) BLISS (Bill's Language for Implementing System Software) Ali Asghar Manjotho, Lecturer CSE-MUET 37

Source Code and Object Code Source Code The set of instructions written in any language other than machine language is called as source code. Object Code The set of instructions written in machine language is called as object code. It is also known as machine code. It is not directly understood by the machine (computer). It is the only code which is directly understood by the machine (computer). Ali Asghar Manjotho, Lecturer CSE-MUET 38

Source Code and Object Code Source Code It is in the form of text. Object Code It is in the form of binary numbers. It is human readable. It is machine (computer) readable. It is generated by human (programmer). It is generated by the language translator. It is input to the language translator. It is the output of the language translator. Ali Asghar Manjotho, Lecturer CSE-MUET 39

Language Translators Ali Asghar Manjotho, Lecturer CSE-MUET 40

Language Translators Language translator is a program that converts the source code in to the object code. Source Code Translator CONVERT Object Code Language Translator Ali Asghar Manjotho, Lecturer CSE-MUET 41

Why Language Translators? Computer only understands object code (machine code). It does not understand any source code. There must be a program that converts source code in to the object code so that the computer can understand it. The language translator is one which does this job. The programmer writes the source code and then translator converts it in machine readable format (object code). Ali Asghar Manjotho, Lecturer CSE-MUET 42

Types of Language Translators There are three types of language translator: Ali Asghar Manjotho, Lecturer CSE-MUET 43

Assembler Assembler is the language translator that converts assembly language code in to the object code (machine code). Assembly Source Code Assembler CONVERT Object Code Ali Asghar Manjotho, Lecturer CSE-MUET 44

Compiler Compiler is the language translator that converts high level language code in to the object code (machine code). It converts the whole code at a time. High-Level Source Code Compiler CONVERT Object Code Ali Asghar Manjotho, Lecturer CSE-MUET 45

Compiler Program Read whole Program Line 1 : Instruction 1 Line 2 : Instruction 2 Line 3 : Instruction 3 Line 4 : Instruction 4 Line 5 : Instruction 5 Line 1 : Instruction 1 Line 2 : Instruction 2 Line 3 : Instruction 3 Line 4 : Instruction 4 Line 5 : Instruction 5 Convert whole program in to object code Execute 1 2 3 4 Ali Asghar Manjotho, Lecturer CSE-MUET 46

Interpreter Interpreter is the language translator that converts high level language code in to the object code (machine code). It converts the code line by line. High-Level Source Code Interpreter CONVERT Object Code Ali Asghar Manjotho, Lecturer CSE-MUET 47

Interpreter Program Line 1 : Instruction 1 Line 2 : Instruction 2 Line 3 : Instruction 3 Line 4 : Instruction 4 Line 5 : Instruction 5 Read Line 1 Convert in to object code Execute Read Line 2 Convert in to object code Execute Read Line 3 Convert in to object code Execute Read Line 4 Convert in to object code Execute Read Line 5 Convert in to object code Execute 2 3 4 5 6 1 Ali Asghar Manjotho, Lecturer CSE-MUET 48

Difference between Compiler and Interpreter Compiler It converts whole code at a time. It is faster. Requires more memory. Errors are displayed after entire program is checked. Example: C, C++, JAVA. Interpreter It converts the code line by line. It is slower. Requires less memory. Errors are displayed for every instruction interpreted (if any). Example: GW BASIC, Ruby, Python Ali Asghar Manjotho, Lecturer CSE-MUET 49

Bug Ali Asghar Manjotho, Lecturer CSE-MUET 50

Bug An error or defect occurred inside a computer program or hardware that causes it to produce an incorrect or unexpected result, or to behave in unintended ways is called as a bug. Most of the bugs arise from mistakes and errors made by programmer in source code. Ali Asghar Manjotho, Lecturer CSE-MUET 51

Bug The term bug was used by Grace Hopper in 1946. Hopper used to work on Mark II computer, there some error occurred in the system. The cause of the error was a moth (bug) trapped in a relay creating short circuit. That caused the term bug to be coined. Ali Asghar Manjotho, Lecturer CSE-MUET 52

Debugging Ali Asghar Manjotho, Lecturer CSE-MUET 53

Debugging It is the process of finding and fixing the bugs (errors) in the program. It is the process of removing errors. The programmer manually does this by examining the source code. Ali Asghar Manjotho, Lecturer CSE-MUET 54