Lab Introduction
Lab Introduction
Program Development
Often, a program contains many instructions, and the instructions are rather complicated.
Therefore, developing a successful program requires some effort. It requires careful planning,
careful implementation, and ongoing maintenance. Here is a list of typical steps involved in the
Requirements analysis
Design
Implementation
Testing
Documentation
Maintenance
The steps ordered in a reasonable sequence in that you'l1 normally perform requirements
analysis first, design second, and so on. But some of the steps should be performed throughout the
development process rather than at one particular time. For example, you should work on the
during and after the implementation step and also after the maintenance step. Be aware that you'll
often need to repeat the sequence of steps as needs arise. For example, if one of the program's goals
changes, you will need to repeat all of the steps in varying degrees.
This term, we will apply the first four steps. We will discuss the requirements analysis step and
the design step this week. Then, we will discuss the Implementation step later this term.
In the design step, we should use some analysis methods. Each programmer uses the methods
that he is aware of. This semester, we will use flow chart and pseudocode.
Pseudocode
In writing an algorithm, you should focus on organizing the flow of the instructions, and you
should try to avoid getting bogged down in details. To facilitate that focus, programmers often write
Pseudocode is an informal language that uses regular English terms to describe a program's
steps. With pseudocode, precise computer syntax is not required. Syntax refers to the words,
grammar, and punctuation that make up a language. Pseudocode syntax is lenient: pseudocode must
be clear enough so that humans can understand it, but the words, grammar, and punctuation do not
have to be perfect.
Suppose you are asked to write an algorithm that finds the average miles per hour value for a
given car trip. Let's step through the solution for this problem. To determine the average miles per
hour, you will need to divide the total distance traveled by the total time. Let us assume that you
have to calculate the total distance from two given locations. To determine the total distance, you'1l
need to take the ending-point location, called "ending location," and subtract the starting-point
location, called "starting location,” from it. Let us assume that you have to calculate the total time in
the same manner, subtracting the starting time from the ending time. Putting it all together, the
pseudocode for calculating average miles per hour looks like this:
There are many ways to write a pseudocode, you do not have to write the same way that was
Begin
Print “Hello, Java”
End
Before we solve this exercise, we should study a very important principle called variables. What
A variable is a characteristic, number, or quantity that increases or decreases over time, or takes
name (an identifier), which contains some known or unknown quantity or information referred to as
a value. The variable name is the usual way to reference the stored value; this separation of name
and content allows the name to be used independently of the exact information it represents. The
identifier in computer source code can be bound to a value during run time, and the value of the
mathematics. The value of a computing variable is not necessarily part of an equation or formula as
value in one place, then used elsewhere, then reassigned a new value and used again in the same
way (like iteration or looping – we’ll discuss looping later - ). Variables in computer programming are
frequently given long names to make them relatively descriptive of their use, whereas variables in
mathematics often have terse, one- or two-character names for brevity in transcription and
manipulation. For Example, if you want to define a variable that refers to rectangle length you
should write RectangleLength. In addition, if the variable contains two words or more, they
must not be separated by a space, they should be connected as one word and the first letter in each
word should be capitalized. Alternatively, you can separate those words using dashes
Rectangle_Length.
Compilers* have to replace variables' symbolic names with the actual locations of the data.
While a variable's name, type, and location often remain fixed, the data stored in the location may
So, if you are asked to write an algorithm or a program, first of all, you should analyze any
variable that can solve the problem. Then, define them at the beginning. After that, think about
*A compiler is a computer program (or set of programs) that transforms source code written in
a programming language (the source language) into another computer language (the target
language, often having a binary form known as object code). The most common reason for
The name "compiler" is primarily used for programs that translate source code from a high-level
programming language to a lower level language (e.g., assembly language or machine code).
First, we should define anything that helps solving this problem. Any rectangle has 4 sides, 2
lengths and 2 widths. We should know one length and one width to calculate the rectangle area.
So, let’s assume that the first variable called RectangleLength and the second one called
RectangleWidth.
Now, we are ready to write the pseudocode after we analyze the problem.
Begin
Set RectangleLength to 2
Set RectangleWidth to 4
RectangleArea = RectangleLength * RectangleWidth
Print “Rectangle Area = “, RectangleArea
End
When you convert the previous pseudocode to a programming language such as java, you must
specify the amount of each variable. Which means, you should tell the computer how many bytes
In this exercise we used integer numbers. So, we should tell the computer to reserve 2 bytes in
the memory.
The computer is programmed that integer is 2 bytes, float is 4 bytes, and so on. The above
As you can see, there is no rules to write a pseudocode, at the first solution we wrote
In the previous example we assumed the values for each RectangleLength and
RectangleWidth. Sometimes, the values should be entered by keyboard. Which means, you have
Begin
Define RectangleLength as integer
Define RectangleWidth as integer
Define RectangleArea as integer
Print “Enter the rectangle length please: “
Input RectangleLength
Print “Enter the rectangle width please : ”
Input RectangleWidth
RectangleArea RectangleLength * RectangleWidth
Print “Rectangle Area = “, RectangleArea
End
So, every time you want a value to solve the problem, you ask the user to enter this value.
In this exercise, we need to define two variables. Also, we need to assume a math operation.
So, let’s us call the two variables: Number1 and Number2. Moreover, assume that we use
Begin
Define Number1, Number2 as integer
Print “Enter the first number please: “
Input Number1
Print “Enter the second number please: “
Input Number2
Define Number3 as integer
Number3 = Number1 * Number2
Print “The result = ”, Number3
In this exercise, we defined two variables in one sentence. In addition, we recognized later that
we needed a new variable to store the result in. So, we defined the new variable where we knew
that.
In pseudocode, we don’t have to define variables. I mentioned it here so you got the idea when
we write java programs. In java or any other programming language, you must define any variable
First: Condition
Case#1
Write an algorithm that prints succeeded if the student succeeded.
Begin
Define Grade as integer
Print “Enter the student grade please: ”
Input Grade
If Grade is greater than or equal to 60 Then
Print “Succeeded”
End
Start
Read Grade
Yes
Grade >= 60? Print “Succeeded”
No
End
reults.
Begin
Define Grade as integer
Print “Enter the student grade please: ”
Input Grade
If Grade is greater than or equal to 60 Then
Print “Succeeded”
Else
Print “Failed”
End
Start
Read Grade
No Yes
Print “Failed” Grade >= 60? Print “Succeeded”
End
80 or more, Good if he got 70 or more, Pass if he got 60 or more or Failed if he got less than
60.
Begin
Define Grade as integer
Print “Enter the student grade please: ”
Input Grade
If Grade is greater than or equal to 90 Then
Print “Excellent”
Else If Grade is greater than or equal to 80 Then
Print “Very Good”
Else If Grade is greater than or equal to 70 Then
Print “Good”
Else If Grade is greater than or equal to 60 Then
Print “Pass”
Else
Print “Failed”
End
Read Grade
No No Grade >= No
Grade >=90? Grade >=80? 70?
No
Print ”Fail” Grade >=60?
Yes
Print ”Pass”
End
Case#1
Write an algorithm that prints Happy Eid 100 times
Set counter to 1
While counter is less than or equal to 100
Print “Happy Eid”
Set counter to counter + 1
Start
counter = 1
No
counter < 100
Yes
End
Set counter1 to 1
Set counter2 to 1
counter1 = 1
counter2 = 1
No
counter1 < 100
Yes
Print “ Happy Eid “
counter1 = counter1 + 1
No
counter2 < 50
Yes
counter2 = counter2 + 1
End