You are on page 1of 26

Preparing to Program

Daniel M. Ahiatrogah
Regent University College of Science and Technology
Sept. 2013
Introduction
First design the program you want to write.
Well designed program enable the
programmer to develop the software both on
time and on budget.
A good design makes for a program that is
relatively bug-free and easy to maintain.
A good design therefore, reduces the cost of
debugging and maintenance.

Regent University College 2


Programmers Questions
The first question by a programmer when
preparing to design a program is, Which
problem is the program going to solve?
Every program should have a clear, well-
articulated goal. The purpose should be to
solve a problem.
The second question is, Can this be
accomplished without resorting to writing
custom software?
Regent University College 3
Programmers Questions
(2)
Sometimes buying a software off the shelf is
often a better solution to developing a new
one.
The Programmer that works with this
understanding will always have a work to do.

Regent University College 4


Definition of Algorithm
An algorithm is a step-by-step procedure for
calculations, in the field of Mathematics and
Computer Science.
It can be also defined as the procedure for
solving a mathematical problem in a finite number
of steps that frequently involves the repetition of
an operation.
Procedure that produces the answer to a question
or a problem in a finite number of steps. [Concise
Encyclopaedia]
Regent University College 5
Definition of Algorithm (2)
Collection of simple instructions to carry out a
task. [Ref to a program]
An algorithm is therefore a representation of a
solution to a problem.
An algorithm is simply the procedure of steps
to take and get a result.

Regent University College 6


Procedure
A procedure is a finite sequence of well-defined
instructions, each of which can be mechanically
carried out in a finite amount of time.
Can be found in the problem solution of every
problem.
In computing, problem solution is usually in the
form of a program that encompasses the
algorithm and explains to the computer a clearly
defined procedure for achieving the solution.

Regent University College 7


Categories of Algorithm
Decision Procedure
An algorithm that produces a yes or no answer.
Computation Procedure
One that leads to a solution. In order ways, the
application of a mathematical formula.
A mathematical formula and the instructions in
a computer program are examples of
algorithms.

Regent University College 8


Uses of Algorithm
Algorithms are used for
Calculations
Computer Data Processing.
Automated Reasoning.
Algorithm Calculation
The process of transforming one or more inputs into
one or more outputs with variable change.
Simple Calculation: Eg: Adding two numbers
Complex Calculation: Eg: Adding an effect to an
image.
Regent University College 9
Uses of Algorithm
Computer Data Processing
The process of using a computer program to analyse, and
convert data into useful information.
Data Processing Systems are often referred to as
Information Systems.
Automatic Reasoning
Sub-field of Artificial Intelligence.
It is the area of computer science and mathematical logic
that has to do with the study of the different aspect of
reasoning. These produces software that allows
computers to reason completely and automatically.
Regent University College 10
Importance of an
Algorithm
The combination of an algorithm and a Data
Structure makes up a program.
Data structure describes the way to represent data
for efficient insertion, retrieval, and deletion of data.
Greater percentage of time is allocated to
algorithms creation by programmers.
The remaining time is spent debugging
algorithms that do not work.

Regent University College 11


Importance of an
Algorithm
The purpose of debugging an algorithm is to
create efficient algorithm that do not waste
computer resources such as RAM and CPU
time.
Algorithms perform on data (integer or string)
differently.
Software update is an indication that the
algorithm of the previous version had bugs
that made is less efficient.
Regent University College 12
Flow Chart
Flowchart is a diagram that is used to show
the flow of processes in a program.
It is sometimes categorized into the following
components.
Document Flowchart.
Shows the control of the flow of a particular
document through system.
Data Flowchart.
Shows the controls over a data flow in a
system.
Regent University College 13
Flowchart
System Flowchart.
Shows the control over a resource through
a system.
Program Flowchart.
Shows the controls of a program within a
system. Mostly such programs are sub-
programs with the integrated programs
called a system.

Regent University College 14


Purpose of Flowchart
It is used to show control flow in a computer
program.
Show an algorithm without writing a program
code, in the form of graphical symbols.
Training beginner programmers.
NB:
Consist of unique symbols.
Each symbol defines specific functions.

Regent University College 15


Flowchart Symbol
Start
Used to start the flowchart/program.
Symbol used is in the form of an eclipse or a
rounded square.
Arrows
Represent the flow of control in the program.
It shows which command is next to be executed.
Rectangle
Use to show computation.

Regent University College 16


Flowchart Symbol
Parallelogram
Used to receive input from user
Display output of program
Rhombus
Used for conditional flow control.
Without flow control, programs will only follow one path.
End
Shows the end of the program.
Represented by an eclipse or a rounded square.

Regent University College 17


Flowchart Symbols
Start Eclipse

Arrows

Rectangle

Parallelogram

Regent University College 18


Flowchart Symbols (2)

Rhombu
Decision Making s

Regent University College 19


Flowchart Best Practices
Used standard symbols
Keep the arrow flow to one side.
Use same size of the symbols.
Name the decision blocks and processes.
Use color schemes that are not excessive.
Use equal spacing between symbols.
Always scale your flowchart. Do not cram it on
one pages even if the writings are unreadable.

Regent University College 20


Flowchart Exercises
Draw a flowchart to sum two numbers.
Draw a flowchart to compute the average of
three numbers.
Draw a flowchart to calculate the product of
two numbers.
Draw a flowchart to calculate the simple
interest on a principal in the first year.

Regent University College 21


The Development
Environment
Programs are written in a text editor that can
save simple, plain-text files, with no word
processing commands embedded in the text.
Examples: windows notepad, DOS Edit
command, vi among others
The files you create with your editor are called
source files.
C++ source files are saved with the
extension .cpp
Regent University College 22
The Development Cycle
If a program works the first time it is
implemented then that will be the complete
development cycle.
Almost every program will have errors, or
bugs which must be fixed.
Fixing of bugs is therefore a usual activity of
every programmer.

Regent University College 23


The steps in the development of
a C++ program
Start
Edit source code
Compile
Return to Edit Source Code in the case of compile error
Link
Return to Edit Source Code in the case of Link error
Run Program
Return to Edit Source Code in the case of Run-Time error.
Done

Regent University College 24


My First C++ Program
#include <stdlib.h>
#include <iostream>

using namespace std;


int main()
{
cout << "Hello World \n";
system("pause");
}

Regent University College 25


References
Sams Teach yourself C++
https://www.google.com.gh/?
gws_rd=cr&ei=Kls4UuatJoaq7QaE24CoCg#q=define+
algorithm
https://www.google.com.gh/?
gws_rd=cr&ei=Kls4UuatJoaq7QaE24CoCg#q=define+
flowchart

Regent University College 26

You might also like