Computer Programming-I. Developed by: Strawberry

Similar documents
CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar

Programs are: CMPSCI 105/119/120: Programming, Flowchar<ng, and Running Program Flowcharts

Macro Assembler. Defini3on from h6p://

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILERS

FLOWCHARTS A flowchart is a graphical representation of the steps to be followed for solving problem. It consists of a set of symbols.

Computer Software: Introduction

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

CS101: Fundamentals of Computer Programming. Dr. Tejada www-bcf.usc.edu/~stejada Week 1 Basic Elements of C++

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

Chapter 1: An Overview of Computers and Logic

Unit. Programming Fundamentals. School of Science and Technology INTRODUCTION

Unit II. (i) Computer Programming Languages

FLOW CHART AND PSEUDO CODE

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Computers Programming Course 6. Iulian Năstac

Module 1: Introduction to Computers, Programs, and Java

Computer Fundamentals: Pradeep K. Sinha & Priti Sinha

COMPILER DESIGN LECTURE NOTES

INTRODUCTION TO ALGORITHMS

UNIT V: CENTRAL PROCESSING UNIT

Low-Level Languages. Computer Programs and Programming Languages

A Beginner s Guide to Programming Logic, Introductory. Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

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

C++ Programming Language Lecture 1 Introduction

Algorithms Lecture 11. UC Davis, ECS20, Winter Discrete Mathematics for Computer Science

Lecture 01 & 02 Computer Programming

Programming Logic and Design Seventh Edition Chapter 2 Elements of High-Quality Programs

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

Programming Languages and Program Development

Related Course Objec6ves

PROGRAM DESIGN TOOLS. Algorithms, Flow Charts, Pseudo codes and Decision Tables. Designed by Parul Khurana, LIECA.

Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

INFS 214: Introduction to Computing

Master of Computer Applications COMPUTER PROGRAMMING USING C

Algorithm: 1. Introduction

Numerical Methods in Scientific Computation

Chapter Twelve. Systems Design and Development

What were his cri+cisms? Classical Methodologies:

BBM 101 Introduc/on to Programming I Fall 2014, Lecture 3. Aykut Erdem, Erkut Erdem, Fuat Akal

CSSE232 Computer Architecture. Logic and Decision Opera:ons

Discovering Computers 2008

CS111: PROGRAMMING LANGUAGE1. Lecture 2: Algorithmic Problem Solving

Compiler Optimization Intermediate Representation

Detailed Contents. 1. Introduction to Computers Input and Output Devices 14

Algorithms and Flowcharts

Computer Architecture. CSE 1019Y Week 16. Introduc>on to MARIE

SNS COLLEGE OF ENGINEERING,

Introduction to Programming

ENT 189: COMPUTER PROGRAMMING. H/P: Home page:

W1005 Intro to CS and Programming in MATLAB. Brief History of Compu?ng. Fall 2014 Instructor: Ilia Vovsha. hip://

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Compilers. Prerequisites

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

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

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

Sequen&al Consistency and Linearizability

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

Introduction to Computer Programming Using FORTRAN 77

Stating the obvious, people and computers do not speak the same language.

CSSE232 Computer Architecture I. Datapath

Computer is an electronic machine that can receive, store, transform and output data of all kinds (image, text, numeric, graphics and sound).

Introduc4on to Algorithms

CISC327 - So*ware Quality Assurance

Main Memory Organization

CS 61C: Great Ideas in Computer Architecture Introduc=on to C, Part I. We are here!

COSC 111: Computer Programming I. Dr. Bowen Hui University of Bri>sh Columbia Okanagan


C Programming Primer 8/31/15 1

Objec0ves. Gain understanding of what IDA Pro is and what it can do. Expose students to the tool GUI

Copyright 2005 Department of Computer & Information Science

PROGRAMMING Programming is a creation of a set of commands or instructions which directs a computer in carrying out a task.

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

0 Introduction: Computer systems and program development

7. Mechanical & Electrical calculator:-

L6: System design: behavior models

Python - Week 1. Mohammad Shokoohi-Yekta

IT2Rail Interoperability Framework

Variable A variable is a value that can change during the execution of a program.

SOFTWARE ANALYSIS & DESIGN TOOLS

