©brooks/cole, 2003 chapter 9 programming languages

Post on 18-Dec-2015

229 Views

Category:

Documents

5 Downloads

Preview:

Click to see full reader

TRANSCRIPT

©Brooks/Cole, 2003

Chapter 9

ProgrammingLanguages

©Brooks/Cole, 2003

Have a vision of computer language evolution.Have a vision of computer language evolution.

Distinguish between machine, assembly, and high-level Distinguish between machine, assembly, and high-level languages.languages.

Understand the process of creating and running a program.Understand the process of creating and running a program.

After reading this chapter, the reader should After reading this chapter, the reader should be able to:be able to:

OOBJECTIVESBJECTIVES

Distinguish between the different categories of languages:Distinguish between the different categories of languages:procedural, object-oriented, functional, declarative, and special.procedural, object-oriented, functional, declarative, and special.

Become familiar with elements of the procedural language C. Become familiar with elements of the procedural language C.

©Brooks/Cole, 2003

EVOLUTIONEVOLUTIONEVOLUTIONEVOLUTION

9.19.1

©Brooks/Cole, 2003

Figure 9-1

Evolution of computer languages

©Brooks/Cole, 2003

00000000 00000100 000000000000000001011110 00001100 11000010 0000000000000010

11101111 00010110 000000000000010111101111 10011110 0000000000001011

11111000 10101101 11011111 000000000001001001100010 11011111 0000000000010101

11101111 00000010 11111011 000000000001011111110100 10101101 11011111 000000000001111000000011 10100010 11011111 000000000010000111101111 00000010 11111011 000000000010010001111110 11110100 1010110111111000 10101110 11000101 000000000010101100000110 10100010 11111011 000000000011000111101111 00000010 11111011 0000000000110100

00000100 000000000011110100000100 0000000000111101

Program 9.1Program 9.1 Program in machine languageProgram in machine language1122334455667788991010111112121313141415151616

©Brooks/Cole, 2003

The only language understood The only language understood byby

a computer is machine a computer is machine language.language.

Note:Note:

©Brooks/Cole, 2003

Entry main, ^m<r2>subl2 #12,spjsb C$MAIN_ARGSmovab $CHAR_STRING_CON

pushal -8(fp)pushal (r2)calls #2,readpushal -12(fp)pushal 3(r2)calls #2,readmull3 -8(fp),-12(fp),-pushal 6(r2)calls #2,printclrl r0ret

Program 9.2Program 9.2Multiplication Program in Multiplication Program in symbolic languagesymbolic language

1122334455667788991010111112121313141415151616

©Brooks/Cole, 2003

/* This program reads two integer numbers from the keyboard and prints their product.

*/ #include <iostream.h>

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.3Program 9.3 Multiplication Program in C++ Multiplication Program in C++ languagelanguage

112233445566778899101011111212131314141515161617171818

©Brooks/Cole, 2003

BUILDINGBUILDINGAA

PROGRAMPROGRAM

BUILDINGBUILDINGAA

PROGRAMPROGRAM

9.29.2

©Brooks/Cole, 2003

Figure 9-2

Building a program

©Brooks/Cole, 2003

PROGRAMPROGRAMEXECUTIONEXECUTIONPROGRAMPROGRAM

EXECUTIONEXECUTION

9.39.3

©Brooks/Cole, 2003

Figure 9-3

Program execution

©Brooks/Cole, 2003

CATEGORIESCATEGORIESOFOF

LANGUAGESLANGUAGES

CATEGORIESCATEGORIESOFOF

LANGUAGESLANGUAGES

9.49.4

©Brooks/Cole, 2003

Figure 9-4

Categories of languages

©Brooks/Cole, 2003

Figure 9-5

Function in a functional language

©Brooks/Cole, 2003

Figure 9-6

Extracting the third element of a list

©Brooks/Cole, 2003

Table 9.1 Common tagsTable 9.1 Common tags

MeaningMeaning----------------------------documentdocument headdocument bodydocument titledifferent header levelsboldfaceItalicunderlinedsubscriptsuperscriptcenteredline breakordered listunordered listan item in the listan imagean address (hyperlink)

Beginning TagBeginning Tag----------------

<HTML><HEAD><BODY><TITLE>

<Hi><B><I><U>

<SUB><SUP>

<CENTER><BR><OL><UL><LI>

<IMG><A>

Ending TagEnding Tag----------------</HTML></HEAD></BODY></TITLE>

</Hi></B></I></U>

</SUB></SUP>

</CENTER>

</OL></UL></LI>

</A>

©Brooks/Cole, 2003

<HTML><HEAD>

<TITLE> Sample Document </TITLE></HEAD><BODY>

This is the picture of a book: <IMG SRC="Pictures/book1.gif" ALIGN=MIDDLE>

</BODY></HTML>

Program 9.4Program 9.4 HTML ProgramHTML Program

©Brooks/Cole, 2003

A PROCEDURALA PROCEDURALLANGUAGE:LANGUAGE:

CC

A PROCEDURALA PROCEDURALLANGUAGE:LANGUAGE:

CC

9.59.5

©Brooks/Cole, 2003

Figure 9-7

Variables

©Brooks/Cole, 2003

Table 9.2 Arithmetic operatorsTable 9.2 Arithmetic operators

ExampleExample----------------------

3 + 5 4

Num * 5Sum / CountCount % 4

-----------------------Count ++Count

OperatorOperator----------------

DefinitionDefinition----------------

AdditionSubtraction

MultiplicationDivision (quotient)

Division (remainder)-----------------------

IncrementDecrement

©Brooks/Cole, 2003

Table 9.3 Relational operatorsTable 9.3 Relational operators

ExampleExample----------------------Num1 < 5Num1 <= 5Num2 > 3 Num2 >= 3

Num1 == Num2Num1 != Num2

OperatorOperator----------------

<

DefinitionDefinition----------------

Less thanLess than or equal to

Greater thanGreater than or equal to

Equal toNot equal to

©Brooks/Cole, 2003

Table 9.4 Logical operatorsTable 9.4 Logical operators

ExampleExample----------------------

! ( Num1 < Num2 )(Num1 < 5 ) && (Num2 > 10 )(Num1 < 5 ) || (Num2 > 10 )

OperatorOperator----------------

!&&

DefinitionDefinition----------------

NOTANDOR

©Brooks/Cole, 2003

Table 9.5 Assignment operatorsTable 9.5 Assignment operators

Meaning----------------------

Store 5 in NumNum = Num + 5Num = Num 5 Num = Num * 5Num = Num / 5Num = Num % 5

OperatorOperator----------------

==+==*=/=

%=

Example Example ---------------- Num = 5 Num += 5 Num = 5 Num *= 5 Num /= 5 Num %= 5

©Brooks/Cole, 2003

Figure 9-8

Statements

©Brooks/Cole, 2003

Figure 9-9

Side effect of a function

©Brooks/Cole, 2003

Figure 9-10 Function declaration

©Brooks/Cole, 2003

Figure 9-11

if-else statement

©Brooks/Cole, 2003

Figure 9-12 switch statement

©Brooks/Cole, 2003

Figure 9-13 while loop

©Brooks/Cole, 2003

Figure 9-14 for loop

©Brooks/Cole, 2003

Figure 9-15 do-while loop

top related