Professional Documents
Culture Documents
The problem solving process starts with the problem specification and ends with a concrete (and
correct) program.
The steps to do in the problem solving process may be: problem definition, problem analysis,
algorithm development, coding, program testing and debugging, and documentation.
The stages of analysis, design, programming, implementation, and operation of an information
system forms the life cycle of the system.
We briefly describe the steps in problem solving process by using a programming environment (it
can allow the around application programming by the possibility of generating programs from
general templates, for example) and by considering only a specific process from the whole system.
In this context the stages can be:
1st. Defining/Specifying the problem [Theme]
2nd. Analyzing the problem [Analysis]
3rd. Algorithm development
4th. Coding (or programming)
5th. Testing and debugging
6th. Documenting the program
7th. Integrate the program in the data process flow (Implementation)
- flowchart - a graphical representation that uses graphic symbols and arrows to express the
algorithms.
After you write the algorithm you must realize step-by-step simulation of the computer execution of
the algorithm in a so called desk-check process (verifying the algorithm).
5) Polymorphism :
Polymorphism allows routines to use variables of different types at different times. An operator or function
can be given different meanings or functions. Polymorphism refers to a single function or multi-functioning
operator performing in different ways.
Poly a Greek term ability to take more than one form. Overloading is one type of Polymorphism. It allows an
object to have different meanings, depending on its context. When an exiting operator or function begins to
operate on new data type, or class, it is understood to be overloaded.
6) Dynamic binding :
It contains a concept of Inheritance and Polymorphism.
7) Message Passing :
It refers to that establishing communication between one place to another.
Control Structures
Formulas without control structures execute each statement in the formula only once. When this happens
the formula is evaluated. The statements are executed in a sequential fashion, from the first statement in the
formula to the last. Control structures enable you to vary this rigid sequence. Depending upon which control
structure you choose, you can skip over some of the statements or repeatedly evaluate some statements
depending on certain conditions. Control structures are the primary means of expressing business logic and
typical report formulas make extensive use of them.
syntax (from Ancient Greek "arrangement" and "an ordering")
- is "the study of the principles and processes by which sentences are constructed in particular languages"
- is also used to refer directly to the rules and principles that govern the sentence structure of any individual
language
Example:
Private Sub Form_Load()
CorpName = "UNICO"
Num = 1
MsgBox CorpName & " is " & Num
End Sub
The three basic control structures are sequence, selection and repetition
Sequence means that program statements are performed one after the other in order (unless
another control structure takes precedence).
o This control structure is built in to the Visual Basic language and most other computer
languages.
Selection means that one part or another of a program is executed, based on the outcome of a test
for which part should be the one executed.
Repetition means that a part of a program is to be executed over and over until a criterion for
stopping the repetition is satisfied.
Selection
If-else-statement
Selection involves making a choice.
This is sometimes called branching (choosing one branch or the other).
Simple branching is done in Visual Basic with the If- Then-Else construct. This can be viewed as follows:
If <condition> Then
<true block>
Else
<false block>
End If
This causes the statement(s) in <true block> to be performed if <condition> is true; otherwise the
statement(s) in <false block> are performed.
The If-Then-Else implements two-way selection (branching), but often multi-way selection is required.
Consider the case of one student taking a course on a pass-fail basis,
and another student taking the course for a regular grade.
Computing the first student's grade uses simple two-way branching
The second student's requires multi-way branching.
If 60 is passing, the first student's grade can be given by:
If score >= 60 then
grade = "P"
Else
grade = "F"
End If
If-Then-ElseIf-Else statement
The second student's grade would need more complicated code.
Assume cutoff scores of 90, 80, 70 and 60
We can achieve the desired result by an If-Then-ElseIf-Else statement:
If score >= 90 Then
grade = "A"
Else If score >= 80 Then
grade = "B"
Else If score >= 70 Then
grade = "C"
Else If score >= 60 Then
grade = "D"
Else
grade = "F"
End If
The code implementing each case may be one or many statements. If the code is long or complex, a
procedure should be used.
Sometimes a rule of thumb that all cases must be implemented as procedures is followed.
Repetition
Simple repetition (looping) may be implemented in Visual Basic by the Do While construct.
The action of the Do While is as follows:
Do While <condition>
<loop body>
Loop
The above causes <condition> to be tested.
If true, the statement(s) in <loop body> are performed and <condition> is again tested.
As long as <condition> remains true, <loop body> is performed over and over.
If <condition> ever tests false, <loop body> is no longer repeated and control is transferred to the statement
after <loop body>.
Statements in <loop body> will normally cause <condition> to become false at some point, or else the loop
would continue forever.
If it does continue forever, it is called an infinite loop; this is a common programming error.
Do-Loops
The most basic form of loop in Visual Basic is the Do-Loop. Its construct is very simple:
Do
(Code to execute)
Loop
So, let's try a somewhat different approach to the Fibonacci problem. We decide that we want to calculate
only eight values of the Fibonacci series, so we'll keep a counter and increment it each time throughout the
loop. Then, once the counter reaches eight, we'll exit the loop.
Public Sub Main()
Dim X As Integer
Dim Y As Integer
Dim cnt As Integer 'Our counter.
cnt = 1
Do
Debug.Print X
X=Y+X
Y=X-Y