Introduction to Programming in C - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Introduction to Programming in C

Description:

Program: A set of instructions that commands the computer to perform a ... The two phase process will produce a correctly working code with minimum hassle. ... – PowerPoint PPT presentation

Number of Views:68
Avg rating:3.0/5.0
Slides: 21
Provided by: rohitval
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Programming in C


1
Introduction to Programming in C
  • Class 1
  • 01/13/2003
  • Rohit Valsakumar

2
Computer Systems
  • Program A set of instructions that commands the
    computer to perform a certain task.
  • Software The collection of programs running on a
    computer e.g. editors, browsers, operating system
    etc.
  • Hardware The physical components that make up a
    computer e.g., motherboard, monitor, keyboard etc.

3
Hardware
  • Three main types of computers
  • PCs, workstations, mainframes

4
Memory
  • Stores the input
  • Stores intermediate results of operations
    performed by CPU
  • Used by CPU as a scratch pad
  • Two distinct forms of memory
  • Main memory e.g. RAM
  • Secondary memory e.g. Hard disks, tape drives,
    CD-ROMS etc.

5
Secondary memory
  • Non volatile
  • Very cheap
  • Used for long term storage

6
Main memory
  • Volatile
  • Expensive
  • Used for intermediate storage

7
Main memory
  • Is designed as a long list of numbered locations
    called as memory locations
  • Each memory location stores a string of 0s and 1s
  • Each 0 or 1 is called a bit
  • In most computer each memory location can hold at
    most eight bits called a byte
  • The number of each byte is its address

8
Main memory
9
Software
  • Types of programs running on the computer
  • Operating System (most important program)
  • Editors
  • Compilers
  • Games
  • Scientific software
  • Operating System is responsible for allocating
    and managing the resources of the computer among
    the various programs that run on it

10
Program
  • Input to a computer is made of two components
    data and program
  • The program is a set of instructions that the
    computer follows to process the data and generate
    the output
  • This activity is called as a process

11
Program
  • The program or set of instructions can be written
    in various languages such as
  • Machine language e.g. 1100100111001
  • Assembly language e.g. MOV A, B
  • High-level language e.g. if cond true ..
  • It is very difficult to write programs in machine
    level or assembly languages because
  • Code is not portable across various platforms
  • Difficult to maintain, debug or extend
  • Impossible to write long programs

12
High Level Languages
  • High level languages like C, C, Pascal were
    developed to overcome the above problems
  • It resembles human language in many ways
  • It becomes easier to read and write programs
  • Larger programs can be written in a short time

13
High Level Languages
  • Computers dont understand high level languages,
    they understand only machine language
  • Two programs that convert the high level language
    into machine language compilers and linkers
  • Compilers A program that translates a high level
    language like C code to a machine language
  • Input program is called source program or source
    code
  • Translated version is called object code
  • Linkers Linkers combine the object code of the
    source code with the object code of the routines
    (such as input and output routines)

14
Algorithm
  • Algorithms - An algorithm is a step-by-step
    finite sequence of instructions that describe how
    to perform a computation.
  • Example To add numbers 1 to 100 we can use the
    following algorithms
  • 123499100 5050
  • 0100 100 199 100 298 100 50 (50
    100) 50 5050
  • Sum N(AB)/2
    Where N Number
    of terms to be added (100)
    A First Number to be added (1)
    B The
    Last Number to be added (100) Thus
    Sum 100(1100)/2 5050

15
Program Design
  • Divided into two phases
  • Problem solving phase
  • Involves expressing the solution to the problem
    in the form of an algorithm
  • Implementation phase
  • Translate the algorithm generated in problem
    solving phase into a computer program
  • Caution do not ever omit the problem solving
    phase whatever be the reason
  • The two phase process will produce a correctly
    working code with minimum hassle.
  • Both phases should include testing to minimize
    error and error propagation
  • Please refer to Display 1.7 pg 17 of the text
    book

16
Object Oriented Programming
  • A program is viewed as a collection of
    interacting objects
  • The behavior of each object is captured by an
    algorithm for that object
  • Thus in OOP programming involves designing the
    objects and the algorithms they use
  • E.g. to design a card game each card can be
    thought of as an object

17
The Software Life Cycle
  • Very important in the design of large software
    products
  • Six main stages
  • Analysis and specification of the task
  • Design of the software
  • Implementation (coding)
  • Testing
  • Maintenance and evolution of the code
  • Obsolence

18
A small C program
  • includeltiostream.hgt
  • int main()
  • int i 10
  • cout ltlt Hello Worldltlt endl
  • cin gtgt i
  • cout ltlt i
  • cin ltlt i
  • return 0

19
Testing and debugging
  • Bug Error or mistake in the code is called a bug
  • Debugging Process of eliminating bugs

20
Types of errors
  • Specification errors Occurs when the
    specification of the problem itself has errors in
    it (very hard to detect and correct)
  • Syntax errors Violation of the syntax (grammar
    rules) of the programming language e.g. missing
    semicolon or brace (gets caught by the compiler)
  • Run-time errors Errors that are detected only
    when the program is run on a computer e.g. divide
    by zero (usually detected at run time and error
    message displayed by the system)
  • Logic errors Mistakes in the algorithm or in the
    translation of the algorithm into program e.g.
    using wrong operators
Write a Comment
User Comments (0)
About PowerShow.com