Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Programming with Structured Flowcharts and Essential Python
Programming with Structured Flowcharts and Essential Python
Programming with Structured Flowcharts and Essential Python
Ebook210 pages1 hour

Programming with Structured Flowcharts and Essential Python

Rating: 0 out of 5 stars

()

Read preview

About this ebook

Although structured flowcharts have been in use for less than a decade, they have found wide acceptance as an aid to developing software. They may be used for writing new algorithms in a step-wise manner or they may be used for documenting existing programs. The major advantage of structured flowcharts is that they make the control section of a program easier to understand. This is especially true when the person revising the program is different from the one who wrote it—a very common practice. Since it is difficult to make a structured flowchart larger than a page, it automatically encourages modularization of a large program.
LanguageEnglish
PublisherLulu.com
Release dateNov 14, 2022
ISBN9781387479665
Programming with Structured Flowcharts and Essential Python

Related to Programming with Structured Flowcharts and Essential Python

Related ebooks

Programming For You

View More

Related articles

Reviews for Programming with Structured Flowcharts and Essential Python

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Programming with Structured Flowcharts and Essential Python - Achla Agarwal

    Programming with Structured Flowcharts

    and

    Essential Python

    Krishna Kumar Agarwal

    Achla Agarwal

    © 2022

    Preface

    Although structured flowcharts have been in use for less than a decade, they have found wide acceptance as an aid to developing software. They may be used for writing new algorithms in a step-wise manner or they may be used for documenting existing programs. The major advantage of structured flowcharts is that they make the control section of a program easier to understand. This is especially true when the person revising the program is different from the one who wrote it—a very common practice. Since it is difficult to make a structured flowchart larger than a page, it automatically encourages modularization of a large program.

    Opponents of flowcharts say that they are worthless either for documentation or as an aid to algorithm development. Clearly, this is a matter of opinion. Familiarity with these flowcharts could make the above-mentioned tasks easier. If it does not, one could just as easily discard structured flowcharting, providing it does not make someone else’s task any harder. Selfish programming is certainly not good practice.

    This book has been written to emphasize the point that algorithm development is the most difficult part of writing a program. Programming itself must be done only when the algorithm has been completed and checked out carefully tracing the flowchart.

    Anyone with only a basic knowledge of mathematics should be able to follow the material of this book; however, like mathematics, programming can only be learned with a lot of practice and patience. Hence, the reader is encouraged to try out as many problems as possible, selecting any suitable programming language for each problem.

    Even though we have deemphasized the importance of programming languages for learning how to program, every algorithm must be programmed in a language to check its correctness. Python has been included in an attempt to convince the reader that algorithm development must be given much more thought than the almost routine task of converting a flowchart to a program.

    Sincere thanks are due to our friend Jay Jain for debugging this book and to our parents for encouraging its development. Many students contributed by telling us what they disliked about many intermediate versions of this book. The editors at Petrocelli Books, Inc. have been very helpful in making improvements. Thanks are also due to McGraw-Hill for granting us permission to copy parts of the first edition, Programming with Structured Flowcharts, first published in 1984.

    krishna_agarwal@hotmail.com    Krishna Kumar Agarwal

    achla1@hotmail.com    Achla Agarwal

    Table of Contents

    Chapter one

    An Introduction to Solving Problems

    Some Common Problems and Procedures

    Standard Flowcharts

    Structured Flowcharts

    Exercises

    Chapter two

    Basic Concepts in Problem Solving

    The Ability to Compare Data Items

    The Ability to Perform Simple Logical Operations

    The Ability to Store Information

    The Ability to Input and Output Data

    The Ability to Repeat a Set of Operations

    Chapter three

    Simple Problems and Their Flowcharts

    Iteration-Free Problems

    Problem 3.1:

    Problem 3.2:

    Problem 3.3:

    Exercises

    Problems Requiring Simple Iteration

    Problem 3.5:

    Problem 3.6:

    Problem 3.7:

    Problems Conducive to Nested Iteration

    Problem 3.8:

    Problem 3.9:

    Problem 3.10:

    Exercises

    Chapter four

    Subscripted Variables

    The Python Program for Figure 4.1

    Reversing the Input Sequence

    Problem 4.1:

    Bubble Sorting

    Problem 4.2:

    Fibonacci Series

    Problem 4.3:

    Sequential Search

    Problem 4.4:

    Binary Search

    Problem 4.5:

    Merge Sorting

    Problem 4.6:

    Students’ Grades

    Problem 4.7:

    Matrix Addition

    Problem 4.8:

    Matrix Multiplication

    Problem 4.9:

    Exercises

    Chapter five

    Subroutines and Functions

    Greatest Common Divisor

    Problem 5.1:

    Minimum Value Computation

    Problem 5.2:

    Perfect Square Computation

    Problem 5.3:

    Matrix transposition

    Problem 5.4:

    Connectivity of a Graph

    Problem 5.5:

    Exercises

    Chapter six

    Recursive Subprograms

    Factorial Computation

    Problem 6.1:

    Greatest Common Divisor

    Problem 6.2:

    Fibonacci Series

    Problem 6.3:

    Recursion with Two Functions

    Problem 6.4:

    Hamiltonian Path Search

    Problem 6.5:

    Exercises

    APPENDIX I

    APPENDIX II

    Index

    Chapter one

    An Introduction to Solving Problems

    Some Common Problems and Procedures

    In daily life we follow so many procedures that they get built into our subconscious and we fail to recognize them as instructions meant for solving problems. Most of these procedures have been taught to us at school and at home. Some have been learned by trial-and-error or by experience. Rather than addressing procedures in the abstract, let us consider a few problems and some common ways of solving them.

    Example 1.1:

    Problem

    : Putting on a pair of shoes and socks

    Procedure

    : (a) Select a pair of matching socks.

          (b) Put the left sock on the left foot, and the other sock on the right foot.

          (c) Select a pair of matching shoes of the correct size.

    The shoes must also match the color of the socks.

          (d) Put the left shoe on the left foot, and the other shoe on the right foot.

          (e) If the shoes have laces, tie them properly.

    This procedure is so simple that discussing it further seems absurd. However, simple thought it may be, it reveals a very important characteristic of procedures, namely, the importance of doing things in their proper sequence.

    Some results of not following the procedure are:

    Some of these might be your objective, for example if you are auditioning for a circus. In that case you would be following another procedure anyway.

    Example 1.2:

    Problem

    : Making lentil soup.

    Procedure

    : (a) Add 1 liter of water and 1 cup of lentils in a large pot.

          (b) Boil for 10 minutes.

          (c) Add 1 chopped carrot and 1 chopped onion.

          (d) As long as not cooked. repeat steps (d1) and (d2):

    (d1) Keep boiling. Stir.

    (d2) Add more water if soup thickens too much.

          (e) Add 1 teaspoon (4 c.c.) of salt.

          (f) Add other spices.

          (g) Cook 2 more minutes and keep stirring.

    Once again we note the importance of doing things in the correct sequence. Obviously, exchanging steps (c) and (g) will produce soups containing raw carrots and onion.

    Step (d) illustrates the concept of indefinite iteration, that is, steps (d1) and (d2) must be repeated as long as the soup is not cooked. Step (d) may be replaced by the following sequence (d’) if it is known that sub-steps (d1) and d2) have to be repeated for only 20 minutes.

    (d’) Repeat for 20 minutes:

    (d1) Keep boiling. Stir.

    (d2) Add more water if soup thickens too

    Enjoying the preview?
    Page 1 of 1