Types of Programming Language (1) - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Types of Programming Language (1)

Description:

Escape character () Indicates that printf should do something out ... Write down some sample screen output that you would expect to see when the program is run ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 17
Provided by: netserver
Category:

less

Transcript and Presenter's Notes

Title: Types of Programming Language (1)


1
Types of Programming Language (1)
  • Three types of programming languages
  • Machine languages
  • Strings of numbers giving machine specific
    instructions
  • Example
  • 1300042774
  • 1400593419
  • 1200274027
  • Assembly languages
  • English-like abbreviations representing
    elementary computer operations (translated via
    assemblers)
  • Example
  • LOAD BASEPAY
  • ADD OVERPAY
  • STORE GROSSPAY

2
Types of Programming Language (2)
  • High-level languages
  • Codes similar to everyday English
  • Use mathematical notations (translated via
    compilers)
  • Example
  • grossPay basePay overTimePay

3
High Level Languages
  • FORTRAN
  • Used for scientific and engineering applications
  • COBOL
  • Used to manipulate large amounts of data still
    used in established business-software
  • Pascal
  • Designed for the teaching of structured
    programming
  • C
  • Evolved by Ritchie from two previous programming
    languages, BCPL and B (early 1970s)
  • Used to develop UNIX and other modern operating
    systems
  • Standardized in 1989 and 1999 into an
    "unambiguous, machine-independent" definition
  • Hardware independent (portable)

4
The C Program Environment
  • Edit
  • Preprocess
  • Compile
  • Link
  • Load
  • Execute

5
A First C Program (1)
  • Comments
  • Text surrounded by / and / is ignored by
    computer
  • Used to describe program
  • include ltstdio.hgt
  • Preprocessor directive
  • Tells computer to load contents of a certain file
  • ltstdio.hgt allows standard input/output operations

6
A First C Program (2)
  • int main()
  • The keyword main indicates where the program
    starts executing
  • Parenthesis ( ) always follow the word main
  • int means that main "returns" an integer value
    (more on this later!)
  • Braces ( and ) indicate a block of code
  • The body of main must be contained in braces

7
A First C Program (3)
  • printf( "Welcome to C!\n" )
  • Instructs computer to perform an action
  • Specifically, prints the string of characters
    within quotes (" ")
  • Entire line called a statement
  • All statements must end with a semicolon ()
  • Escape character (\)
  • Indicates that printf should do something out of
    the ordinary
  • \n is the newline character
  • return 0
  • Indicates the end of the main function

8
Compiling and Executing (5)
9
An Alternative First C Program
  • Produces the same output as the previous program
  • Another variation printf(Welcome\nto\nC!\n)
    would produce three lines of output, with
    newlines inserted after the words welcome and to,
    as well as at the end.

10
Adding two Numbers (Program Listing)
11
Adding two Numbers (New Concepts)
  • Lines 13 and 16 read input from the keyboard
  • scanf( "d", integer1 )
  • scanf( "d", integer2 )
  • Lines 8 - 10 declare the programs variables
  • int integer1
  • int integer2
  • int sum
  • Line 18 performs a mathematical calculation on
    the numbers input from the keyboard
  • sum integer1 integer2
  • Line 20 prints to the screen the result of this
    calculation
  • printf( "Sum is d\n", sum )

12
Adding two Numbers (Discussion)
  • As before
  • Comments, include ltstdio.hgt and main
  • int integer1, integer2, sum
  • Definition of variables
  • Variables locations in memory where a value can
    be stored
  • int means the variables can hold integers (e.g.
    -1, 3, 0, 47)

13
Adding two Numbers (Discussion)
  • Variable names (identifiers)
  • integer1, integer2, sum
  • Identifiers consist of letters, digits (cannot
    begin with a digit) and underscores( _ )
  • Case sensitive
  • Definitions appear before executable statements
  • If an executable statement references and
    undeclared variable it will produce a syntax
    (compiler) error

14
Adding two Numbers (Discussion)
  • scanf( "d", integer1 )
  • Obtains a value from the user
  • scanf uses standard input (usually keyboard)
  • This scanf statement has two arguments
  • d - indicates data should be a decimal integer
  • is confusing in beginning for now, just
    remember to include it with the variable name in
    scanf statements
  • When executing the program the user responds to
    the scanf statement by typing in a number, then
    pressing the enter (return) key

15
Adding two Numbers (Discussion)
  • (assignment operator)
  • Assigns a value to a variable
  • Is a binary operator (has two operands)
  • sum integer1 integer2
  • sum gets the result of integer1 integer2
  • Variable receiving value on left
  • printf( "Sum is d\n", sum )
  • Similar to scanf
  • d means decimal integer will be printed
  • sum specifies what integer will be printed
  • Calculations can be performed inside printf
    statements
  • printf( "Sum is d\n", integer1 integer2 )
  • Write down some sample screen output that you
    would expect to see when the program is run

16
Adding two Numbers (Output)
  • This shows an example of what you see when you
    run this program

Enter first integer45 Enter second
integer72 Sum is 117
Write a Comment
User Comments (0)
About PowerShow.com