Informatica 3 Syntax and Semantics

PROBLEM SOLVING AND OFFICE AUTOMATION. A Program consists of a series of instruction that a computer processes to perform the required operation.

Another Simple Program: Adding Two Integers

depicts pictorially schematic representation of an algorithm document algorithms. used in designing or documenting

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

MACRO NOTES DOCUMENTATION

Introducing Computer Programming

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

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

A flow chart is a graphical or symbolic representation of a process.

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

Agenda. Address vs. Value Consider memory to be a single huge array. Review. Pointer Syntax. Pointers 9/9/12

Agenda. General Organiza/on and architecture Structural/func/onal view of a computer Evolu/on/brief history of computer.

Advanced Topics in MNIT. Lecture 1 (27 Aug 2015) CADSL

CS 465 Final Review. Fall 2017 Prof. Daniel Menasce

Writing a Fraction Class

Instructor: Randy H. Katz hap://inst.eecs.berkeley.edu/~cs61c/fa13. Fall Lecture #7. Warehouse Scale Computer

1. In COMAL language programs, parameters after name of procedure must be put in A. brackets B. back-slash C. insecure data D.

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

Programming Fundamentals (CS 302 ) Dr. Ihsan Ullah. Lecturer Department of Computer Science & IT University of Balochistan

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Transcription:

Computer Programming-I

Objec=ve of CP-I The course will enable the students to understand the basic concepts of structured programming.

What is programming? Wri=ng a set of instruc=ons that computer use to perform specific opera=ons.

What is programming language? Set of instructions are written in a programming language. Need for programming language to communicate instructions to machine (computer).

What is Programming? Art of solving computational problems by computer. Computer is an electronic device and does not understand natural language. Set of symbols, characters, grammar rules that permit people to construct instructions in the format that can be interpreted by the computer system.

Language Types Types of Programming Languages Programming Languages Low-level Language High-level Language Machine Language Assembly Language Procedural Language Fourth Generation Languages(4GLs) Visual Programming Languages

Language Genera=ons On the basis of development, programming languages can be divided into 5 genera=ons : First Machine Language Generation Language (1940 1950) Second Assembly Language Generation Language (1950 1958) Third Procedural Languages Generation Language (1958 1985) Fourth 4GLs Generation Language (1985 onwards) Fifth Visual/Graphic Languages Generation Language (1990 onwards)

Machine Level Language (1940-50) Language containing binary code (1,0) which the computer can understand. Instruc=on contains two parts: Opera=on Part Specifies what is to be performed. Address Part Specifies the loca=on of data to be manipulated.

Advantages-Machine Language Directly executable. Most efficient use of computer system resources like storage, register, etc. Can be used to manipulate individual bits.

Disadvantages-Machine Language Not portable as device dependent. More error prone and difficult to debug. Storage locations have to be addressed directly, and not symbolically. Increases programmer training cost as requires a high level of programming skills. Requires knowledge of the computer s intricate details.

Assembly Language (1950-58) Substitute alphabetic symbols for the binary codes of machine language. Symbols memory locations. Mnemonics operation code. One-to-one correspondence between assembly & machine language. Requires an assembler to convert assembly language into machine language. MVI B, 06 //Load Register B with the Hex value 06 MOV A, B MVI C, 07 //Load the Register C with the second number 07 ADD C STA 8200 //Store the output at a memory loca=on e.g. 8200 HLT //Stop the program execu=on //Move the value in B to the Accumulator or register A //Add the content of the Accumulator to the Register C

Advantages-Assembly Language Because symbols are meaningful, it is easier to read and understand. Relieves users of the problems in allocating computer storage. Encourages modular programming. Used only when efficiency is the must or when there is a need to manipulate processor registers, signals, etc.

Disadvantages-Assembly Language Machine-dependent and hence not portable. Knowledge of details of logical structure of the computer. Writing is difficult & time-consuming. Requires rigorous training. Not directly executable, require Assembler. One-to-one correspondence with machine language.

Assembler A program to translate an assembly program (source code) into its machine equivalent(object code). Procedure : After the object program is created, it is transferred into the computer s primary memory using the system s loader. Another program called link editor passes computer control to the first instruction in the object program, and then the execution starts and proceeds till the end of the program.

