Rajarata University of Sri Lanka 1
Department of Computing
COM1407
Computer Programming
T.C IRUGALBANDARA
2
Course Content
Fundamentals of C Programming: Structure of a C
Program, Input/Output, Variable Declaration,
Arithmetic Operations, Relational Operations,
Logical Operations. Control Structures: If/Else, While
repetition, For repetition, Switch multiple selection,
Do/While, Break and Continue, Functions, Scope of
Variables and Parameters, Recursion, Arrays,
Records, File processing, Comparison of structure
and class, Pointers, Dynamic memory allocation,
Pointers to functions.
3
Corse Learning Outcomes
At the end of this course, students should be able to:
Analyze a given problem (KS)
Design an algorithm to the given problem (KS)
Implement the algorithm using a programming
language (KS)
Apply best practices in programming (KSAM)
Test the implemented solution (KS)
4
Methodology:Lectures (45 Hours), Practical (45
Hours).
Lectures
Practical
5
Evaluation Criteria:
Continuous Assessments:
Assignments (Practical) 10%
Mid Examinations 10%
Final Exam:
Practical (20%),
Theory (50%)
Rajarata University of Sri Lanka 6
Department of Computing
COM1407
Computer Programming
LECTURE 01
STRUCTURED PROGRAM DEVELOPMENT
7
Objectives
At the end of this lecture students should be able to;
Define fundamentals of data processing in computer.
Define fundamental terms in computer programming.
Define the phases of program development life cycle.
Define structured program theorem.
8
What is a Computer?
A computer is a machine which can take
instructions (data) as input, perform computations
based on those instructions (process) and generate
results a.k.a output (information).
9
What is a Computer? (Cont…)
10
What is a Computer? (Cont…)
11
Machine Language
Machine Language is the only language that is
directly understood by the computer.
It does not needs any translator program.
The only advantage is that program of machine
language run very fast.
Each different type of CPU has its own unique
machine language.
12
Machine Language (Cont…)
13
What is a Computer Program?
A computer program is a collection of instructions
that performs a specific task when executed by a
computer.
A computer requires programs to function, and
typically executes the program's instructions in a
central processing unit.
A computer program is usually written by a
computer programmer in a programming
language.
14
What is a Programming
Language?
A programming language is a formal computer
language designed to communicate instructions to
a machine, particularly a computer.
Programming languages can be used to create
programs to control the behavior of a machine or to
express algorithms.
15
From Program To Software
A collection of computer programs, libraries and
related data are referred to as software.
Computer programs may be categorized along
functional lines, such as application software or
system software.
Application Software is a set of programs for a specific
application.
System software are general programs designed for
performing tasks such as controlling all operations
required to move data into and out of the computer
16
Program Development Cycle
Review the
Specification
Maintain Informal Design
Test Formal Design
Code &
Compile
17
Review Specification
In this phase, we define the problem statement and
we decide the boundaries of the problem.
When you review the specification, ask yourself;
Do you understand what is required?
Do you have sufficient instruction to carry it out?
Do you have the necessary input available to
generate the desired output?
18
Case Study
Read the following case study carefully.
19
Informal Design
Addresses WHAT need to be done.
Do experiment on variety of possible solutions and
then decide on a general approach, before you
formalize those ideas in a design.
The informal design step lets you make changes in
your plan before you invest too much time in one
approach.
There are two steps in the informal design that need
to be completed frequently in a repeated cycle.
List the major tasks
List the subtasks
20
Informal Design (Cont…)
List the major tasks
Identify the high level tasks that needed to reach the
expected output.
List the sub tasks
Now, go back to each major tasks, one at a time, and list
the subtasks for each major task.
Once you have completed the major tasks and sub
tasks list, you should figuratively step back a bit, re-read
the specifications, and make sure you have met all the
requirements in the specifications. If not go for
modifications.
Remember, you are not committed to the first attempt
and frequently the first attempt will not be the best
solution.
21
Informal Design (Cont…)
Play with your lists a bit until you are
satisfied that you have included
everything in a logical approach.
Keep in mind that there is no single,
right answer.
22
Case Study (Cont…)
Task List for “MS Fly Miles” Case Study
23
Formal Design
It takes the lists and puts them into a recognized
format that others could easily read and use.
Formal design addresses HOW it will be done.
Formal design is a communication tool for program
designers and coders.
Eventually the formal design will become a part of
the program’s documentation package that will
stay with the program as long as it is in use.
There are many possible program design tools
available and this course will concentrate on two of
them namely; Flowcharts and Pseudocodes.
24
Formal Design (Cont…)
Desk check the design
Desk checking is the way to check the logic of the
design.
You will work through the design, step by step,
implementing each step as the computer would,
reading the test data, doing any calculations, and
writing output.
This will tell you if there are any logic errors before you
invest the time in coding. (assuming you have created
good test data.)
If you have errors, go back to the task list, make the
necessary changes, implement those changes in
formal design, and try the desk checking again.
25
Formal Design (Cont…)
The informal design
and formal design
are really a cycle
that you perform
until your desk
checking tells you
the logic is perfect.
26
Code & Compile
Coding the program is simply translating each design statement into
the proper syntax for the desired programming language.
• In this phase, we construct
actual program.
• That means we write the
program to solve the given
problem using programming
languages like C, C++, Java
etc.
27
Test
During this phase, we check whether the code written in previous
step is solving the specified problem or not.
• That means we test the
program whether it is solving
the problem for various
input data values or not.
• We also test that whether it
is providing the desired
output or not.
28
Test (Cont…)
All those other
Programmers who did not
plan ahead frequently
spend most of their
program development
time trying to get the
“BUGS” out of their
programs.
29
Maintenance
During this phase, the program is actively used by
the users.
If any enhancements found in this phase, all the
phases are to be repeated again to make the
enhancements.
That means in this phase, the solution (program) is
used by the end user.
If the user encounters any problem or wants any
enhancement, then we need to repeat all the
phases from the starting, so that the encountered
problem is solved or enhancement is added.
30
The Structure Theorem
The structure theorem forms the basic framework for
structured programming.
It states that it is possible to write any computer
program by using only three basic control structures
such as:
Sequence
Selection and
Repetition / Iteration
31
Sequence
The sequence control structure is the straight
forward execution of one processing step after
another.
E.g.
Statement 1
Statement 2
Statement 3
Sequence instructions will be executed in the order
in which it appears.
32
Selection
The selection control structure is the presentation of
a condition and the choice between two actions,
the choice depending on whether the condition is
true or false.
This construct represents the decision making
abilities of the computer.
After processing selection part control is passed to
the next processing step.
33
Repetition
The repetition control structure can be defined as
the presentation of a set of instructions to be
performed repeatedly, as long as a condition is true.
After processing repetition part successfully the
control is passed to the next processing.
You need to accurately write and test the accuracy
of the repetition structure because your mistake can
causes get endless repetition structures.
34
Algorithm
An algorithm is a procedure
or formula for solving a
problem, based
on conducting a sequence of
specified actions.
A computer program can be
viewed as an elaborate
algorithm.
In mathematics and
computer science, an
algorithm usually means a
small procedure that solves a
recurrent problem.
35
Objectives - Revisit
Define fundamentals of data processing in computer.
Define fundamental terms in computer programming.
Define the phases of program development life cycle.
Define structured program theorem.
36
References
Re-read COM1201 Notes
37
NEXT: INTRODUCTION
Q&A TO C PROGRAMMING
LANGUAGE