Structured Program Development - PowerPoint PPT Presentation

1 / 18
About This Presentation
Title:

Structured Program Development

Description:

How to use Borland. Equality and Relational Operators. Algorithms. Pseudocode. Control Structures ... A new text page automatically when you open Borland ... – PowerPoint PPT presentation

Number of Views:73
Avg rating:3.0/5.0
Slides: 19
Provided by: dilshad7
Learn more at: https://cs.nyu.edu
Category:

less

Transcript and Presenter's Notes

Title: Structured Program Development


1
Structured Program Development
  • Dilshad M. Shahid
  • New York University
  • _at_1998

2
Today
  • Float Variables
  • How to use Borland
  • Equality and Relational Operators
  • Algorithms
  • Pseudocode
  • Control Structures

3
Float variables
  • Float Data Type Data Type that can hold numbers
    with decimal values e.g. 5.14, 3.14
  • Float example

4
  • / Float Example Program /
  • include ltstdio.hgt
  • main ()
  • float var1, var2, var3, sum
  • var1 87.25
  • var2 92.50
  • var3 96.75
  • sum var1 var2 var3
  • printf(Sum .2f, sum)
  • getchar()

5
How to use Borland C
  • Borland comes with 3 disks. Please use the 5.0
    disk.
  • ACF labs have correct version installed
  • A new text page automatically when you open
    Borland
  • Alternatively, you can go to menu option File,
    then New, then Text Edit

6
More Borland
  • Use Save As to save to your disk on the A\ drive
  • After you type in your program, there are 3 ways
    to compile
  • click lightning bolt
  • go to menu option Debug, then Run
  • Hit Control-F9

7
Relational and equality operators
  • table adapted from Figure 2.12, pg 38
  • standard algebraic in C example in C meaning of C
    condition
  • Equality x y x is equal to y
  • ! x ! y x is not equal to y
  • Relational gt gt x gt y x is greater than y
  • lt lt x lt y x is less than y
  • gt gt x gt y x is greater than or equal to y
  • lt lt x lt y x is less than or equal to y

8
Algorithms
  • Algorithm the procedure for solving a problem
    in terms of
  • the actions to be executed
  • the order in which these actions are to be
    executed.
  • See pages 56 to 57 for a more detailed
    description.

9
Pseudocode
  • Pseudocode this is simply writing your code in
    ordinary English to help yourself develop an
    algorithm that will be converted into a
    structured C program.
  • More examples in the text book

10
Control structures
  • All programs can be written in terms of only 3
    control structures
  • sequence structure
  • selection structure
  • repetition structure

11
Sequence structure
  • This is essentially built into C
  • Unless directed otherwise, the computer will
    automatically execute C statements one after
    another in the order in which they are written
  • This is called sequential execution

12
Selection structure
  • A selection structure will perform an action
    based on the conditions it receives
  • 3 kinds of selection structures in C
  • if
  • if/else
  • switch

13
If statement
  • Performs indicated action only when condition is
    true otherwise the action is skipped.
  • Example in pseudocode
  • If bank balance is less than 100
  • Print You are below the required minimum

14
If statement
  • Same example in C
  • int balance
  • balance 90
  • if (balance lt 100)
  • printf(You are below the required minimum
    balance\n)
  • What will the output be? Change the program so
    that balance 110. What will the output be in
    this case?
  • Answer You are below the required minimum
    balance
  • No output.

15
If/else statement
  • Programmer can specify that different actions are
    to be performed when the condition is true than
    when the condition is false

16
If/else statement
  • Example in pseudocode
  • If bank balance is less than 100
  • Print You are below the required minimum
  • else
  • Print You may withdraw money

17
If/else statement
  • Same example in C
  • int balance
  • balance 90
  • if (balance lt 100)
  • printf(You are below the required minimum
    balance\n)
  • else
  • printf(You may withdraw money\n)
  • Make balance equal 120, i.e. greater than 100.
    What will the output be?

18
If/else statement
  • Another example in C
  • int age
  • float height
  • age 10
  • height 5.0
  • if (height gt 4.0) / must have 4.0, it is
    float/
  • printf(Your height is f\n, height)
  • else
  • printf(Your age is d\n, age)
  • What will output be if height 4.0 ? Does
    changing value of age affect the program output?
Write a Comment
User Comments (0)
About PowerShow.com