1 / 18

Structured Program Development

Structured Program Development. Dilshad M. Shahid New York University @1998. Today. Float Variables How to use Borland Equality and Relational Operators Algorithms Pseudocode Control Structures. Float variables.

wenger
Download Presentation

Structured Program Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Structured Program Development Dilshad M. Shahid New York University @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 <stdio.h> 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 > > x > y x is greater than y • < < x < y x is less than y • > >= x >= y x is greater than or equal to y • < <= x <= 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 < 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 < 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 >= 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?

More Related