Computer Programming

download Computer Programming

of 16

  • date post

  • Category


  • view

  • download


Embed Size (px)


Computer Programming

Transcript of Computer Programming

  • Computer Programming

    Engr. Muniba Ashfaq

    DCSE UET Peshawar

  • Course Pre-Requisite

    Basic Computing & Programming

    Text Book

    Dietel & Dietel, C++ How to program.

    Reference Book

    Robert Lafore, Object Oriented Programming in C++

  • Grading Criteria

    Mid term 25%

    Final term 50%

    Sessional 25%

  • Contents of Week 1

    What is a Computer and what are computer languages

    Machine languages, Assembly languages and High level languages

    Translators: Compilers, Interpreter, Assembler History of C and C++ C++ Standard Library Structured Programming Basic of a Typical C++ Environment Algorithms, Pseudocode

  • What is a Computer?

    Electronic device that receives, stores, retrieves and process information

    Device capable of performing computations and making logical decisions.

    consist of: Software

    Instructions to command computer to perform actions and make decisions. (Programs that run on computer).

    Hardware Various devices comprising computer

    Keyboard, screen, mouse, disks, memory, CD-ROM, processing units,

  • Computer languages

    Defines the rules under which programs are written to make use of computers

    Machine languages

    Assembly languages

    High level languages

  • 7

    Computer Languages

    Machine language Only language computer directly understands

    Defined by hardware design Machine-dependent

    Generally consist of strings of numbers Ultimately 0s and 1s

    Instruct computers to perform elementary operations One at a time

    Cumbersome for humans

    Example: +1300042774



  • 8

    Computer Languages

    Assembly language English-like abbreviations representing elementary

    computer operations

    Clearer to humans

    Incomprehensible to computers Translator programs (assemblers)

    Convert to machine language

    Example: LOAD BASEPAY



  • 9

    Computer Languages

    High-level languages Similar to everyday English, use common

    mathematical notations

    Single statements accomplish substantial tasks Assembly language requires many instructions to accomplish

    simple tasks

    Translator programs (compilers) Convert to machine language

    Interpreter programs Directly execute high-level language programs

    Example: grossPay = basePay + overTimePay

  • 10

    History of C and C++

    History of C Evolved from two other programming languages

    BCPL and B

    Dennis Ritchie (Bell Laboratories) Added data typing, other features

    Development language of UNIX Hardware independent

    Portable programs

    1989: ANSI standard 1990: ANSI and ISO standard published

    ANSI/ISO 9899: 1990

  • C and C++

    C is a high level language designed to be,

    Much easier to understand than assembler

    As powerful

    As fast

    Close to the machine


  • Libraries and Modules

    Dont want to rewrite code someone else has already written Expensive Might make mistakes User gets confused Need to share resources with other programs

    Compile each source file Link with other compiled source files and libraries Now can execute our program C++ is easy, learning how to use the libraries is


  • C++ Standard Library

    C programs consist of pieces/modules called functions A programmer can create his own functions

    Advantage: the programmer knows exactly how it works

    Disadvantage: time consuming

    Programmers will often use the C++ library functions Use these as building blocks

    Avoid re-inventing the wheel If a premade function exists, generally best to use it rather

    than write your own

    Library functions carefully written, efficient, and portable

  • Structured Programming

    Disciplined approach to writing programs

    Clear, easy to test and debug and easy to modify

  • 15

    Basics of a Typical C Program Development Environment

    Phases of C++ Programs:

    1. Edit

    2. Preprocess

    3. Compile

    4. Link

    5. Load

    6. Execute

    Program is created in the editor and stored on disk.

    Preprocessor program processes the code.

    Loader puts program in memory.

    CPU takes each instruction and executes it, possibly storing new data values as the program executes.

    Compiler creates object code and stores it on disk.

    Linker links the object code with the libraries


    Primary Memory





    Primary Memory



















  • 16

    Basics of a Typical C++ Environment

    Input/output cin

    Standard input stream

    Normally keyboard

    cout Standard output stream

    Normally computer screen

    cerr Standard error stream

    Display error messages