COMPUTER PROGRAMMING
1. INTRODUCTION
Modified and Presented by: Dr.Yassamin Khalid
Written by: Mr. Aza Hani Shukri
Civil Engineering Department, UoD.
Wed 4TH APRIL 2018 PRESENTATION’S OBJECTIVES
Introduction:
1-Questionnaire 2-Definitions 3-User, Program and Programmer Relationship
Programming Languages: History and Parts
Why Do Engineers Need to Study Programming
Programming Steps and an Illustrated Example
Algorithms: Example 1, Example 2, Example 3
Flow Charts: Example 1, Example 2, Example 3
Course Information: Goals, Grading Model, Recommended References, The Course Work and Course
Outlines
General Notes
2
QUESTIONNAIRE
What is a computer program?
What is computer programming?
3
DEFINITIONS
A program is a sequence of instructions that tell a computer
to do a particular task.
A program is a set of step-by-step instructions that directs
the computer to do tasks that are wanted to be done and
produce the required results.
Programming is creating a sequence of instructions to enable
the computer to do something.
4
USER, PROGRAM AND PROGRAMMER RELATIONSHIP
A user is a person or group of persons that use a computer program.
USER PROGRAM PROGRAMMER
INPUT
CODING
OUTPUT
5
PROGRAMMING LANGUAGE
A programming language is an artificial language
designed to communicate instructions to a
machine, particularly a computer.
It’s a set of rules that provide a way of telling a
computer what operations to perform
6
PROGRAMMING LANGUAGE HISTORY
1-Low-Level languages 2- High-Level languages
Programming languages are called "lower" or "higher," depending on how close they are to the language
the computer itself uses or to the language people use
A computer program is generally written by a high level language
compilers.
Interpreter
7
PROGRAMMING LANGUAGE PARTS
Syntax: grammar rules for defining legal statements – what's grammatically legal?
Semantics: what things mean – what do they compute?
Statements: instructions that say what to do – compute values, make decisions, repeat sequences of
operations
Variables: places to hold data in memory while program is running – numbers, text
Most languages are higher-level and more expressive than the assembly language( Environment “editor,
compiler, debugger, builder… etc”)
8
WHY DO ENGINEERS NEED TO STUDY PROGRAMMING
1- Simplify and speed up specific tasks at work.
2- Programming is a necessary tool in research.
3- Modern-day science and engineering is all about processing,
analyzing, and extracting insights from data.
9
PROGRAMMING STEPS
1 2 3 4 5
• Clarify the • Design a • Code the • Test the • Document
problem solution program program and
maintain
the
program
10
PROGRAMMING STEPS
What is the problem?
What are the desired inputs? What form are they in?
2 3 3 3
1.Clarify • What
Designare
a the required outputs?
• Code the In what
• Test the form •will they be?
Document
the solution program program and
problem maintain
the
program
11
PROGRAMMING STEPS
Write down the necessary steps to accomplish
1 3 the program 3goals (How to turn
3 inputs to the
• Clarify the outputs).
• Code the • Test the • Document
problem 2. Design program program and
a solution Use an algorithm or flow chart.maintain
the
program
12
PROGRAMMING STEPS
Use the programming language
syntax to write the program in the
1 2 3 3
computer.
• Clarify the • Design a 3. Code • Test the • Document
problem solution the program and
program maintain
the
program
13
PROGRAMMING STEPS
Run the program and test it for selected cases and
values. Explore all the possibilities and eliminate
1 2 3 3
bugs. • Clarify the • Design a • Code the • Document
problem solution program 4.Test the and
program maintain
the
program
14
PROGRAMMING STEPS
Document your program.
Use
1 remarks (comments)
2 to explain
3 the various steps
3 of your
• Clarify the
program. • Design a • Code the • Test the
problem solution program program 5.Document
and maintain
the program
15
ILLUSTRATED EXAMPLE
Example: Write a program that calculates the area of any circle given its
diameter.
16
ILLUSTRATED EXAMPLE
STEP 1: Clarify the problem
What is the problem (program goal):
Find the area of a circle of given diameter.
Diameter (D)
What are the inputs?
The diameter of the circle (D) in certain units.
What are the desired outputs? Area (A) in square units
The area of the circle (A) in squared units.
17
ILLUSTRATED EXAMPLE
STEP 2: Design a solution
Get the value of D (input)
Set the value of Pi=3.14159265
Calculate the area of the circle A=Pi * D2/4 Diameter (D)
Display the value of A (output)
Area (A) in square units
A=Pi * D2/4 18
ILLUSTRATED EXAMPLE
STEP 3: Design a solution
Dim D as Double, A as Double, Pi as Double
Pi=3.14159265 Diameter (D)
D=InputBox(“Enter the Diameter”)
A=Pi*D^2/4
MsgBox(A)
Area (A) in square units
19
ILLUSTRATED EXAMPLE
STEP 4: Test the program
STEP 5: Document and maintain the program
Diameter (D)
Area (A) in square units
20
ALGORITHMS
In programming, algorithms are the set of well defined instructions in sequence to solve a program.
To write A good algorithm:
1-Inputs and outputs should be defined precisely.
2-Each step in an algorithm should be clear and unambiguous.
3-The algorithm should be the most effective among many different ways to solve a problem.
4-An algorithm should not have computer code. Instead, the algorithm should be written in such a way
that, it can be used in similar programming languages.
21
SOURCE: http://www.programiz.com/article/flowchart-programming
ALGORITHM EXAMPLE I
Write an algorithm to add two numbers entered by user.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
22
Step 6: Stop SOURCE: http://www.programiz.com/article/flowchart-programming
ALGORITHM EXAMPLE II
Write an algorithm to find the largest among three different numbers entered by user.
Step 1:
Start
Step 2:
Declare variables a,b and c.
Step 3:
Read variables a,b and c.
Step 4:
If a>b
If a>c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b>c
Display b is the largest number.
Else 23
Display c is the largest number.
Step 5: Stop SOURCE: http://www.programiz.com/article/flowchart-programming
ALGORITHM EXAMPLE III
Write an algorithm to find all roots of a quadratic equation ax2+bx+c=0.
Step 1: Start
Step 2: Declare variables a, b, c, D, x1, x2, rp and
ip;
Step 3: Calculate discriminant
D←b2-4ac
Step 4: If D≥0
r1←(-b+√D)/2a
r2←(-b-√D)/2a
Display r1 and r2 as roots.
Else
Calculate real part and imaginary part
rp←b/2a
ip←√(-D)/2a
24
Display rp+j(ip) and rp-j(ip) as roots
Step 5: Stop
SOURCE: http://www.programiz.com/article/flowchart-programming
FLOWCHARTS
Definition: A flowchart is a diagrammatic representation of an algorithm. Flowchart are very helpful
in writing program and explaining program to others.
25
SOURCE: http://www.programiz.com/article/flowchart-programming
FLOWCHART ELEMENTS
Symbol Purpose Description
Flow line Used to indicate the flow of logic by connecting symbols.
Terminal(Stop/Start) Used to represent start and end of flowchart.
Input/Output Used for input and output operation.
Processing Used for arithmetic operations and data-manipulations.
Used to represent the operation in which there are two alternatives,
Decision
true and false.
On-page Connector Used to join different flow line
Off-page Connector Used to connect flowchart portion on different page.
26
Used to represent a group of statements performing one processing
Predefined Process/Function
task.
SOURCE: http://www.programiz.com/article/flowchart-programming
27
FLOWCHART EXAMPLE I
Draw a flowchart to add two numbers entered by user.
28
FLOWCHART EXAMPLE II
Draw flowchart to find the largest among three different
numbers entered by user.
29
FLOWCHART EXAMPLE III
Draw a flowchart to find all the roots of a quadratic
equation ax2+bx+c=0
30
COURSE INFORMATION
31
COURSE INFORMATION: -GOALS
At the end of this course the students will:
Understand the significant importance of computer programming for engineers.
Analyse a given problem using algorithms and flowcharts.
Learn the basic syntax of Visual Basic for Applications (VBA).
Independently develop computer programs using the VBA in Microsoft Excel.
32
COURSE INFORMATION:- GRADING MODEL
Item Grade Remarks
Homework Assignments 10 Minimum of 3 assignments.
Assessed on the basis of attendance to classes and completion
Class Activities 10
of classwork tasks.
Quizzes 10 Daily unannounced short quizzes (5-10 minutes)
Mid-Semester 30 Theory and practice combined.
Final Exam 40 Theory and practice combined.
Course Total 100
* This distribution is subject to change. The student will be notified if changes occurred.
33
COURSE INFORMATION: -RECOMMENDED REFERENCES
The recommended references for the course are:
1. John Walkenbach, “Excel VBA Programming for Dummies”, 2nd Edition, 2010.
2. John Green et al, “Excel® 2007 VBA Programmer’s Reference”, 2007.
3. Excel VBA Programming, http://homeandlearn.org/
34
COURSE INFORMATION :-THE COURSEWORK
Work in the laboratory will be graded.
Quizzes are expected in every lecture/laboratory session and they will be graded.
Homework assignments will be graded.
Avoid plagiarism.
35
COURSE INFORMATION :-THE COURSE OUTLINES
Download course book.
Browse reference.
Submit assignments.
36
GENERAL NOTES
Always have a notepad and a pen ready during sessions.
Start practice right after the lecture.
Prepare your computer for the course
1. Control Macro Settings:
Go to Excel Options Trust Center Trust Center Settings Macro Settings Disable all macros with
notification.
2. Display the Developer Tab
Go to Excel Options Customize Ribbon check Developer under the Main Tabs list.
37
38