You are on page 1of 11

Steps in problem solving process by using a programming environment

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)

1st. Defining/Specifying the problem [Theme] - by answering to questions as:


What the computer program do?
What tasks will it perform?
What kind of data will it use, and where will get its data from?
What will be the output of the program?
How will the program interact with the computer user?
Specifying the problem requirements forces you to state the problem clearly and unambiguously and
to gain a clear understanding of what is required for its solution.
Your objective is to eliminate unimportant aspects and to focus on the root problem, and this may not
be as easy as it sound.
2nd. Analyzing the problem [Analysis] - involves identifying the problem
(a) inputs, that is, the data you have to work with;
(b) outputs, the desired results; and
(c) any additional requirements or constraints on the solution.
3rd. Algorithm development: find an algorithm for its solution [Design]
Write step-by-step procedure and then verify that the algorithm solves the problem as intended.
The development can be expressed as:
- pseudocode a narrative description of the flow and logic of the intended program, written in plain
language that expresses each step of the algorithm;
Example:
If student's grade is greater than or equal to 60
Print "passed"
else
Print "failed"

- 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).

4th. Coding (programming)


Is the process of translating the algorithm into the syntax of a given programming language. You
must convert each algorithm step into one or more statements in a programming language.
Syntax - The arrangement of words and phrases to create well-formed sentences in a language.
5th. Testing and debugging
- testing means running the program, executing all its instructions/functions, and testing the logic by
entering sample data to check the output;
- debugging is the process of finding and correcting program code mistakes:
syntax errors;
run-time errors;
logic errors (or so called bugs).
- field testing is realized by users that operate the software with the purpose of locating problems.
6th. Documenting the program by:
internal documentation;
external documentation.
7th. Integrate the program in the data process flow (Implementation)
- use the program to solve problems [Exploitation].

OOPs Object Oriented Programming System


Object-oriented programming (OOP) is a programming paradigm that uses Objects and their interactions to
design applications and computer programs.
There are different types of OOPs are used, they are
Object
Class
Data Abstraction & Encapsulation
Inheritance
Polymorphism
Dynamic Binding
Message Passing
1) Object :
Object is the basic unit of object-oriented programming. Objects are identified by its unique name. An object
represents a particular instance of a class. There can be more than one instance of an object. Each instance
of an object can hold its own relevant data.
An Object is a collection of data members and associated member functions also known as methods.
For example whenever a class name is created according to the class an object should be created without
creating object cant able to use class.
The class of Dog defines all possible dogs by listing the characteristics and behaviors they can have; the
object Lassie is one particular dog, with particular versions of the characteristics. A Dog has fur; Lassie has
brown-and-white fur.
2) Class :
Classes are data types based on which objects are created. Objects with similar properties and methods are
grouped together to form a Class. Thus a Class represents a set of individual objects. Characteristics of an
object are represented in a class as Properties. The actions that can be performed by objects become
functions of the class and is referred to as Methods.
For example consider we have a Class of Cars under which Santro Xing, Alto and WaganR represents
individual Objects. In this context each Car Object will have its own, Model, Year of Manufacture, Colour, Top
Speed, Engine Power etc., which form Properties of the Car class and the associated actions i.e., object
functions like Start, Move, Stop form the Methods of Car Class.No memory is allocated when a class is
created. Memory is allocated only when an object is created, i.e., when an instance of a class is created.
3) Data abstraction & Encapsulation :
The wrapping up of data and its functions into a single unit is called Encapsulation.
When using Data Encapsulation, data is not accessed directly, it is only accessible through the functions
present inside the class.
Data Abstraction increases the power of programming language by creating user defined data types. Data
Abstraction also represents the needed information in the program without presenting the details.
Abstraction refers to the act of representing essential features without including the background details or
explanation between them.
For example, a class Car would be made up of an Engine, Gearbox, Steering objects, and many more
components. To build the Car class, one does not need to know how the different components work
internally, but only how to interface with them, i.e., send messages to them, receive messages from them,
and perhaps make the different objects composing the class interact with each other.
4) Inheritance :
Inheritance is the process of forming a new class from an existing class or base class.
The base class is also known as parent class or super class, the new class that is formed is called derived
class.
Derived class is also known as a child class or sub class. Inheritance helps in reducing the overall code size
of the program, which is an important concept in object-oriented programming.

It is classifieds into different types, they are

Single level inheritance


Multi-level inheritance
Hybrid inheritance
Hierarchial inheritance

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 Select Case statement


