chapter1 introduction new

Upload: muhd-rzwan

Post on 14-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/29/2019 Chapter1 Introduction New

    1/24

    Principles of Programming - NI July 2005 1

    Chapter 1: Introduction

    In this chapter you will learn about:Overview of PC components

    The different types of language

    Natural Language

    Formal Language

    Functional / Imperative Language

    Programming Languages

    C as an imperative language

    C program at a glance

  • 7/29/2019 Chapter1 Introduction New

    2/24

    Principles of Programming - NI July 2005 2

    Computer Hardware Components

    Components of a PC

  • 7/29/2019 Chapter1 Introduction New

    3/24

    Principles of Programming - NI July 2005 3

    Input / Output Devices

    Input DevicesAccepts information from the user and transformsit to digi ta l codesthat the computer can process

    Example: keyboard, mouse, scanner

    Output DevicesAn interfaceby which the computer conveys theoutput to the user

    Example: monitor, printer

  • 7/29/2019 Chapter1 Introduction New

    4/24

    Principles of Programming - NI July 2005 4

    Main Memory

    A semiconductor device which stores theinformation necessary for a program to run.2 types

    ROM (Read Only Memory)

    Contains information that is necessary for the

    computer to boot upThe information stays there permanently even whenthe computer is turned off.

    RAM (Random Access Memory)

    Contains instruction or data needed for a program torun

    Got erased when the computer is turned off.

  • 7/29/2019 Chapter1 Introduction New

    5/24

    Principles of Programming - NI July 2005 5

    Central Processing Unit (CPU)

    Does most of the work in executing a programThe CPU inside a PC is usually the microprocessor

    3 main parts:Control Unit

    Fetch instructions from main memory and put them inthe instruction register

    ALU (Arithmetic Logic Unit)Execute arithmetic operations

    Registers

    Temporarily store instructions or data fetched frommemory

  • 7/29/2019 Chapter1 Introduction New

    6/24

    Principles of Programming - NI July 2005 6

    Storage Devices

    A magnetic device used to store a large amountof information.

    Store the software components or data neededfor the computer to execute its tasks.

    Could be read only or writable.

    Example: Hard drive, CD ROM, floppy disks

  • 7/29/2019 Chapter1 Introduction New

    7/24

    Principles of Programming - NI July 2005 7

    Network Devices

    Connect a computer to the other computers.Enable the users to access data or executeprograms remotely.

    Example: modem, Ethernet card

  • 7/29/2019 Chapter1 Introduction New

    8/24

    Principles of Programming - NI July 2005 8

    Natural language

    Our everyday-language; spoken and writtenNot 100% needed to understand:

    Do you want to buy this computer ? remainscomprehensible

    Depends on circumstances; the context:

    Do you like one ? doesn't make sense on its own.It needs a situation around it: someone holding a bouquet of flowers: you might

    take one

    someone pointing to an expensive car: your opinionis asked

    someone 'offers' you an oily cloth to sneeze: youdon't take it

  • 7/29/2019 Chapter1 Introduction New

    9/24

    Principles of Programming - NI July 2005 9

    Semantics and Syntax

    Semantics the meaning of the language within agiven context

    Syntax - Syntax are the rules to join words

    together in forming a correct expressionor

    phrase.In natural languages it is often possible toassemble a sentence in more than one correctways.

  • 7/29/2019 Chapter1 Introduction New

    10/24

    Principles of Programming - NI July 2005 10

    Formal Language

    Language with limited, defined, wordsEach concatenation of words ('phrase') has asingle, clearly defined meaning

    no (miss-)interpretation possible

    Sometimes called Context Free Language

    To 'talk' to a computer; to instruct a computer; ourcommands must be 100% clear and correct.

    Often there is only a single, correct syntax.

  • 7/29/2019 Chapter1 Introduction New

    11/24

    Principles of Programming - NI July 2005 11

    Functional / Imperative Language

    Functional Language:Tell what to do, but not how:

    sum [1...10]

    Imperative Language:Tell what to do, but mainly how:

    Take number 1 and add the next number to it;

    then add the next number to the sum; and so on;

    until you have reached 10 as number to be added.Then print the sum of all numbers

  • 7/29/2019 Chapter1 Introduction New

    12/24

    Principles of Programming - NI July 2005 12

    What is Programming?

    Programmingis instructing a computer to do somethingfor you with the help of a programming language

    The two roles of a programming language:

    Technical: It instructs the computer to perform tasks.

    Conceptual: It is a framework within which we

    organize our ideas about things and processes.In programming, we deal with two kind of things:

    Data - representing 'objects' we want to manipulate

    Procedures-'descriptions' or 'rules' that define howtomanipulate data.

  • 7/29/2019 Chapter1 Introduction New

    13/24

    Principles of Programming - NI July 2005 13

    Programming Language

    Formal Language used to communicate to acomputer.

    A programming language contains inst ruct ionsfor the computer to perform a specific action or a

    specific task:'Calculate the sum of the numbers from 1 to 10

    'Print I like programming

    'Output the current time'

  • 7/29/2019 Chapter1 Introduction New

    14/24

    Principles of Programming - NI July 2005 14

    Programming Language

    Can be classified into as a special-purpose andgeneral-purpose programming languages.

    Special-purpose : is design for a particular type ofapplication

    Structured Query Language (SQL)

    General-purpose : can be used to obtain solutionsfor many types of problems

    Machine Languages

    Assembly Languages

    High-Level Languages

  • 7/29/2019 Chapter1 Introduction New

    15/24

    Principles of Programming - NI July 2005 15

    Machine Language

    The only language that the processor actually'understands

    Consists of binary codes: 0 and 1Example: 00010101

    11010001

    01001100Each of the lines above corresponds to a specific taskto be done by the processor.

    Programming in machine code is difficult and slowsince it is difficult to memorize all the instructions.

    Mistakes can happen very easily.Processor and Architecture dependent

  • 7/29/2019 Chapter1 Introduction New

    16/24

    Principles of Programming - NI July 2005 16

    Assembly Language

    Enables machine code to be representedin words andnumbers.

    Example of a program in assembler language:

    LOAD A, 9999

    LOAD B, 8282

    SUB B

    MOV C, ALOAD C, #0002

    DIV A, C

    STORE A, 7002

    Easier to understand and memorize (called Mnemonics),

    compared to machine code but still quite difficult to use.Processor and Architecture dependent

  • 7/29/2019 Chapter1 Introduction New

    17/24

    Principles of Programming - NI July 2005 17

    High-Level Language

    Use more English words. They try to resemble Englishsentences. Therefore, it is easier to program in theselanguages.

    The programming structure is problem oriented - does notneed to know how the computer actually executestheinstructions.

    Processorindependent - the same code can be run ondifferent processors.

    Examples: Basic , Fort ran , Pascal, Cobol , C, C++, Java

    A high level language needs to be analyzed by the compiler

    and then compiled into machine code so that it can beexecuted by the processor.

  • 7/29/2019 Chapter1 Introduction New

    18/24

    Principles of Programming - NI July 2005 18

    C Programming Language

    Why 'C' ?Because based on 'B'; developed at Bell Laboratories

    Developed by Dennis Ritchie at Bell Laboratories inthe 1960s

    In cooperation with Ken Thomson it was used forUnix systems

    The C Language was only vaguely defined, notstandardized, so that almost everyone had his ownperception of it, to such an extend that an urgent

    need for a standard code was creeping up

  • 7/29/2019 Chapter1 Introduction New

    19/24

    Principles of Programming - NI July 2005 19

    C Programming Language cont

    In 1983, the American National Standards Institute(ANSI) set up X3J11, a Technical Committee to drafta proposal for the ANSI standard, which wasapproved in 1989 and referred to as the ANSI/ISO9899 : 1990 or simply the ANSI C, which is now theglobal standard forC.

    This standard was updated in 1999; but there is nocompiler yet

  • 7/29/2019 Chapter1 Introduction New

    20/24

    Principles of Programming - NI July 2005 20

    C An Imperative Language

    C is a highly imperative languageWe must tell it exactly how to do what;

    the means and functions to use;

    which l ibrariesto use;

    when to add a new line;when an instruction is finished;

    in short: everything and anything

    Hint: Observe thesyntax

    in the next slide

  • 7/29/2019 Chapter1 Introduction New

    21/24

    Principles of Programming - NI July 2005 21

    A Simple Program in C

    #include

    main()

    { printf("I like programming in C.\n");

    }

  • 7/29/2019 Chapter1 Introduction New

    22/24

    Principles of Programming - NI July 2005 22

    A Simple Program in C - explanation

    #include

    main(){

    printf("I like programming in C.\n");

    }

    standard Library, input-output, header-file

    Begin of program

    End of statement

    End of Segment

    Start of Segment

    Function for printing text

    Insert a new line

  • 7/29/2019 Chapter1 Introduction New

    23/24

    Principles of Programming - NI July 2005 23

    C Output

    I like programming in C.

  • 7/29/2019 Chapter1 Introduction New

    24/24

    Principles of Programming - NI July 2005 24

    Summary

    We have looked at some underlying hardwareWe have seen some different types of languages;

    the relevance ofsemantics and syntax.

    We have observed the detail necessary in animperative language to instruct a computerproperly.

    Finally, we examined the syntax to print a line oftext to the screen of our computer.