Docsity

1. Flowchart n Pseudo code (1).ppt, Exercises of Compiler Design

Partial preview of the text

Download 1. Flowchart n Pseudo code (1).ppt and more Exercises Compiler Design in PDF only on Docsity!

BASICS OF

PROGRAMMING

Difference

Top-Down Design

  • (^) If we look at a problem as a whole, it may seem impossible to solve because it is so complex. Examples: - (^) Coding a tax computation program - (^) Coding a semesterly result for the university
  • (^) Complex problems can be solved using top-down design , also known as stepwise refinement , where - (^) We break the problem into parts - (^) Then break the parts into parts - (^) Soon, each of the parts will be easy to do

Advantages of Top-Down Design

  • (^) Breaking the problem into parts helps us to clarify

what needs to be done.

  • (^) At each step of refinement, the new parts become

less complicated and, therefore, easier to figure

out.

  • (^) Parts of the solution may turn out to be reusable.
  • (^) Breaking the problem into parts allows more than

one person to work on the solution.

SDLC

Download devcpp

  • (^) You need this to develop your program : https://sourceforge.net/projects/orwelldevcpp/

Structured Programs

  • (^) We will use top-down design for all remaining programming projects.
  • (^) This is the standard way of writing programs.
  • (^) Programs produced using this method and using only the three kinds of control structures, sequential, selection and repetition, are called structured programs.
  • (^) Structured programs are easier to test, modify, and are also easier for other programmers to understand.

Algorithm

  • (^) Algorithm is a step-by-step problem- solving method in a limited time
  • (^) At every step, the subsequent action should uniquely be determined by the instructions and data obtained at that time.

Steps in Problem Solving

  • (^) First produce a general algorithm (one can use pseudocode )
  • (^) Refine your steps until you get to an easy sequence. Perhaps use numbers or bullets. The point is to simplify.
  • (^) Pseudocode is an artificial and informal language that helps programmers develop algorithms. Pseudocode may be an informal English, combinations of computer languages and spoken language. Whatever works for you.

A guide that we can follow when building algorithms: a) Identify the input and output of a problem. b) Identify and list the sub-problems. Each problem must be solved, in order to get the results needed. c) For every sub-problem, identify and list the steps that must be taken to solve it.

Exercise :

Write a program to change lb

unit to kg (1lb = 2.5kg)

Input : lb

Output : kg

Process : multiply the lb to 2.

The pseudo-code is:

1.0 Start. 2.0 Read lb_weight 3.0 kg_weight = lb_weight * 2. 4.0 Print kg_weight 5.0 End

Program in editor

The Flowchart A Flowchart is another algorithm but graphical.

  • (^) shows logic solution
  • (^) emphasizes individual steps and their interconnections
  • (^) A flowchart must have a start and stop
  • (^) A steps in a flowchart must connect. Can’t leave a step “hanging” with no connection. e.g. control flow from one action to the next