Sunteți pe pagina 1din 28

CS-141 Programming Fundamentals

Jameel Ahmad Assistant Professor Jameel.ahmad@umt.edu.pk Department of Electrical Engineering University of Management and Technology

CS141-Programming Fundamentals

Text Book for the course

Required Textbook: C How to Program 5th or 6th edition Paul Deitel and Harvey Dietel

CS141-Programming Fundamentals

Grading Policy
Labs (attendance + task completion): 20% Quizzes : 10% Assignments: 15% Mid Term: 15% Final Exam (Code + Conceptual): 40%

CS141-Programming Fundamentals

Student Civility
In an effort to make this class enjoyable for

everybody
Please be on time to class!

Please do not talk to your friends and neighbors in

class! It disturbs everyone, and makes it hard to concentrate. If you have a question, just ask me! Please turn your pagers and cell-phones off!

5
CS141-Programming Fundamentals

Help is always available

Option 0: Send me an SMS that

you want to discuss some issue Option 1: Come to my Office Hours Option 2:Send me an email

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

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

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

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

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

Software Categories
System SW
Programs written for computer systems Compilers, operating systems,

Application SW
Programs written for computer users Word-processors, spreadsheets, & other application packages

CS141-Programming Fundamentals

A Layered View of the Computer


Application Programs
Word-Processors, Spreadsheets, Database Software, IDEs, etc

System Software
Compilers, Interpreters,Preprocessors, etc. Operating System, Device Drivers

Machine with all its hardware


CS141-Programming Fundamentals

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

Programs
Programs are written in programming languages
PL = programming language Pieces of the same program can be written in different

PLs

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 computer

program A language used to interact with the computer


CS141-Programming Fundamentals

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

PL hierarchy

CS141-Programming Fundamentals

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 ADD STORE
2000 Prentice Hall, Inc. All rights reserved.

BASEPAY OVERPAY GROSSPAY


18

CS141-Programming Fundamentals

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 is difficult to get too close due to the ambiguities in natural languages (a statement in English can mean different things to different people obviously that is unacceptable for computer programming). However, this is a big research area of computer science.

Use mathematical notations (translated via compilers) Example:


grossPay = basePay + overTimePay

Interpreter Executes high level language programs without compilation.


19
CS141-Programming Evan Korth) (modified by Fundamentals

2003 Prentice Hall, Inc. All rights reserved.

Machine Language
instructions.

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:
Machine instructions are in binary code
Instructions specify operations and memory cells involved in the

operation

Example:

Operation

Address

0010 0100 0011

0000 0000 0100 0000 0000 0101 0000 0000 0110

CS141-Programming Fundamentals

Assembly Language
A symbolic representation of the machine language of a

specific processor. Is converted to machine code by an assembler. Usually, each line of assembly code produces one machine instruction (One-to-one correspondence). Programming in assembly language is slow and errorprone but is more efficient in terms of hardware performance. Mnemonic representation of the instructions and data Example:
Load Add Store Price Tax Cost

CS141-Programming Fundamentals

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 language instructions (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

Attributes of a good language


Clarity, simplicity, and unity
Have a minimum number of different concepts, with

the 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

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

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, like

arithmetic overflow, invalid inputs)

Maintainability
Factoring (modularity) Locality

Efficiency
CS141-Programming Fundamentals

Syntax & Semantics


Syntax:
The structure of strings in some language. A language's

syntax is described by a grammar. Examples:

Binary number
<binary_number> <bit> =0|1 = <bit> | <bit> <binary_number>

Identifier
<identifier> = <letter> {<letter> | <digit> } <letter> =a|b|...|z <digit =0|1|...|9

Semantics:
The meaning of the language
CS141-Programming Fundamentals

An algo. is correct if its:

Syntax & Semantics

WARNINGS: 1. An algo. can be syntactically correct, yet semantically incorrect very dangerous situation! 2. Syntactic correctness is easier to check as compared with semantic
27

Semantics are correct

Syntax is correct
Semantics:

The concept embedded in an algorithm (the soul!)


Syntax:

The actual representation of an algorithm (the body!)

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 be

implemented by a compiler to enforce grammar restrictions. Some PLs look more like grammar descriptions than like instructions.

CS141-Programming Fundamentals

S-ar putea să vă placă și