CS141 Lecture 1 (1)

download CS141 Lecture 1 (1)

of 28

Transcript of CS141 Lecture 1 (1)

  • 7/31/2019 CS141 Lecture 1 (1)

    1/28

  • 7/31/2019 CS141 Lecture 1 (1)

    2/28

    CS-141

    Programming Fundamentals

    Jameel Ahmad

    Assistant [email protected]

    Department of Electrical EngineeringUniversity of Management and Technology

    CS141-Programming Fundamentals

    mailto:[email protected]:[email protected]
  • 7/31/2019 CS141 Lecture 1 (1)

    3/28

    Text Book for the course

    Required Textbook:

    C How to Program 5th or 6th edition

    Paul Deitel and Harvey Dietel

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    4/28

    Grading Policy

    Labs (attendance + task completion): 20%

    Quizzes : 10%

    Assignments: 15%

    Mid Term: 15%

    Final Exam (Code + Conceptual): 40%

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    5/28

    Student Civility In an effort to make this class enjoyable foreverybody

    Please be on time to class!

    Please do not talk to your friends and neighbors inclass! It disturbs everyone, and makes it hard toconcentrate. If you have a question, just ask me!

    Please turn your pagers and cell-phones off!

    5CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    6/28

    Help is always available

    Option 0: Send me an SMS thatyou want to discuss some issue Option 1: Come to my Office

    Hours

    Option 2:Send me an email

    6

  • 7/31/2019 CS141 Lecture 1 (1)

    7/28

    Course Description Introduction to algorithms and programming

    What is an algorithm?

    What is programming?

    Programming philosophy How to think of a programming problem

    How to plan the solution to the problem Problem decomposition

    Top-down refinement

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    8/28

    Course Description (2) Using an interactive development environment (IDE)

    Types of programming errors Syntactic

    Semantic

    Using a structured programming language What is a programming language?

    What is a structured programming language?

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    9/28

    Course Description (3) Main language concepts covered:

    Simple data types

    Numbers (integer, real)

    Boolean

    Characters Strings

    (NOT structured/complex data types)

    Input / output statements

    Basic statements (assignment, conditionals,iteration/looping)

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    10/28

    Course Objectives Understand basic components in a computer

    architecture

    Appreciate the role of programming languages

    Design a top-down solution for solving problems

    Be familiar with an IDE

    Edit, compile, debug and run short programs

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    11/28

    Outline of Topics Hardware/Software interface

    Layers of the Machine

    Kinds of Software Computer Languages

    Syntax, Semantics, Grammars

    What happens to your program?

    Compilation, Linking, Execution

    Program errors

    Compilation vs. Interpretation etc.

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    12/28

    Software CategoriesSystem SW

    Programs written for computer systems

    Compilers, operating systems,

    Application SWPrograms written for computer users

    Word-processors, spreadsheets, & otherapplication packages

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    13/28

    A Layered View of the Computer

    Machine with all its hardware

    System SoftwareCompilers, Interpreters,Preprocessors, etc.

    Operating System, Device Drivers

    Application Programs

    Word-Processors, Spreadsheets,

    Database Software, IDEs,

    etc

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    14/28

    Operating System (OS) Provides several essential services:

    Loading & running application programs

    Allocating memory & processor time Providing input & output facilities

    Managing files of information

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    15/28

    Programs Programs are written in programming languages

    PL = programming language

    Pieces of the same program can be written in differentPLs Languages closer to the machine can be more efficient

    As long as they agree on how to communicate

    A PL is

    A special purpose and limited language

    A set of rules and symbols used to construct a computerprogram

    A language used to interact with the computer

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    16/28

    Computer Languages

    Machine Language Uses binary code Machine-dependent Not portable

    Assembly Language Uses mnemonics Machine-dependent Not usually portable

    High-Level Language (HLL) Uses English-like language Machine independent Portable (but must be compiled for different platforms) Examples: Pascal, C, C++, Java, Fortran, . . .

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    17/28

    PL hierarchy

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    18/28

    Machine Languages, Assembly Languages,

    and High-level Languages Three types of programming languages

    Machine languages Strings of numbers giving machine specific instructions

    Example:

    +1300042774 (these would really be in binary)+1400593419

    +1200274027

    Assembly languages English-like abbreviations representing elementary

    computer operations (translated via assemblers) Example:

    LOAD BASEPAY

    ADD OVERPAY

    STORE GROSSPAY

    2000 Prentice Hall, Inc. All rights reserved.

    18CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    19/28

    Machine Languages, Assembly Languages,

    and High-level Languages High-level languages

    Instructions closer to everyday English English is a natural language. Although high level

    programming languages are closer to natural languages, it isdifficult to get too close due to the ambiguities in naturallanguages (a statement in English can mean different things todifferent people obviously that is unacceptable for computerprogramming). However, this is a big research area ofcomputer science.

    Use mathematical notations (translated via compilers)

    Example:grossPay = basePay + overTimePay

    Interpreter Executes high level language programs withoutcompilation.

    2003 Prentice Hall, Inc. All rights reserved.

    19(modified by Evan Korth)

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    20/28

    Machine Language The representation of a computer program which is

    actually read and understood by the computer. A program in machine code consists of a sequence of machine

    instructions.

    Instructions:

    Machine instructions are in binary code Instructions specify operations and memory cells involved in the

    operation

    Example: Operation Address

    0010 0000 0000 0100

    0100 0000 0000 0101

    0011 0000 0000 0110

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    21/28

  • 7/31/2019 CS141 Lecture 1 (1)

    22/28

    High-level language A programming language which use statements consisting

    of English-like keywords such as "FOR", "PRINT" or IF, ...etc.

    Each statement corresponds to several machine languageinstructions (one-to-many correspondence).

    Much easier to program than in assembly language.

    Data are referenced using descriptive names

    Operations can be described using familiar symbols Example:

    Cost := Price + Tax

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    23/28

    Attributes of a good language Clarity, simplicity, and unity

    Have a minimum number of different concepts, withthe rules for their combination, simple and regular

    (conceptual integrity). readability

    Orthogonality Being able to combine various features of a language in

    all possible combinations. Naturalness for the application

    Support for abstraction

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    24/28

    Attributes of a good language Ease of program verification

    Proof of correctness, desk checking, test

    Simplicity of semantic and syntax

    Programming environment

    Portability of programs

    Cost of use

    Program execution Program translation

    Program creation, testing, and use

    Program maintenance

    CS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    25/28

    Attributes of a good language(another view: to make a software reliable,

    maintainable, efficient) Reliability

    Writability

    Readability

    Simplicity

    Safety (no goto, no pointers)

    Robustness (undesired events can be trapped, likearithmetic overflow, invalid inputs)

    Maintainability Factoring (modularity)

    Locality

    EfficiencyCS141-Programming Fundamentals

  • 7/31/2019 CS141 Lecture 1 (1)

    26/28

    Syntax & Semantics Syntax:

    The structure of strings in some language. A language'ssyntax is described by a grammar.

    Examples: Binary number

    = | = 0 | 1

    Identifier = { | }

    = a | b | . . . | z

  • 7/31/2019 CS141 Lecture 1 (1)

    27/28

  • 7/31/2019 CS141 Lecture 1 (1)

    28/28

    Syntax & Grammars Syntax descriptions for a PL are themselves written in

    a formal language.

    E.g. Backus-Naur Form (BNF)

    The formal language is not a PL but it can beimplemented by a compiler to enforce grammarrestrictions.

    Some PLs look more like grammar descriptions thanlike instructions.

    CS141 Programming Fundamentals