High Level languages (1958.) They are machine-independent as they relate to the procedures being coded. A HLL program can be executed on any computer system that has a translator for that HLL. Translated into machine code by compilers & interpreters. Written in English-like language.

Advantages-HLL Machine-independent hence portable. Easier to learn & requires less time to code. Provides better documentation. Libraries of subroutines can be incorporated and used in many other programs. Easier to debug as translators display all errors with proper error messages.

Some High Level Languages FORTRAN Engineering and Scientific work COBOL BASIC PASCAL SNOBOL LISP ADA Business data processing Learnt quickly by beginners, popular among users of small computers Used in teaching computer programming, useful in system programs because of rich data structure representation. Used in Symbol manipulation Solving logical complex problems (chess, prove theorems) Complex military applications

INTERPRETER Translates the program line by line. Each time the program is executed, every line is checked for syntax and then converted to equivalent machine code. Source program & the interpreter are required for execution. Translators Good fro fast debugging and at testing stage. Execution time is more. No security of source code. COMPILER Translates the entire program. Converts the entire program to machine-code, when all the syntax errors are removed, and executes the object code directly. Neither source nor the compiler are required for execution. Slow for debugging and testing. Execution time is less. Security of source code. - Basic - C, Cobol, Pascal, Fortran

Programming Concepts? Computer requires instruc=ons to be given for any job to be done. Students need to know as part of course and job. Later on just a maaer of knowing the syntax.

Program Development Steps In order to solve a problem using a computer it is necessary to evolve a detailed and precise step by step method of solu=on. Algorithm Flowchart Program

Algorithm Finite sequence of instruc=ons (to solve a problem). The development of a proper procedure to get the required results. Characteris=cs n n n n n Inputs Precise & unambiguous processing rules Basic instruc=ons Finite steps Outputs

Points for developing Algorithm Every procedure should carefully specify the input and output requirements. Meaning of variables should be clearly defined. The flow of program should generally be forward except for normal looping and unavoidable instance.

Example Problem : Obtain the percentage of marks obtained by a student in an examina=on. Solu,on : I/P : In the problem maximum marks and marks obtained is given. O/P : The required result is percentage of marks and the formula used is % of marks = Marks obtained X 100 Maximum marks Algorithm : Step 1 : Read name, marks obtained, and maximum marks. Step 2 : Divide marks obtained by maximum marks and store it in Per. Step 3 : Mul=ply Per. by 100 to get percentage. Step 4 : Write name and percentage. Step 5 : Stop.

Flowchart A detailed graph which represents steps to be performed within the machine to produce the needed output. Algorithm represented in pictorial form. Requires only a few symbols in program char=ng to indicate the necessary opera=ons.

Characteris=cs of FCs An aid in formula=ng and understanding algorithms. Easy visual recogni=on, a standard conven=on is used in drawing flow charts. Sequencing & repe==on instruc=ons easily visible. Helps in detec=ng, loca=ng, and removing mistakes if the program fails to run to comple=on. The program FC acts as a guide or blueprint during the program prepara=on phase.

Characteris=cs of FCs. Leads to quicker grasp of rela=onships. It becomes a model of a program or system that can be broken down into detailed parts for study. Can be used as working models in the design of new programs and systems. Program Documenta=on. Aid in communica=ng the facts of a problem to those whose skills are needed in the solu=on.

Symbols used in Program FCs Symbols adopted by the American Na=onal Standards Ins=tute (ANSI). Input/Output (Parallelogram) Used to represent I/O opera=ons. Have two flow lines, entry & exit. Processing (Rectangle) Storage & Arithme=c opera=ons. Have two flow lines, entry & exit.

Terminal (Rounded Rectangle) Used to indicate START & STOP. Has a single entry or exit line. Decision (Diamond) Logic/comparison opera=ons. Has one entry and at least two exit paths or branches. The exits are labeled with the answers to the decision ques=on. Flow (Line with Arrow) Most important in a Flow Chart. Indicates the flow of logic of the program. All the other flow chart symbols are connected by the flow line.

