CPS 196 Introduction to Computer Programming: C - PowerPoint PPT Presentation

1 / 22
About This Presentation
Title:

CPS 196 Introduction to Computer Programming: C

Description:

Machine. language. program. Compiler (Translation. Program) Coding. Program. Translation ... low-level languages like Assembly language and machine language ... – PowerPoint PPT presentation

Number of Views:56
Avg rating:3.0/5.0
Slides: 23
Provided by: su15
Category:

less

Transcript and Presenter's Notes

Title: CPS 196 Introduction to Computer Programming: C


1
CPS 196Introduction to Computer Programming C
  • Norka Lucena
  • norka_at_ecs.syr.edu
  • Summer Session II
  • Syracuse University
  • July 2004

2
Overview
  • Course setup
  • Basics of programming
  • Introduction to C
  • Variables
  • Identifiers

3
What is a Computer Program?
  • A sequence of instructions used to operate a
    computer to produce specific results

4
What is Programming?
  • The process of writing those instructions in a
    language that the computer can respond and other
    programmers can understand

5
What is a Programming Language?
  • The set of instructions that can be used to
    construct a program

6
How do programs run?
7
What is an Algorithm?
  • A step-by-step sequence of instructions that
    describes how to perform a computation
  • Example
  • Add the numbers from 1 to 100

8
Algorithms for Adding the Numbers from 1 to 100
9
What is Pseudo Code?
  • English phrases used to describe the algorithm
    (the processing steps)
  • Example
  • Calculate the average of 3 numbers
  • Input the three numbers
  • Add the three numbers and dividing the sum by 3
  • Display the average

10
What is a Flowchart?
  • The graphical representation of a pseudo code
    employing specifically designed shapes

11
Flowchart Symbols
Terminal
Decision
Input/Output
Loop
Predefined Process
Process
Flow Lines
Connector
12
Flowchart for Calculating the Average of Three
Numbers
Start
  • Input the three numbers
  • Add the three numbers and dividing the sum by 3
  • Display the average

Input three values
Calculate average
Display average
End
13
What is Coding?
  • Converting an algorithm into a computer program,
    using a language like C is called coding the
    algorithm

List Requirements
Select an Algorithm
Translate the Algorithm into C language code
Coding
Compiler (Translation Program)
C language source program
Program Translation
14
What is C?
  • Developed in the 1970s at ATT laboratories
  • Names CPL ? BCPL ? B ? C
  • Originally created for systems programming, i.e.,
    writing software that controls hardware and other
    software. UNIX and other operating systems are
    written in C
  • C was developed to find a common language for a
    variety of application

15
What type of language C is?
  • C is a high-level language
  • A high level language is designed to give better
    programming efficiency i.e. for faster program
    development. C is similar to other high-level
    languages like Pascal, PL/I, FORTRAN and BASIC
  • C is a low-level language
  • A low level language is designed to give a better
    machine efficiency i.e. faster program execution.
    C is similar to other low-level languages like
    Assembly language and machine language
  • C is between both categories, so it is often
    called a middle-level language

16
Why do we want to learn C?
  • Supports writing portable programs
  • A program's source code is portable which can be
    run on various operating environments
  • Still high-level language of choice for system
    programming
  • Used to write sophisticated workstations and PC
    applications
  • Examples Most popular word processors,
    spreadsheets, data base management systems
    and graphics packages are written at least
    partially in C
  • Many commercial tools and code libraries support
    C
  • C programs are simple and easy to use
  • There exist a lot of public domain C code
    available through the Internet

17
Why dont we have a break now?
18
What are Identifiers?
  • Names given to various program elements such as
    variables, functions and arrays
  • Identifiers consist of letters and digits in any
    order, except that
  • The First character must be a letter
  • The identifier can be in lowercase or uppercase
  • The upper and lower case are interchangeable
  • The underscore (_) can be included and it can
    also begin with underscore
  • The identifiers should not contain a blank space,
    hyphen or quotes

19
Identifiers
  • Valid Identifiers
  • sum
  • Sum
  • SuM
  • A112
  • total_sum
  • Invalid Identifiers
  • sum quotes() is illegal
  • total-sum illegal character ( - )
  • total sum blank space should not be there

20
What are Variables?
  • Labeled block of memory that you can store,
    change and read information from/to
  • A variable is an identifier that is used to
    represent some specified type of information
    within the program
  • As an identifier, variables follow the naming
    restrictions mentioned above

21
Variables
  • The basic format for declaring variables is
  • data type var, var, ...
  • where data type is one of the four basic
    types, an integer, character, float, or double
    type

22
Variables
  • Examples of variables
  • float x ? declares x to be a floating point
    variable
  • int k ? declares k to be an integer variable
  • char c ? declares c to be a character variable
  • char p ? declares p a pointer-to-character
    (string) variable
  • int q ? declares q a pointer-to-integer
    variable
Write a Comment
User Comments (0)
About PowerShow.com