Programming with Structured Flowcharts and Essential Python
()
About this ebook
Related to Programming with Structured Flowcharts and Essential Python
Related ebooks
Problem Solving in C and Python: Programming Exercises and Solutions, Part 1 Rating: 5 out of 5 stars5/5Basic Exercises for Competitive Programming: Python Rating: 0 out of 5 stars0 ratingsPython An Introduction Rating: 0 out of 5 stars0 ratingsLearn Python Programming the Easy and Fun Way Rating: 1 out of 5 stars1/5TouchCode Class 8 Rating: 0 out of 5 stars0 ratingsPython Programming Concepts Rating: 0 out of 5 stars0 ratingsEmployability Skills: Brush Up Your Business Studies Rating: 0 out of 5 stars0 ratingsPython. Easy Steps to Learning. Rating: 0 out of 5 stars0 ratingsAccounting, Maths and Computing Principles for Business Studies V11 Rating: 0 out of 5 stars0 ratingsUniversal Languages Introduction Rating: 3 out of 5 stars3/5Praxis Core 2023-2024 For Dummies Rating: 0 out of 5 stars0 ratingsADVANCED COLLEGE ALGEBRA STUDY GUIDE Rating: 0 out of 5 stars0 ratingsPennsylvania PSSA Grade 8 Math Rating: 1 out of 5 stars1/5Python Handbook For Beginners. A Hands-On Crash Course For Kids, Newbies and Everybody Else Rating: 0 out of 5 stars0 ratingsC Language for Beginners with Easy Tips of C Basic Programming Rating: 0 out of 5 stars0 ratingsSAT Math Workbook Rating: 2 out of 5 stars2/5An Introduction to SAGE Programming: With Applications to SAGE Interacts for Numerical Methods Rating: 0 out of 5 stars0 ratingsFoundations of Computing: Essential for Computing Studies, Profession And Entrance Examinations - 5th Edition Rating: 0 out of 5 stars0 ratingsLearn to Code with C: Program with the world's most popular language on your Raspberry Pi Rating: 5 out of 5 stars5/5Practice Makes Perfect Pre-Algebra Rating: 5 out of 5 stars5/5Algebra & Trigonometry II Essentials Rating: 4 out of 5 stars4/5Basics of Python Programming: Embrace the Future of Python Rating: 0 out of 5 stars0 ratingsPython from the Very Beginning Rating: 0 out of 5 stars0 ratingsEthical Hacking: A Beginners Guide To Learning The World Of Ethical Hacking Rating: 3 out of 5 stars3/5Programming Concepts in Python Rating: 0 out of 5 stars0 ratingsPractice Makes Perfect Algebra II Rating: 0 out of 5 stars0 ratingsSchaum's Outline of Programming with C++ Rating: 0 out of 5 stars0 ratingsAdvanced college algebra study guide Rating: 0 out of 5 stars0 ratings
Programming For You
HTML in 30 Pages Rating: 5 out of 5 stars5/5SQL QuickStart Guide: The Simplified Beginner's Guide to Managing, Analyzing, and Manipulating Data With SQL Rating: 4 out of 5 stars4/5Python: Learn Python in 24 Hours Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 4 out of 5 stars4/5Excel 101: A Beginner's & Intermediate's Guide for Mastering the Quintessence of Microsoft Excel (2010-2019 & 365) in no time! Rating: 0 out of 5 stars0 ratingsCoding with JavaScript For Dummies Rating: 0 out of 5 stars0 ratingsPython Programming : How to Code Python Fast In Just 24 Hours With 7 Simple Steps Rating: 4 out of 5 stars4/5SQL All-in-One For Dummies Rating: 3 out of 5 stars3/5Learn to Code. Get a Job. The Ultimate Guide to Learning and Getting Hired as a Developer. Rating: 5 out of 5 stars5/5Excel : The Ultimate Comprehensive Step-By-Step Guide to the Basics of Excel Programming: 1 Rating: 5 out of 5 stars5/5Python Data Structures and Algorithms Rating: 5 out of 5 stars5/5C Programming Language Essentials Rating: 4 out of 5 stars4/5Linux: Learn in 24 Hours Rating: 5 out of 5 stars5/5Automate the Boring Stuff with Python, 2nd Edition: Practical Programming for Total Beginners Rating: 4 out of 5 stars4/5C All-in-One Desk Reference For Dummies Rating: 5 out of 5 stars5/5Spies, Lies, and Algorithms: The History and Future of American Intelligence Rating: 4 out of 5 stars4/5Coding All-in-One For Dummies Rating: 0 out of 5 stars0 ratingsMicrosoft 365 Business for Admins For Dummies Rating: 0 out of 5 stars0 ratingsLearn PowerShell in a Month of Lunches, Fourth Edition: Covers Windows, Linux, and macOS Rating: 5 out of 5 stars5/5
Reviews for Programming with Structured Flowcharts and Essential Python
0 ratings0 reviews
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.
[email protected] Krishna Kumar Agarwal
[email protected] 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