Showing posts with label Introduction. Show all posts
Showing posts with label Introduction. Show all posts

Pseudo Code

Filed under , on Wednesday, January 27, 2010

2

Pseudo Code is a sequence of lines similar like programming code and doesn’t have exact rules for writing syntax. Pseudo Code is a different way to implements algorithms beside Flowchart. Pseudo Code is more commonly used by experienced programmers. While Flowchart is more understandable for beginners, Pseudo Code supports many programming features and easy to implement into real programming code rather than Flowchart.
There are no exact rules for Pseudo Code. We can write our Pseudo Code freely as long as it is easy to understand for other persons. But it is suggested to use common used keywords in programming tool (i.e. if, then, else, while, do, repeat, for and etc.) and follow certain programming style (i.e. Pascal, C++, etc.). See the code below:
   
    Program Start
    Read a number
    Read a number, store it and write it
    Get the number before and write it
    Repeat
    End Program
Although Pseudo Code above is still understandable but some statements is ambiguous. From second to forth lines, we don’t know where the number currently read store into, and we also don’t know which number is exactly for “the number before”. Is it the first number read or the second one ? And for “Repeat”, we hardly tell which lines are supposed to repeat over. Pseudo Code above is modified to a better one as follows:
   
    Start
    Repeat
       Read Number1
       Read Number2
       Display Number2
       Display Number1
    Until Number1=0
    End
Pseudo Code above is better than previous one. We clearly see where the values are stored into and which values are displayed. Repeat statements will be discussed in Week 3.
   

Algorithms

Filed under , on Sunday, January 24, 2010

0

A logical and concise list of steps required to solve a problem is called an algorithm. An algorithm is the first step in problem solving. Not only in programming world, actually have algorithms also existed in daily life. Given below is the example case in daily life:
A person wishes to book a railway ticket from Oxford to London.
The steps involved or rather the algorithm as follows:
• The passenger enters details like his name, age, the starting point of journey, destination, and the date of journey in the reservation slip.
• On submitting the slip at the reservation counter, the counter assistant checks for the availability of the seats.
• If the required number of seats is available the passenger is given a confirmed ticket.
• Otherwise, a wait-listed ticket is issued.
• A wait-listed ticket is confirmed if another person cancels his ticket.
• The passenger is given a refund if he is not given the confirmation.
Algorithms
How to Think About Algorithms

Problem Solving by Programming

Filed under , on Sunday, January 24, 2010

1

We use computers to solve problems and perform calculations. However, in order to solve a problem using a computer, we must express the solution to the problem in terms of instructions necessary to solve the specific problem.

In other words, we have to provide the computer with a set of instructions to solve the problem at hand. This set of instructions is called a program. Once we write a program to solve a specific type of problem, it can be used again and again to solve the same type of problem.

For example, if we write a program to calculate the average of the marks obtained by 100 students in a class, the same program can be reused whenever we want to calculate the average of any set of 100 students.

Problem solving is an intricate process requiring thought, planning, logical precision, persistence and attention to detail.
The computer cannot be used to solve a problem until the programmer develops a method for the solution. This method or approach used solve a problem is called an algorithm.
The following steps are involved in solving a problem:
* Studying the problem in detail
* Gathering the relevant information
* Processing the information
* Arriving at the results

The above mentioned steps can be understood well with the following example.

For example, to check if a number is even or odd, the following steps are required:
* Read the number
* Divide the number by 2
* If the remainder of the division is zero, then the number is even
* Otherwise the number is odd

With these sequences of steps in hand, we can then proceed with expressing them in the statements of a particular programming language.

Although, there are so many programming languages today with different tools, name, syntax and way to use, they are all based on three primitive fundamental: sequence, branching and looping. Sequence means all program code always run from the first line to the last line of program code. Branching means program flow can jump or skip one or more lines of program code. Looping means program flow can repeat one or more lines of program code. These fundamental will be discussed more in the next week.