Pages

Translate

Tuesday, 24 July 2012

KEYWORDS USED IN PSEUDOCODE AND SYMBOLS USED IN DRAWING A FLOWCHART

When drawing a flowchart,a set of symbols is used with each set of symbols representing an activity to be done.
The picture below shows various symbols and the activity they represent.capture-20120724-072322capture-20120724-072211capture-20120724-072040
They are other symbols also used in flowchart but rarely,these are the major ones.

Every programming language has its vocabulary and syntax used when writing in that programming language,the table below shows the keywords that are used when writing a Pseudocode .

Keywords

Usage

//
This represents a comment entry that is used to provide additional information about the steps in the pseudocode
begin……end
The first statement in a pseudocode is a ‘begin’ and the last an ‘end’.The steps of the pseudocode comes between the begin….end block.
accept
This simply accepts an input.for example to accept the number 10,the following statement can be used:
accept 10
compute
This is used to calculate the result of an expression,for example to calculate the product of two numbers:
compute product as 5 * 5
display
it is used to display an output,for example to display the number ‘25 ‘:
display 25
if…..else
This is used when,depending on on a condition,different actions may have to be taken.
repeat…..until
This is an iterative construct with a testing statement at the bottom of the iterative set of statements.
while
This is an iterative construct with a testing statement at the top of the iterative set of statements
for( ; ; )
This is an iterative construct in which a variable is initialized,incremented and an expression is tested in the same line

Monday, 18 June 2012

Guidelines For Writing Algorithms,Pseudocode And Flowcharts

Here are a few guidelines that will help you in writing an efficient algorithm:

  • An expected output should be decided by the programmer before writing an algorithm.
  • Each step in an algorithm should be written clearly,stating each task to be performed.
  • To be sure that the algorithm produces the expected output,it should be checked using sample values.
And a couple too for writing pseudocode,

  • Statements that are related should be combined to avoid writing a lengthy pseudocode. For example,
          display "Enter first number"
          accept number1
          display "Enter Second number"
          accept number2

The statements above make the for a lengthy pseudocode,it can be shortened by combining the statements. For example:
         display "Enter two numbers"
         accept number1,number2

  •  The pseudocode should be aligned properly for a clear understanding of the steps carried out.
Here are also rules recommended by the American National Standard Institute (ANSI) that are to be followed when drawing a flowchart.

  • The entire logic of a flowchart should be represented using standard symbols.
  • The flowchart should be clear,precise and easy to follow.
  • The flowchart should have only one start point and one end point.
  • The steps in a flow chart should follow top-to-bottom or left-to-right approach.
  • All necessary inputs should be listed in logical order.
  • The start and stop symbols should have only a single flow line.
  • The input,process,output and display symbols should have at least two flow line connecting to the previous symbol and to the next symbol.
  • The decision symbol should have one flow line flowing into it and two flow lines flowing out of it for each possible decision.
  • Flow charts should use page connectors if they extend over multiple pages.
  • It is useful to text the logic of the flowchart by texting the flowchart using some sample values.........


Monday, 11 June 2012

Tools Used In Problem Solving (Pseudocode & Flowcharts)

Carrying on from where i left off with the last post where i talked about algorithm,i'll be looking at pseudocode and flowcharts. Two more tools used in problem solving when it comes to Logic building.

PSEUDOCODE:
The pseudocode is a detailed readable description of what an algorithm must do,expressed in a formally styled natural language rather than a programming language.
It is easy and fast to write since it uses english statements and can easily be converted to a program using any programming language but it might also be difficult to understand the complex logic in a pseudocode as it does not provide a graphical representation of an algorithm like the flowchart does.

FLOWCHARTS:
A flowchart can simply be defined as the graphical representation of an algorithm. It uses symbols to represent the activities depicted in an algorithm. It also requires the I-P-O cycle to solve problems,but here the processing would involve the computations and the decisions that are been taken.
The flowchart helps in analyzing the problems effectively and act as a guide during the program development phase. However it can be time consuming and a lengthy flowchart may extend over multiple pages which reduces readability. One should also be carful to avoid mistakes as a change made to a single step may cause redrawing the entire flow chart.
One will know the symbols used when preparing a flow chart and their meanings if your familiar with microsoft office.
Here's an example of an algorithm that displays the sum of two numbers presented in both pseudocode and flowchart.

