Chapter 9 Programming Languages. Have a vision of computer language evolution. Distinguish between machine, assembly, and high-level languages. Understand.

Slides:



Advertisements
Similar presentations
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Advertisements

©Brooks/Cole, 2003 Chapter 9 Programming Languages.
Kyung Hee University 1 1 Application Layer. 2 Kyung Hee University Position of Application Layer.
COSC 120 Computer Programming
Chapter 3 Assignment and Interactive Input. 2 Objectives You should be able to describe: Assignment Operators Mathematical Library Functions Interactive.
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
High-Level Programming Languages
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
1 Lecture 1  Getting ready to program  Hardware Model  Software Model  Programming Languages  The C Language  Software Engineering  Programming.
Guide To UNIX Using Linux Third Edition
COMP1170 Midterm Preparation (March 17 th 2009) Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education.
WWW and Internet The Internet Creation of the Web Languages for document description Active web pages.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 1 Introduction.
Programming Concepts and Languages Chapter 12 – Computers: Understanding Technology, 3 rd edition 1November
CHAPTER 1: INTORDUCTION TO C LANGUAGE
CSE 1301 J Lecture 2 Intro to Java Programming Richard Gesick.
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
CS102 Introduction to Computer Programming
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
INTRODUCTION TO WEB DATABASE PROGRAMMING
© The McGraw-Hill Companies, 2006 Chapter 1 The first step.
COMPUTER SOFTWARE Section 2 “System Software: Computer System Management ” CHAPTER 4 Lecture-6/ T. Nouf Almujally 1.
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
High-Level Programming Languages: C++
UNIVERSITI TENAGA NASIONAL “Generates Professionals” CHAPTER 4 : Part 2 INTRODUCTION TO SOFTWARE DEVELOPMENT: PROGRAMMING & LANGUAGES.
COMPUTER PROGRAMMING Source: Computing Concepts (the I-series) by Haag, Cummings, and Rhea, McGraw-Hill/Irwin, 2002.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Chapter 1: Introduction to Computers and Programming.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
Introduction of C++ language. C++ Predecessors Early high level languages or programming languages were written to address a particular kind of computing.
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Client Scripting1 Internet Systems Design. Client Scripting2 n “A scripting language is a programming language that is used to manipulate, customize,
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 13: An Introduction to C++
Chapter 8 Introduction to HTML and Applets Fundamentals of Java.
Machine Languages It is the only language the computer understands. It is made of 0s and 1s. They must be in 0s and 1s because the internal circuit of.
Recursion Textbook chapter Recursive Function Call a recursive call is a function call in which the called function is the same as the one making.
Introduction to Computer Systems and the Java Programming Language.
Java Programming, Second Edition Chapter One Creating Your First Java Program.
Chapter 9 Programming Languages
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Chapter 1 Section 1.1 Introduction to Java Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska Anchorage.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CPS120: Introduction to Computer Science Decision Making in Programs.
C++ Basics C++ is a high-level, general purpose, object-oriented programming language.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
JavaScript Defined JavaScript Basics Definitions JavaScript is an object-oriented programming language designed for the world wide web. JavaScript code.
8-1 Compilers Compiler A program that translates a high-level language program into machine code High-level languages provide a richer set of instructions.
IT ELECTIVE 2.  Web server Can refer to either the hardware (the computer) or the software (the computer application) that helps to deliver content that.
Chapter 9 ProgrammingLanguages.  Describe the evolution of programming languages from machine language to high-level languages.  Understand how a program.
JavaScript 101 Introduction to Programming. Topics What is programming? The common elements found in most programming languages Introduction to JavaScript.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 11  Getting ready to program  Hardware Model  Software Model  Programming Languages  Facts about C++  Program Development Process  The Hello-world.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
Chapter 1: Introduction to Computers and Programming.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
PROGRAMMING (1) LECTURE # 1 Programming and Languages: Telling the Computer What to Do.
Your Interactive Guide to the Digital World Discovering Computers 2012 Chapter 13 Computer Programs and Programming Languages.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
CSCI-235 Micro-Computer Applications
C Programming Hardik H. Maheta.
Java programming lecture one
Chapter 27 WWW and HTTP.
PHP.
Tonga Institute of Higher Education IT 141: Information Systems
Tonga Institute of Higher Education IT 141: Information Systems
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Presentation transcript:

