0% found this document useful (0 votes)
17 views

MU Structured Programming Fall 2024 CH01 Introduction

Uploaded by

bdllhstudy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

MU Structured Programming Fall 2024 CH01 Introduction

Uploaded by

bdllhstudy
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Mansoura University

Faculty of Computers and Information

Structured Programming
Introduction

Dr. Mohamed Handosa


Computer Science Department
[email protected]
Introduction

Computer System Components Structured Programming


1 5

Computer system organization Unstructured Programming


2 6

Computer Software Algorithms


3 7

Programming Languages Flowcharts


4 8

2
Computer System Components

3
Computer System Components

User

Application Programs

Operating System

Computer Hardware

4
Computer System Components
Hardware
• Provides the basic computing resources for the system.
• E.g., the central processing unit (CPU), the memory, and the input/output (I/O) devices.

Application programs
• Define the ways in which these resources are used to solve users' computing problems.
• E.g., word processors, spreadsheets, compilers, and Web browsers

Operating system
• Controls the hardware and coordinates its use among the various application programs for the various users.
• E.g., Microsoft Windows, Apple iOS, Google Android.

Users
• Commonly humans but can be machines as well.

5
Computer System Organization

6
Computer System Organization

Computer
Input Devices

Processor Memory User

Output Devices

7
Computer Examples

Laptop Smartphone Desktop Computer

8
Computer Software

9
Computer Software

• A user needs computer software to use computer hardware.


• A program is a collection of instructions to perform a specific task.
• Software is a collection of programs that can perform various tasks.

User Software Hardware

10
Computer Instructions

Input Devices Input Instructions

Output Devices Output Instructions

Memory Memory Instructions

Processor Processing Instructions


11
Programming Languages

12
Programming Language

• A computer program is written by a computer programmer.


• A computer program is written using a programming language.
• There are several programming languages with different syntax.
• The programmer writes the source code representing instructions.
• The programmer must obey the rules of the programming language.
• Once the source code is ready, it can be
• Executed directly using an interpreter (e.g., Python).
• Converted into an executable program using a compiler (e.g., C++).

13
Interpreter

Source Code Source Code

Interpreter Interpreter

Programmer’s Computer User’s Computer

14
Compiler

Source
Program
Code
Program
Compiler

Programmer’s Computer User’s Computer

15
Programming Language Levels

High-Level Languages Low-Level Languages


• User-oriented • Machine-oriented
• Easier to write code • Requires detailed coding

• Example: • Example:
x = a + b LOAD r1, a
LOAD r2, b
ADD r1, r2
STORE x, r1
16
Programming Language Types

Programming
Languages

Structured Unstructured
Programming Programming
Languages Languages
17
Unstructured Programming

18
Unstructured Programming

• The code is written as a single whole block.

• The code can get very complex for big programs.

• Used in earlier versions of BASIC, COBOL, and FORTRAN.

19
Unstructured Programming

Simple Programs Big Programs

20
Structured Programming

21
Structured Programming

• The code is divided into functions or modules.

• The code remains organized even for big programs.

• Structured programming languages include C++, C#, Java, and Python.

22
Structured Programming

Program

Module 1 Module 2 … Module n

23
Structured vs. Unstructured Programming

Readability Purpose Complexity Application

Code Testing and


Modification Data Types
Duplication Debug

24
Readability

Structured Programming

• Programs are easy to read.

Unstructured Programming

• Programs are hard to read.


25
Purpose

Structured Programming

• Makes the code more efficient and easier to understand.

Unstructured Programming

• Just to creates a program to solve the problem.


• Does not create a logical structure to organize the code.

26
Complexity

Structured Programming

• Easier because of modules.

Unstructured Programming

• Harder and more complex.


27
Applications

Structured Programming

• Can be used for small and medium scale projects.

Unstructured Programming

• Not applicable for medium and complex projects.

28
Modifications

Structured Programming

• It is easy to do changes.

Unstructured Programming

• It is hard to do modifications.
29
Data Types

Structured Programming

• Uses many data types.

Unstructured Programming

• Uses a limited number of data types.


30
Code Duplication

Structured Programming

• Avoids code duplication.

Unstructured Programming

• Can have code duplication.


31
Testing and Debugging

Structured Programming

• Easy to test and debug.

Unstructured Programming

• Hard to test and debug.


32
Algorithms

33
Algorithms

• Algorithm is a set of step-by-step instructions to solve a problem.

• Humans can follow algorithms too, such as recipes for cooking.

34
Problem Solving

Inputs
• A phone book that is sorted alphabetically.
• A name to look for in the sorted phone book.
Output
• The phone number associated with the name.
• Or “Not found” if the name does not exist in the phone book.

35
Problem Solving

Algorithm 1 (correct but slow)


• Start from the first page, looking for the name one page at a time.

Algorithm 2 (fast but has a bug)


• Start from the first page, flip through the book two pages at a time.

Algorithm 3 (correct and fast)


• Open the phone book to the middle and decide which half contains the name.
• Repeat this and dividing the problem in half each time until we find the name.
• With 1024 pages to start, we will only need 10 steps to find the name if it exists.

36
Problem Solving

37
Pseudocode

• An English-language-like representation of an algorithm.


• Does not have a standard syntax and can take different forms.
• It is a compact and informal high-level description of a program.
• Not a programming language and cannot be compiled into a program.

• Example:

38
Flowchart

39
Flowchart Definition

• A flowchart is simply a graphical representation of steps.

• It uses a set of symbols that are connected using arrows.

40
Uses of a Flowchart

• It originated from computer science as a tool to represent algorithms.

• Nowadays, it has extended to other fields as it plays an important role


in displaying information and assisting reasoning.

41
Flowchart Symbols

42
Terminator

• It represents the starting or ending point of the system.

43
Process

• A box indicates some operation.

44
Decision

• A diamond represents a decision or branching point.

45
Input / Output

• It represents information entering or leaving the system.

46
Arrow

• It represents the flow of the sequence and direction of a process.

Start Stop

47
Flowchart Examples

48
Printing “Hello World” to the Screen

Start

Output “Hello World!”

Stop

49
Adding Two Numbers

Start Input x Input y

sum = x + y Output sum Stop

50
Print Grade Based on Score

Start Input score

yes No
score ≥ 50?

Output “Pass” Stop Output “Fail”

51
Print Numbers from 1 to 1000

Start x=1

yes No
x ≤ 1000?

Output x x=x+1 Stop

52
Development Environment

53
What is Visual Studio?

• An Integrated Development Environment (IDE).


• Allows a programmer to use several languages such as C#.
• Provides an environment to write code and compile it into a program.

• The C# compiler compiles the C# code into a simple language called


Common Intermediate language (CIL).

• A computer needs to have the .NET Framework to run CIL program.

54
Required Software to Develop using C#

C#
Program
Code
Program

Visual Studio .NET Framework

Programmer’s Computer User’s Computer

55
Installing Visual Studio

56
Visual Studio Installation Steps

• Go to https://visualstudio.microsoft.com/
• Select Visual Studio or Visual Studio for mac.
• Select the free community edition and download the file.
• Run the downloaded file to install the visual studio installer.
• Run the visual studio installer and select the modules to install.
• For Desktop apps, select the .NET Desktop Development module.

57
C# on Your Smartphone

Android iOS

58
Thank You

59

You might also like