ALGORITHM                                           PSEUDOCODE PRESENTATION
STEP 1:Start the algorithm                          Begin
STEP 2:Get the first number                            Accept firstnumber
STEP 3:Get the second number                       Accept secondnumber        
STEP 4:Add the two numbers                         Compute sum as firstnumber +
STEP 5:Display the result                                + secondnumber
STEP 6:End the algorithm                               Display Sum
                                                                  End
FLOWCHART PRESENTATION


.
Please it should be noted that these examples i've given are without variables.....till next time.

Wednesday, 6 June 2012

Logic Building: Tools Used For Problem Solving (Algorithm)

We already know what programs and programming languages are from my last post. Now we'll talk about problem solving. The procedures to solve a problem can be represented by using any of these:

  • Algorithm
  • Flowchart
  • Pseudocode
ALGORITHM: When we hear algorithm,numbers and calculations are the first things that come to mind right?. It's quite the opposite,an algorithm is a sequence of steps required to solve a problem,it is a list of well defined instructions to solve a given problem.Here's an example of an algorithm that displays the subtraction of two numbers:


STEP 1: Start the algorithm
STEP 2: Get the first number
STEP 3: Get the second number
STEP 4: Subtract the two numbers
STEP 5: Display the result
STEP 6: End the algorithm


Of the three procedures used in problem solving,the algorithm is quite simply the easiest one.The algorithm follows the I-P-O cycle to solve a problem. Here the inputs are the numbers,these inputs are accepted and then the process of subtraction takes place. When the processing is done,the result which is the output is then displayed.
According to D.E Knuth,an algorithm should have the following characteristics:

  • An algorithm ends after a fixed number of steps.
  • Each step in an algorithm clearly specifies the action to be performed.
  • The steps in algorithm specifies basic operations,these could include calculations,input/output operations and comparisons.
  • An algorithm accepts input data in a defined format before it can be processed.
  • An algorithm can generate one or more outputs after the input is processed. The resulting information termed as output can be displayed or stored for further references.
I will talk about Pseudocode and Flowcharts in my next post.......Until Then........





Saturday, 2 June 2012

Logic Building: Programs And Programming Languages

Logic building is all about laying a strong foundation in programming language,it's a programming concept one should be familiar with before working on any programming language. Understanding logic will help with ones ability to apply the appropriate logic and technique to solve a given problem in programming.
First the basics.What is a computer ?
A computer can simply be defined as an electronic device used for storing and processing information.
A computer is designed to accept input,process it and generate an output,which means a computer carries out tasks in phases. For example,to check your account balance on your mobile device,a certain code is keyed into the mobile device. This is called the input phase. The information is then processed to determine your balance. This is known as the process phase. Once the processing is complete,the result is displayed on your screen showing your account balance. This is called the Output phase. This cycle of activities is also known as the I-P-O- cycle.
                                                                   The I-P-O Cycle
However for the I-P-O Cycle to be complete,the computer has to be provided with a set of instructions that will specify the kind of input that will be provided,the processing that needs to be done and the kind of output expected. This set of instructions are known as wwwwwwwwwwwwwwwwwwwwwwwprograms.

PROGRAMS
Programs are set of instructions a computer needs to perform a particular task,mainly input,processing and output activities.therefore for each task you'd like to run you would need a set of program.Instructions in a program can be any of the following:


  • Iterative: These instructions are executed repeatedly,depending on the value of an expression (relation or condition)
  • Sequential: These are instructions that are executed one after the other.
  • Decision Making: These instructions first evaluate an expression (relation or condition) and then depending on the value of the expression whether true or false,it transfers the control to a particular statement.
NOTE: An Application is a collection of programs working together to solve a problem.



PROGRAMMING LANGUAGE
A programming Language like any other language is meant for communication,it's a language designed to communicate instructions to a computer as well as other machines.A computer only understands the Machine Language which uses the binary system that consist of two digits, "0 and 1". However to communicate and relay information to a computer we use High Level Language which consist of a set of instructions using simple English words.
Just as with real languages,programming languages has its own set of vocabulary and grammar rules. The vocabulary of the programming language is referred to as the set of keywords of that language,and the grammar is referred to as the syntax. Example of level programming languages are C,C++,Javascript and SQL.
It is also important to note that for each programming language there is a different compiler. Compilers are special programs that processes the statement written in a particular programming language and converts them into machine language for the computer to understand,this process of conversion is known as compilation. For example you would need a java compiler for the compiling of a java program.