Chapter 9 Programming Languages

Have a vision of computer language evolution. Distinguish between machine, assembly, and high-level languages. Understand the process of creating and running a program. After reading this chapter, the reader should be able to: O BJECTIVES Distinguish between the different categories of languages: procedural, object-oriented, functional, declarative, and special. Become familiar with elements of the procedural language C.

EVOLUTIONEVOLUTION 9.1

Evolution of computer languages Computer language – a set of predefined words that are combined into a program according to predefined rules (syntax).

The only language understood by a computer is machine language. Note: Each computer has its own machine language, which is made of streams of 0s and 1s.

Program 9.1 Program in machine language

Symbolic language – simply mirrored the machine languages using symbols to represent the various machine language instructions. Assembler – a special program to translate symbolic code into machine language. Assembly language

Entry main,^m subl2 #12,sp jsb C$MAIN_ARGS movab $CHAR_STRING_CON pushal -8(fp) pushal (r2) calls #2,read pushal -12(fp) pushal 3(r2) calls #2,read mull3 -8(fp),-12(fp),- pushal 6(r2) calls #2,print clrl r0 ret Program 9.2 Program in symbolic language

High-Level language –  Portable to many different computers  Allow programmer to concentrate on application  Must be converted to machine languages (Compilation) Natural language – English, French, or Chinese

/* This program reads two integer numbers from the keyboard and prints their product. */ #include int main (void) { // Local Declarations int number1; int number2; int result; // Statements cin >> number1; cin >> number2; result = number1 * number2; cout << result; return 0; }// main Program 9.3 Program in C++ language

BUILDINGAPROGRAMBUILDINGAPROGRAM 9.2

Building a program 1. Writing and Editing 2. Compiling 3. Linking  Running 1. Load 2. Execute

Building a program Source file Object file Executable file Assemble all subprograms into final executable program

PROGRAMEXECUTIONPROGRAMEXECUTION 9.3

Program execution Loader – An OS program to load the program into memory for executing

CATEGORIESOFLANGUAGESCATEGORIESOFLANGUAGES 9.4

Categories of languages

Procedural language – a set of instructions that are executed one by one from beginning to end unless an instruction forces the control elsewhere. When programmers need to solve a problem, they should know the procedure to follow. For each problem, the programmer should carefully design an algorithm, and the algorithm should be carefully translated to instructions. Imperative language – each instruction is a command to the computer to do some specific task.

Fortran –  For scientific and engineering application  The first high-level language COBOL –  a business programming language Pascal –  Structured programming for teaching

C –  High-level instructions (Structured programming for writing UNIX)  Low-level instructions to access the hardware directly and quickly. Closer to assembly language than any other language. A good language for system programmers.  Efficient language; its instructions are short.  Standardized by ANSI and ISO

Procedural language –  Objects – independent from Operations  Objects – passive Object-Oriented language –  An approach to problem solving that is totally different from procedural language.  Objects – tied together with Operations  Objects – active

C++ -  Developed by Bell Lab.  adds object-oriented features to its predecessor, C. Java –  Developed by SUN, Based on C and C++  Java source code files are compiled into a format called bytecode, which can then be executed by a Java interpreter.  Compiled Java code can run on most computers because Java interpreters and runtime environments, known as Java Virtual Machines (VMs), exist for most operating systems.  Programs Application – a complete stand-alone program that can be run independently. Applet – embedded in HTML language, stored on a server, and run by a client browser.

Function in a functional language In Functional language, a program is considered a mathematical function. A function is a black box that maps a list of inputs to a list of outputs. LISP – designed by MIT

Extracting the third element of a list Rest – extracts all the elements except the first. First - extracts all the first elements.

HTML (Hypertext Markup Language)  A seudolanguage that includes marks that serve as formatting hints and links to other files.  An HTML file is made of text and tags. An HTML file (page) is stored on the server and can be download by a browser. Browser – removes the tags and interprets them as either formatting hints or links to other files.

Table 9.1 Common tags Meaning Meaning document document head document body document title different header levels boldface Italic underlined subscript superscript centered line break ordered list unordered list an item in the list an image an address (hyperlink) Beginning Tag Ending Tag

