100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.6 TrustPilot
logo-home
Class notes

structured programming

Rating
-
Sold
-
Pages
196
Uploaded on
09-12-2024
Written in
2024/2025

Structured Programming: A Brief Overview Structured programming is a programming paradigm that emphasizes the use of well-defined control structures to create clear, understandable, and maintainable code. It emerged in the 1970s as a response to the problems associated with the unstructured and complex programming practices of the time, often leading to "spaghetti code"—code that is tangled, difficult to follow, and error-prone. The core idea of structured programming is that programs should be divided into smaller, manageable blocks (or modules), with well-defined and logical control flows. The primary focus is on improving code clarity, reducing complexity, and making the program easier to debug, maintain, and extend. Here are the key concepts of structured programming: 1. Control Structures Structured programming relies on the use of the following three basic control structures to dictate the flow of the program: Sequence: The default mode of execution, where statements are executed one after another in a linear fashion. Selection (Decision-making): This structure allows the program to make decisions based on conditions. It’s typically implemented using if, else, switch, or case statements. Example: python Copy code if condition: # code block else: # code block Iteration (Loops): Repeating a set of instructions a specified number of times or until a certain condition is met. Common loops include for, while, and do-while. Example: python Copy code for i in range(5): print(i) These three control structures—sequence, selection, and iteration—form the backbone of structured programming. They ensure that the program is easy to follow and that the flow of control is clearly defined. 2. Modularization (Subroutines/Functions) Instead of writing large, monolithic blocks of code, structured programming encourages breaking down the program into smaller, logically organized functions or subroutines. Each function should perform a specific task and be relatively independent of other functions, promoting reusability and maintainability. Functions should have well-defined inputs and outputs (parameters and return values). Each function should ideally do one thing and do it well, which makes it easier to understand and test. Example: python Copy code def add(a, b): return a + b 3. Top-Down Design Structured programming often follows a top-down approach to design, where the problem is broken down into smaller sub-problems. The design starts with the highest-level overview (the main function) and then refines it into more detailed components (individual functions or modules). This approach promotes better organization and ensures that each part of the program serves a specific, logical function. 4. Avoidance of GOTO Statements A hallmark of structured programming is the avoidance of GOTO statements (or jumps) in the code. GOTO can lead to unstructured and unpredictable control flow, making programs difficult to understand and maintain. Instead, structured programming relies on the aforementioned control structures to maintain a clear and predictable flow of execution. 5. Clarity and Readability Structured programming encourages code that is easy to read and understand. This includes: Using meaningful variable and function names. Writing comments and documentation to explain the purpose of code blocks. Following consistent indentation and formatting practices to visually distinguish the structure of the code. 6. Error Handling Error handling in structured programming is usually done using structured mechanisms, such as try-except blocks or predefined error codes, which ensures that errors are caught and dealt with in a controlled manner. Advantages of Structured Programming: Improved Readability: By using well-defined control structures and functions, the flow of the program is clear and easy to understand. Easier Maintenance: Smaller, modular pieces of code are easier to test, debug, and modify. Reduced Complexity: Structured code tends to have fewer bugs and is less prone to errors due to its organized nature. Reusability: Functions and modules can be reused across different parts of the program or in future projects. Example of Structured Programming in Practice: python Copy code # Function to calculate the area of a rectangle def calculate_area(length, width): return length * width # Main function that drives the program def main(): length = float(input("Enter the length of the rectangle: ")) width = float(input("Enter the width of the rectangle: ")) area = calculate_area(length, width) print(f"The area of the rectangle is: {area}") # Calling the main function if __name__ == "__main__": main() In this example: The program is broken into a main function and a helper function (calculate_area), making it easy to understand. The flow of control is structured: the program prompts for input, calculates the area, and outputs the result. There's no use of GOTO statements; the program follows logical control structures (sequence, selection, iteration). Conclusion Structured programming revolutionized the way software was developed, promoting clarity, simplicity, and maintainability. Its principles are still widely followed in modern programming practices, even as newer paradigms like object-oriented programming (OOP) have emerged. By adhering to structured programming practices, developers create code that is easier to read, test, and maintain, which ultimately leads to more reliable software.

Show more Read less
Institution
Course











Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Course

Document information

Uploaded on
December 9, 2024
Number of pages
196
Written in
2024/2025
Type
Class notes
Professor(s)
Unknown
Contains
All classes

Subjects

Content preview

LABAN KARIUKI STRUCTURED PROGRAMMING (C)

, CONTENTS
Module: 1
Lecture 1: A Beginner’s Guide

Lecture 2: Introduction to Programming

Lecture 3: Introduction to C, structure of C programming

Lecture 4: Elements of C

Lecture 5: Variables, Statements, Expressions

Lecture 6: Input-Output in C

Lecture 7: Formatted Input-Output

Lecture 8: Operators

Lecture 9: Operators continued…

Lecture 10: Control Statements

Lecture 11: Iterative statements

Lecture 12: Jump statements

Module: 2
Lecture 13: Function

Lecture 14: Function categories

Lecture 15: Actual arguments and Formal arguments

Lecture 16: Recursion

Lecture 17: Recursion verses Iteration

Lecture 18: Storage classes

Lecture 19: Arrays

Lecture 20: Two Dimensional Arrays

Lecture 21: Array using Function

Lecture 22: Strings

, Lecture 23: Common Functions in String



Module: 3
Lecture 24: Structure in C Union

Lecture 25: Nested Structure

Lecture 26: Union

Lecture 27: Pointers

Lecture 28: Pointers and Arrays

Lecture 29: Pointer Arithmetic

Lecture 30: Pointers and Function

Lecture 31: Dynamic Memory Allocation

Lecture 32: Pointer to Structure

Lecture 33: File

Module: 4
Lecture 34: Algorithm and Data Structure

Lecture 35: Analysis of Algorithms

Lecture 36: Storage structure of Arrays

Lecture 37: Sparse Matrices

Lecture 38: Stack

Lecture 39: Queue

References

, MODULE 1
LECTURE NOTE-1



A BEGINNER’S GUIDE
INTRODUCTION TO COMPUTERS

Any programming language is implemented on a computer. Right form its inception, to the
present day, all computer system (irrespective of their shape & size) perform the following 5
basic operations. It converts the raw input data into information, which is useful to the users.

 Inputting: It is the process of entering data & instructions to the computer system.
 Storing: The data & instructions are stored for either initial or additional processing,
as & when required.
 Processing: It requires performing arithmetic or logical operation on the saved data
to convert it into useful information.
 Outputting: It is the process of producing the output data to the end user.
 Controlling: The above operations have to be directed in a particular sequence to be
completed.

Based on these 5 operations, we can sketch the block diagram of a computer.




Fig 1: Block Diagram of a Computer

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
Nechemia17 Campbell University
Follow You need to be logged in order to follow users or courses
Sold
139
Member since
4 year
Number of followers
124
Documents
1884
Last sold
7 months ago
BEST HOMEWORK HELP AND TUTORING ,ALL KIND OF QUIZ or EXAM WITH GUARANTEE OF A

WELCOME TO MY WORLD, GET ALL KIND OF EXAMS ON THIS PAGE, COMPLETE TEST BANKS, SUMMARIES,STUDY GUIDES, PROJECT PAPERS, ASSIGNMENTS, CASE STUDIES AND YOU CAN ALSO COMMUNICATE WITH THE SELLER FOR ANY PRE WORK EXAMS, I ASSURE YOU A SATISFACTORY WORK IF YOU WILL USE MY WORK.

3.9

20 reviews

5
11
4
1
3
5
2
1
1
2

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Frequently asked questions