Structured Programming: Dr. Ahmed Sherif Zekri
Structured Programming: Dr. Ahmed Sherif Zekri
1
Course Goals
• Introduce General concepts of
Programming
Overview of Computer,
Programming and Problem Solving
4
Outline
• Overview of Computer, Programming and
Problem Solving
• What is Programming?
• Sample problem 5
Background
?What is a Computer
• Device capable of performing computations and
logical decisions
7
?What is Programming
8
Programming Life Cycle Phases
9
… Programming Life Cycle Phases
4. Test and verify the completed program.
• Run the program several times using different sets of data, making sure
that it works correctly for every situation in the algorithm .
• if it does not work correctly, then you must find out what is
wrong with your program or algorithm and fix it--this is called
DEBUGGING
10
Algorithm Basic Control
Structures
• a sequence is a series of statements that execute one after
another
11
Control Structures
Sequences
12
Control structures
Selection (Branching)
True Statement1
Statement
Condition ...
False Statement2
13
Control structures
Loop (Repetition)
False
...
Condition
Tr
ue
Statement
14
Control structures
Subprogram (Function)
PROGRAM1 ...
SUBPROGRAM1
a meaningful collection
of SEQUENCE,
SELECTION, LOOP,
SUBPROGRAM
15
Sample Problem
Company payroll case study
A small company needs an interactive
program to figure its weekly payroll.
16
Sample Problem
17
One Employee’s Wages
Ex1. In one week an employee works 52
hours at the hourly pay rate of 24.75. Assume
a 40.0 hour normal work week and an
overtime pay rate factor of 1.5
What are the employee’s wages?
40 x 24.75 = 990.00
12 x 1.5 x 24.75 = ___________
445.50
1435.50 18
18
One Employee’s Wages
Ex2. In one week an employee works 36
hours at the hourly pay rate of 24.75. Assume
a 40.0 hour normal work week and an
overtime pay rate factor of 1.5
What are the employee’s wages?
36 x 24.75 = 891.00
19
19
Weekly Wages, in General
If hours are more than 40.0, then
wages = (40.0 * payRate) +
(hours - 40.0) * 1.5 *payRate
otherwise,
wages = hours * payRate
21
C Program
/* ***************************************************
Payroll program
This program computes each employee’s wages and
the total company payroll
***************************************************/
22
total = 0.0 ;
printf( “Enter employee number: “); /* Prompt */
scanf(“%d” , &empNum); /* Read ID number */
23
void CalcPay ( /* in */ float payRate ,
/* in */ float hours ,
/* out */ float& wages )
24
24
Problem
• Write a program that takes the length and
width of a piece of land, and the length and
width of a house to be built inside it and
then tell you how much grass you need to
buy to cover the garden (in square meters).
25