Introduction to High-Level Language Programming - PowerPoint PPT Presentation

About This Presentation
Title:

Introduction to High-Level Language Programming

Description:

Chapter 7 Introduction to High-Level Language Programming – PowerPoint PPT presentation

Number of Views:170
Avg rating:3.0/5.0
Slides: 37
Provided by: WenH150
Category:

less

Transcript and Presenter's Notes

Title: Introduction to High-Level Language Programming


1
Chapter 7
  • Introduction to High-Level Language Programming

2
Where Do We Stand?
  • Machine language
  • Assembly language
  • LOAD X
  • ADD ONE
  • STORE X
  • .
  • ONE .DATA 1
  • Equivalent to INCREMENT X
  • Fine-tuning

3
Disadvantages of Assembly Language
  • Manually manage the movement of data items
    between and among memory locations.
  • Must take a microscopic view of a task
  • Machine-specific
  • Statements are not English-like

4
High-level Programming Language
  • Data management is much easier.
  • Take a macroscopic view of tasks.
  • High-level languages are more portable.
  • Closer to standard English, use standard
    mathematical notation.
  • High-level programming languages are often called
    third-generation language.

5
Program Translation
  • Need a translator to convert high-level language
    instructions into machine languages.
  • Such a system software is called a compiler.
  • Code library
  • Linker

6
Translations of High-Level Language
  • Refer to Figure 7.1.
  • Source program ? translation(compiler) ?
    intermediate program (assembly language code) ?
    translation (assembler) ?object program(object
    code in machine language) ? Linker (links with
    library object code)?complete object
    code(executable) ? loader ? complete object code
    loaded into memory ? hardware (execution) ?results

7
The C Language
  • Developed in the 1980s by Bjarne Stroustrup at
    ATT Bell labs.
  • Extension of C
  • Object-oriented (more on this topic later)

8
Welcome to C!
9
Overall Form of a C Program
  • Prologue comment optional
  • Include derivatives optional
  • Functions optional
  • Main function
  • declarations optional
  • main function body

10
Virtual Data Storage
  • Can associate data with a more meaningful name
    called identifier.
  • In C, an identifier can be any combination of
    letters,digits and the underscore symbol (_), as
    long as it does not begin with a digit.
  • Cannot use keywords for identifiers, either.
  • C is a case-sensitive language.
  • Constants vs. variables

11
C Keywords
  • Cannot be used as identifiers or variable names.

12
Declaration
  • Tells whether the data item is a constant or a
    variable.
  • Tells the identifier that will be used throughout
    the program to name the item.
  • Tells the data type for that item.
  • e.g.
  • double Radius

13
C Syntax
  • Syntax the correct form for each component of
    the language.
  • C is a free-format language, it does not matter
    where things are placed on a line.
  • const double PI 3.1416
  • int grades50
  • int image256256

14
2-D Array
Site 1 Site 2 Site 3
Final reading 14.3 15.2 16.4
Initial reading 13.9 14.2 12.7
  • 0014.3, 0115.2, 0216.4
  • 1013.9, 1114.2, 1212.7
  • ? Data structure

15
Statement Types
  • Input/output statements
  • Assignment statements
  • Control statements

16
Input/output Statements
  • Get the value for radiuscin gtgt Radius
    extraction operator gtgt
  • iostream library include ltiostream.hgt
  • Print the value of circumferencecout ltlt
    Circumferenceinsertion operation ltlt

17
Output format
  • Fixed-point format 84.8232
  • Scientific notation (floating-point format)
    8.482320e001
  • include ltiomanip.hgt
  • cout.setf(iosfixed)
  • cout.setf(iosscientific)
  • cout.precision(2)
  • setw(8)

18
The Assignment Statement
  • Set the value of variable to arithmetic
    expression
  • variableexpression
  • B2
  • C5
  • ABC
  • AA1
  • ,-,,/, (mod)
  • Changing data type type casting

19
Control Statements
  • Sequential (default, no action required)
  • Conditional
  • Looping

20
C Comparison and Boolean Operators
  • Comparison operators , lt , lt, gt , gt, !
  • Boolean operators (AND), (OR), ! (NOT)

21
Conditional Statements
  • if-else
  • if
  • Nested-if

22
Enter two integers, and I will tell you the
relationships they satisfy 3 7
3 is not equal to 7
3 is less than 7
3 is less than or equal to 7
23
Enter two integers, and I will tell you the
relationships they satisfy 3 7 3 is not equal to
7 3 is less than 7 3 is less than or equal to 7
Enter two integers, and I will tell you the
relationships they satisfy 22 12 22 is not equal
to 12 22 is greater than 12 22 is greater than or
equal to 12
Enter two integers, and I will tell you the
relationships they satisfy 7 7 7 is equal to 7 7
is less than or equal to 7 7 is greater than or
equal to 7
24
Nested if/else Structures
  • Test for multiple cases by placing if/else
    selection structures inside if/else selection
    structures.
  • if students grade is greater than or equal to
    90 Print Aelse if students grade is
    greater than or equal to 80 Print B else
    if students grade is greater than or equal
    to 70 Print C else if
    students grade is greater than or equal to 60
    Print D else
  • Print F
  • Once a condition is met, the rest of the
    statements are skipped

25
Looping
  • while (Boolean condition) S1
  • Initialization of variables.
  • Sentinel value to signal that there are no more
    data.
  • Infinite loop

26
(No Transcript)
27
Enter grade 98 Enter grade 76 Enter grade
71 Enter grade 87 Enter grade 83 Enter grade
90 Enter grade 57 Enter grade 79 Enter grade
82 Enter grade 94 Class average is 81
28
(No Transcript)
29
Enter grade, -1 to end 75 Enter grade, -1 to
end 94 Enter grade, -1 to end 97 Enter grade,
-1 to end 88 Enter grade, -1 to end 70 Enter
grade, -1 to end 64 Enter grade, -1 to end
83 Enter grade, -1 to end 89 Enter grade, -1 to
end -1 Class average is 82.50
30
Meeting Expectations
  • Data management issue
  • Macroscopic view
  • Portability ANSI standard
  • Closer to human-language

31
Keeping the Pieces Apart
  • Divide and conquer
  • Using functions
  • Function name (identifier)
  • Argument list what to pass, what gets
    returned(return indicator)
  • Local vs. global variables
  • Pass by value vs. pass by reference

32
(No Transcript)
33
  • 3.1 Define Functions

34
local x in outer scope of main is 5 local x in
inner scope of main is 7 local x in outer scope
of main is 5   local x in a is 25 after entering
a local x in a is 26 before exiting a   local
static x is 50 on entering b local static x is 51
on exiting b   global x is 1 on entering c global
x is 10 on exiting c   local x in a is 25 after
entering a local x in a is 26 before exiting
a   local static x is 51 on entering b local
static x is 52 on exiting b   global x is 10 on
entering c global x is 100 on exiting c local x
in main is 5
35
(No Transcript)
36
x 2 before squareByValue Value returned by
squareByValue 4 x 2 after squareByValue   z
4 before squareByReference z 16 after
squareByReference
Write a Comment
User Comments (0)
About PowerShow.com