Sample Document This is the picture of a book: Program 9.4 HTML Program

Perl (Practical Extraction and Report Language)  a programming language especially designed for processing text.  one of the most popular languages for writing CGI scripts.  CGI (Common Gateway Interface) programs are the most common way for Web servers to interact dynamically with users. Many HTML pages that contain forms, for example, use a CGI program to process the form's data once it's submitted. SQL (Structured Query Language) – a language used to answer queries about database.

A PROCEDURAL LANGUAGE:C LANGUAGE:C 9.5

Variables Variables – names for memory locations. Each memory location has an address.  Used by the computer internally  Inconvenient for the programmer

Constants constants – data values that cannot be changed during the execution of a program.  Literal constant – a = 2 * p * r ;  Named constant – constant pi = 3.14;  Symbolic constant - #define taxRate

Table 9.2 Arithmetic operators Example Example  4 Num * 5 Sum / Count Count % Count ++ Count  Operator   *     Definition Addition Subtraction Multiplication Division (quotient) Division (remainder) Increment Decrement

Table 9.3 Relational operators Example Example Num1 < 5 Num1 <= 5 Num2 > 3 Num2 >= 3 Num1 == Num2 Num1 != Num2 Operator <     Definition Less than Less than or equal to Greater than Greater than or equal to Equal to Not equal to

Table 9.4 Logical operators Example Example ! ( Num1 < Num2 ) (Num1 10 ) Operator ! && Definition NOT AND OR

Table 9.5 Assignment operators Meaning Store 5 in Num Num = Num + 5 Num = Num  5 Num = Num * 5 Num = Num / 5 Num = Num % 5 Operator == +=  = *= /= %= Example Example Num = 5 Num += 5 Num  = 5 Num *= 5 Num /= 5 Num %= 5

label: goto label; Statement  cause an action to be performed by the program.  translates directly into one or more executable instructions.

Statement  Expression statement – a statement by placing a semicolon(;) after it. a++; b = 4; c = b + c * 4;  Compound statement – a unit of code consisting of zero or more statements. { x = 1; y = 20; }

Functions  In C, a subroutine is called a function.  A C program is made of one or more functions, one and only one of which must be called main.  The execution of the program always starts and ends with main, but this function can call other functions.  The function main is called by the operating system; main in turn calls other functions. When main is complete, control returns to the operating system.

Side effect of a function Side effect  Is an action that results in a change in the state of the program.  Occurs while the function is executing and before the function returns.  In general, the purpose of a function is At the same time, a function can have a side effect.

Parameter Passing  Pass by value  Pass by reference Function declaration Function header Function body Return type Formal parameters Actual parameters

Parameter Passing  Pass by value – a copy of data is created and placed in a local variable in the called function.  Pass by reference – sends the address of a variable to the called function rather than sending its value.

Call by Value void swap(int x, int y) { int temp; temp=x; x=y; y=temp; } ab y x 12 temp main() { int a=1,b=2; swap(a, b); } 12

Call by Address (Reference) void swap(int *x, int *y) { int temp; temp=*x; *x=*y; *y=temp; } ab y x 12 temp main() { int a=1,b=2; swap(&a, &b); } *x *y

if-else statement

switch statement

while loop

for loop False

do-while loop

Recursion C language supports recursion. A function in C can call itself. int fac(int n) { if (n == 0) return(1); else return( n * fact(n-1) ); }

Recursion C language supports recursion. A function in C can call itself. int fac(int n) { if (n == 0) return(1); else return( n * fac(n-1) ); }

The Towers of Hanoi It is a puzzle about three poles and n disks of increasing sizes. Initially, all the of the disks (all have holes at their centers) are placed on the first pole. Our goal is to transfer all the disks from the first pole to the third. We can move only one disk at a time and it is not allowed to place a larger disk on top of a smaller one. Let T(n) denote the number of moves. Then T(n) = 2T(n-1) + 1. Finally we get T(n) = 2 n - 1. A BC

Recursive solution Solve(n, A, B, C) { if (n == 1) A → C else { Solve(n-1, A, C, B) Move from A → C Solve(n-1, B, A, C) } } n A → C B n-1 A → B C n-1 B → C A A → C