- is provided for multi-way branching when the case to be done can be represented by a numeric or string
value (or perhaps several values).
The value, computed by the program or taken from input, is called the case selector value.
A simple example is:
Private Sub Form_Click ()
selector = CInt(InputBox("Enter 1, 2 or 3:"))
Select Case selector
Case 1
Print "This is case 1."
Case 2
Print "This is case 2."
Case 3
Print "This is case 3."
End Select
End Sub
The variable selector, here an integer, is called the case selector; an expression may be used.
1, 2 and 3 are the match expressions.
The action of this example consists of performing the case whose label matches the value of selector, and
control then passes to the statement following end.
If there is no match, nothing is done and control immediately goes to the statement following End Select.
A flow chart may help to visualize this.
We can redo the grading example of the preceding section using two additional features of the Select Case
statement:
Lists of case labels are allowed.
A default case (preceded by Case Else) can be given which is performed if there is no match with a case
label.
Also, Visual Basic allows ranges; for example, 1 To 4 can be used to match any value from 1 to 4 inclusive.
Relational operators are allowed if preceded by Is, so the example becomes:
Select Case score
Case 90 To 100
grade = "A"
Case Is >= 80
grade = "B"
Case Is >= 70
grade = "C"
Case Is >= 60
grade = "D"
Case Else
grade = "F"
End Select

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

If cnt >= 8 Then


Exit Do
Else
cnt = cnt + 1
End If
Loop
End Sub
And now we're talking! This program successfully computes and prints out the first eight values of the
Fibonacci series.
Do Until
As an alternative approach to nesting an If-Statement inside the loop, and invoking Exit Do once we're done
looping, Visual Basic provides a Do Until statement. Its syntax is the following:
Do Until (Expression)
(Code to execute)
Loop
(Expression) can be any legal logical expression that we wish to evaluate to determine whether or not to exit
the loop. Each time the program reaches Loop it will evaluate this expression. If the expression is True, it will
exit the loop for us, but otherwise it will continue looping.. So let's try rewriting our Fibonacci program to use
a Do-Until loop instead of Exit Do.
Public Sub Main()
Dim X As Integer
Dim Y As Integer
Dim cnt As Integer 'Our counter.
cnt = 1
Do Until cnt >= 8
Debug.Print X
X=Y+X
Y=X-Y
cnt = cnt + 1
Loop
End Sub
Here we've replaced the hideous If cnt >= 8 Then ... Else: Exit Do with a very simple Until cnt >= 8. We
must, however, still be sure to increment our counter every time through the loop, or else the Until
expression will never be True, resulting in an infinite Do Loop.
Do While
In the place of Do Until, you can also use Do While. Its syntax is the following:
Do While (Expression)
(Code to execute)
Loop
(Expression) can be any legal logical expression that we wish to evaluate to determine whether or not to exit
the loop. Each time the program reaches Loop it will verify that this expression is True, and if it is False, it
will exit the loop for us. Thus, instead of exiting when an expression is True, it now exits only once this
expression is false. Let's try rewriting our Fibonacci program to use a Do-While loop instead of a Do-Until
loop.
Public Sub Main()
Dim X As Integer
Dim Y As Integer
Dim cnt As Integer 'Our counter.
cnt = 1

Do While cnt < 8


Debug.Print X
X=Y+X
Y=X-Y
cnt = cnt + 1
Loop
End Sub
For-Next Loops
In situations where you merely want to run the loop a predefined number of times, it can become quite
tiresome to have to create and manage a counter for each loop, which is why we also have something called
a For-Next Loop. This kind of loop allows you to specify a counter, to tell it to count from one number to
another each time through the loop, and to exit once the counter has reached its upper limit. The syntax is
as follow:
Dim I As Integer
For I = (Integer) To (Integer)
(Code to execute)
Next I
We used the variable name "I" above, as it is the most common name used for For-Loops; however, you can
use any variable name you want, so long as the variable is of the type Integer. Now, let's improve our
Fibonacci program even further:
Public Sub Main()
Dim X As Integer
Dim Y As Integer
Dim cnt As Integer 'Our counter.
For cnt = 1 To 8
Debug.Print X
X=Y+X
Y=X-Y
Loop
End Sub
In the example above, we first dimensioned cnt as an Integer, and then, in the declaration of the For-Next
loop, set its value to 1. Each time through the loop, the value of cnt was incremented by 1 until it reached 8,
at which point the loop was executed.
Exit For
As with Do Loops, there is a statement that can be used to exit a For-Next loop, and it is called Exit For.
Simply invoke this statement anywhere within a For-Next loop and the current loop will be exited.
Step
By default, the variable used in the declaration of the For-Next loop is incremented by 1 each time through
the loop; however, if you want to increment this value by a different amount each time through the loop, you
can simply append Step (Integer) to the end of the For-Next loop declaration. If, for instance, we wanted to
print out every even number counting backward from 20 to 0, we could do this using the following code:
Dim I As Integer
For I = 20 To 0 Step -2
Debug.Print I
Next I

You might also like