Connector (Circle) Used when addi=onal flow lines might cause confusion and reduce understanding. Two connectors with iden=cal labels serve the same func=on as a long line. Exit Point Entry Point Predefined Process (Rectangle with end lines) Certain processing opera=ons are repeated in programs which are grouped into a separate procedure. A single symbol replaces a number of opera=ons that need not be detailed.

Limita=ons of FCs Complex and detailed charts are laborious to plan and draw. No standards determining the amount of detail that should be included in a chart.

Example Problem : Obtain the percentage of marks obtained by a student in an examina=on. Start Input name, mks., max. mks. Per=marks/max. marks Per=PerX100 Print name & per Stop

Program Expresses the flow chart/algorithm in a more precise and concise nota=on to be fed to the computer for execu=on. Machine-Independent : Primary objec=ve is to facilitate a large number of people to use computers without the need to know in detail the internal structure of the computer. The specifica=on of the sequence of computa=onal steps in a par=cular programming language is termed as a program.

Programming Techniques Linear Programming When programming started the size and scope of the programs was small. Structured Programming Introduced as the size and scope of programs grew, the tradi=onal linear approach to programming made programs unstructured and difficult to understand.

Linear Programming Straighmorward programming in a sequen=al manner. Does not involve any decision making. General model of a linear program : 1. Read a data value. 2. Compute an intermediate result. 3. Use the intermediate result to compute the desired answer. 4. Print the answer. 5. Stop.

Structured Programming It refers to the process in which we break the overall job down into separate piece of modules. Digital computers can make a decision, thus crea=ng a branching point. If branching and looping can be use, then more complex itera=ve algorithms can be developed into complex programs. Complex programs that make them less error prone and easier to debug.

Choice of Modules Modules must be chosen in such a way that we can specify how they are to interact. There must be a contact between each modules. Contacts specify : What the module will do? What inputs a par=cular module is to receive from the various other modules and what outputs it is required to provide for them?

Advantages of Struct. Prog. Decreases the complexity of the program. Allows several programmers to code simultaneously. Allows reuse of common func=ons across programs. Isolates errors hence decreases debugging. Amendments to single module does not affect the rest of the program. As it is a standard method takes less =me to write. Easy naming of modules help to locate easily in documenta=on.

Modular Design of Programs Program is designed as a set of units referred to as blocks or modules. The modules reflect a logical flow for a computer program. Modules basically have : Input Output Func=on Mechanism Internal Data Modules are arranged at different levels into a structured chart and all are connected.

Module Connec=on Rules Only one module at the top of the structure called the root module. The root passes control down the structure chart to the lower level modules. Control is always returned to the invoking module and a finished module should always terminate at the root. There cannot be more than one control rela=onship between any two modules on the structure chart. If module A invokes module B, then B cannot invoke module A.

Example Structured Module Chart Creature Bird Animal Amphibian Winged Not_Winged Wild Domestic Frog Crow Sparrow Penguin Lion Dog

Program Instruc=on Types Statements to establish the start of the program. Variable declara=on. Program statements (blocks of code). Expressions. Programming Constructs.

Variable Declara=on Place holders for data a program might use or manipulate. Variables are given names so that we can assign values to them and refer to them later to read the values. They are declared at the start because in order to use a variable within a program, the compiler needs to know in advance the type of data that will be stored in it. Variable typically stores value (content) of a given type (characteris=c of the variable).

Variable Type n Integer n Real To store integer or "whole" numbers. To store real or fractional numbers (also called float to indicate a floating point number). n Character A single character such as a letter of the alphabet or punctuation. n String A collection of characters.

Expressions Expressions are made up of a combina=on of variables & operators which act on it. Operators work with respect to precedence & associa=vity rules set for the language. Some operators are : Arithme=c (Mathema=cal) Logical (Boolean) Rela=onal (Comparison)

Operators Arithme=c Add, Subtract, Mul=ply, Divide, Remainder. Logical And, Or, Not. Rela=onal Less than, Greater than, Equal to, Not equal to, Less than equal to, Greater than equal to.

Programming Constructs Control statements "control" which sec=ons of code in a program are to be executed. Types of Control Statements are : Sequen=al - The default ordering of execu=on. Selec=on (Condi=onal) - Controls which block of code within several alterna=ves is executed. Itera=ve - controls how many =mes a block of code is executed.

Thank You