0% found this document useful (0 votes)
5 views2 pages

Cs BDC As Word Excel

Uploaded by

hasanfahd09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Cs BDC As Word Excel

Uploaded by

hasanfahd09
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.

id Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir
1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com

9.2 Algorithms: PSEUDOCODE: Pseudo code is an outline or a rough draft of a program, written
Syllabus Content: An algorithm is a sequence of steps done to perform some task. as a series of instruction.
Syllabus Content: The essential aim of an algorithm is to get a specific output, Pseudo code uses keywords commonly found in high-level programming languages,
9.2. Algorithms 11.1 Programming basics An algorithm involves with several continuous steps, without being bound to the syntax of any particular language.
show understanding that an algorithm is a solution to a problem expressed as a sequence of
defined steps
The output comes after the algorithm finished the whole process. It describes an algorithm’s steps like program statements.
Implement and write pseudocode from a given design presented as either a program
use suitable identifier names for the representation of data used by a problem flowchart or structured English So basically, all algorithms perform logically while following the steps to get an output for a
o summarise identifier names using an identifier table Notes and guidance given input. Variable:
show understanding that many algorithms are expressed using the four basic constructs of Write pseudocode statements for implement and write a program from a given design Variable is a named memory location with DataType where value can be stored.
assignment, sequence, selection and repetition presented as either a program flowchart or pseudocode Types of Algorithms: The content of a variable can change at runtime
show understanding that simple algorithms consist of input, process, output at various write pseudocode for: Structured English
stages o the declaration of variables and constants Flowcharts Constants:
document a simple algorithm using: o the assignment of values to variables and constants Pseudo codes Just like variables, constants are "dataholders". They can be used to store data that is
o Structured English o expressions involving any of the arithmetic or logical operators Program Code needed at runtime.
o pseudocode (on the examination paper, any given pseudocode will be presented o input from the keyboard and output to the console given pseudocode will use the STRUCTURED ENGLISH: In contrast to variable, the content of a constant can't change at runtime, it has a
using the Courier New font) following structures: constant value.
o program flowchart o DECLARE <identifier> : <data type> // declaration Structured English provides a more formal way of documenting the stages of the algorithm. Before the program can be executed (or compiled) the value for a constant must be
derive pseudocode or a program flowchart from a structured English description of a o CONSTANT <identifier> = <value> Structured English is a subset of English language that consists of command statements used known.
problem o <identifier> ← <value> or <expression> // assignment to describe an algorithm.
derive pseudocode from a given program flowchart or vice versa o INPUT <identifier>
FLOWCHARTS: Arithmetic
use the process of stepwise refinement to express an algorithm to a level of detail from o OUTPUT <string> , OUTPUT <identifier(s)>
Flow chart is a graphical representation of a program. Use the arithmetic operators.
which the task may be programmed
Flowcharts use different symbols containing information about steps or a sequence of events.
decompose a problem into sub-tasks leading to the concept of a program module 11.2 Constructs
(procedure/ function) Assignment
Write pseudocode to write: Symbol Name Usage
show an appreciation of why logic statements are used to define parts of an algorithm Assignment is the process of writing a value into a variable (a named memory location).
solution
For example, Count ← 1 can be read as ‘Count is assigned the value 1’, ‘Count is
use logic statements to define parts of an algorithm solution Selection Terminator To start and stop the program made equal to 1’ or ‘Count becomes 1’.
10.1 Data types use an ‘IF’ structure including the ‘ELSE’ clause and nested IF statements
use a ‘CASE’ structure Initialization:
select appropriate data types for a problem solution INPUT or OUTPUT To INPUT or OUTPUT data If an algorithm needs to read the value of a variable before it assigns input data or a
use in practical programming the data types that are common to procedural high-level Iteration calculated value to the variable, the algorithm should assign an appropriate initial value
languages: integer, real, char, string, Boolean, date (pseudocode will use the following data
types: INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE, ARRAY, FILE) use a ‘count-controlled’ loop: to the variable, known as Initialization.
show understanding of how character and string data are represented by software including o FOR <identifier> ← <value1> TO <value2> <statement(s)> ENDFOR Process To show a process
the ASCII and Unicode character sets o alternatively: FOR <identifier> ← <value1> TO <value2> STEP <value3> Input
<statement(s)> ENDFOR
We indicate input by words such as INPUT, READ or ENTER, followed by the name of
10.2 Arrays use a ‘post-condition’ loop:
o REPEAT <statement(s)> UNTIL <condition>
a variable to which we wish to assign the input value.
To Represent a Pre Defined
PROCEDURE or FUNCTION
use the technical terms associated with arrays including upper and lower bound use a ‘pre-condition’ loop Function/Procedure/Subroutine
select a suitable data structure (1D or 2D array) to use for a given task o WHILE <condition> <statement(s)> ENDWHILE • justify why one loop structure Output:
use pseudocode for 1D and 2D arrays (pseudocode will use square brackets to contain the may be better suited to a problem than the others We indicate output by words such as OUTPUT, WRITE or PRINT, followed by a
array subscript, for example a 1D array as A[1:n] and a 2D array as C[1:m, 1:n]) comma-separated list of expressions.
write program code using 1D and 2D arrays A Condition statement with
Decision Symbol
write algorithms/program code to process array data including: Yes/No/True/False decision
Totaling
To keep a running total, we can use a variable such as Total or Sum to hold the running
Represent the flow of data total and assignment statements such as:
Data flow lines
from one component to next.
Total ← Total + Number (Adds Number to Total)

www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 1 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 2 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 3 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 4

9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir
1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com

Counting 10.1 Data types Declaring Multiple Variables: VB code PYTHON


It is sometimes necessary to count how many times something happens.To count up or Pseudocodes VB Code Console Mode Sub main() num1=int(input("enter number1"))
increment by 1, we can use statements such as: The following table shows the Visual Basic data types, their supporting common Dim Num1 As Integer num2=int(input("enter number2"))
Count ← Count + 1 language runtime types, their nominal storage allocation, and their value ranges.
DECLARE index : Integer Dim index As Integer total = num1+num2
Dim Num2 As Integer
INCREMENT Count by 1 DECLARE grade : Integer Dim grade As Integer
Dim Sum As Integer prod = num1*num2
Structured statements Basic Data Types: DECLARE counter : Integer Dim counter As Integer Dim Procduct As Integer print("Total is", total)
A variable can store one type of data. The most used data types are: The three declarations above can be rewritten as one declaration if same data type is used: Console.Writeline(“Enter number1”) print("Product is", prod)
In the sequence structure the processing steps are carried out one after the other. The DECLARE index, grade, counter : Integer Num1 = Console.Readline()
instructions are carried out in sequence, unless a selection or loop is encountered. Operator Operator DATA TYPE Formats Console.Writeline(“Enter number2”)
Pseudo VB Code Console Mode Num2 = Console.Readline()
code (VB) (Python)
Mathematical Operators in Pseudocodes and Programming languages Dim index, grade, counter As Integer Sum = Num1+Num2
INTEGER Integer int Integer (Whole numbers) In Python you have to initialize variable with a value Product = Num1*Num2
Pseudocode Operator Operator Mathematical operator REAL Decimal float Decimal numbers PYTHON: Console.Writeline(“Sum is” & sum)
(VB) (Python) Single character e.g “F” for female or Index, grade, counter = 0 Console.Writeline(“Product is” & Product)
CHAR Char Not used in Python
+ + + Addition “M” for male End Sub
Constants
- - - Subtraction BOOLEAN Boolean bool Boolean e.g True or False Creating Constants in Pseudocode is just writing costant name and value with it. In contrast to variable,
STRING String str Text
the content of a constant can't change at runtime, it has a constant value. STRUCTURED ENGLISH FLOWCHART
* * * Multiplication Pseudocode: VB Console mode:
DATE Date class datetime Date CONSTANT <identifier> = <Value> Const pi As Decimal = 3.1415
/ / / Division
CONSTANT Pi 3.1415 Dim Pi As Decimal = 3.1415
= = == Equal 11.1 Declaration of Variables and Constant: or
PYTHON:
<> <> != Not equal CONSTANT Pi = 3 .14 ConstPi =3.1415
The process of creating a variable is called declaring a variable. Variables must be
MOD Mod % Modulus created or declared where users enter their data. Type of Programs:
Pseudo code 
^ ^ ** Exponent 23 = 2^3 or 2**3 
Sequence
Selection
BEGIN  Repetitions/Loops
Logical Operators in Pseudocodes and Programming languages DECLARE variable : Datatype
Variable 0 //initialization Sequence
Pseudocode Operator Operator Comparison OUTPUT (“What is your Email address”) Statements are followed in sequence so the order of the statements in a program is
(VB) (Python) INPUT variable value\ important. Assignment statements rely on the variables used in the expression on the
> > > Greater than IF valid email address? right-hand side of the statement all having been given values. Input statements often
Less than Then ... provide values for assignment statements. Output statements often use the results from
< < < END IF assignment statements.
>= >= >= Greater than equal to start
PSEUDOCODE Flow Chart
<= <= <= Less than equal to BEGIN
Each declaration needs 4 things:
Equals to DECLARE num1, num2 : Integer INPUT Pseudocode VB Code
= = == DECLARE sum, profduct :Integer
VB code example: num1, num2
<> <> != Not equal Pseudo code PRINT (“Enter number 1”)
• DECLARE keyword INPUT number1
() () () Group in Brackets • Variable name PRINT (“Enter number 2”) Sum = num1 + num2
Exponent • : keyword
^ ^ ** • Variable data type
INPUT number2 prod = num1 * num2
Sum number1 + number2
OR OR OR Or product number1 * number2
NOT NOT NOT Not DECLARE variable : Datatype PRINT (“the sum is”, sum) OUTPUT
PRINT (“the product is”, product)
AND AND AND And sum, prod
END

End
www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 5 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 6 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 7 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 8

9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir
1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com

Pseudocode: PYTHON: The IF THEN ELSE statement FLOWCHART: Python code OUTPUT

BEGIN miles = float(input("enter miles")) marks = int(input(" Enter your marks "))
START
DECLARE miles,km : REAL km = miles*1.61 if marks>=80:
OUTPUT (“Enter miles”) print("Kilometers are:", km) print("Grade A")
INPUT miles INPUT elif marks>=60:
km miles * 1.61 PSEUDOCODE FLOWCHART: marks print("Grade B")
OUTPUT(“Km are : ” & km) BEGIN
START elif marks>=50:
END DECLARE marks : Integer Yes print("Grade C")
PRINT ("Enter your grade") OUTPUT else:
INPUT marks IF marks >=
(“Grade A”) print("Grade U")
IF marks > 50 INPUT
int("Grade U")
THEN marks No
PRINT ("You have passed") Yes OUTPUT The IF statement is useful, but can get clumsy if you want to consider “multi-way
IF marks >= 60
ELSE (“Grade B”) selections
11.2 Structured statements for selection (conditional statements) PRINT (“You’ve failed”) Yes OUTPUT No
END IF IF marks>50 (“Pass”)
These statements are used to select alternative routes through an algorithm; selection’s OUTPUT (“Grade C”)
logical expressions often involve comparisons, which can operate on text strings as well END No IF marks >=50 CASE Statement START FLOWCHART:
as numbers No Yes
IF…THEN…ELSE…ENDIF OUTPUT INPUT num1,
CASE…OF…OTHERWISE…ENDCASE (“Fail”) OUTPUT (“Grade U”) num2, Opvalue
IF…THEN…ELSE…ENDIF
For an IF condition the THEN path is followed if the condition is true and the ELSE path Yes
STOP Ans = num1+num2
is followed if the condition is false. STOP Opvalue = “+”
There may or may not be an ELSE path. The end of the statement is shown by ENDIF.
IF THEN, ELSE-IF statements VB code example
A condition can be set up in different ways: VB Code No Yes
IF ((Height > 1) OR (Weight > 20) OR (Age > 5)) AND (Age < 70) PYTHON Code: BEGIN Sub main() Opvalue = “-”
Sub main() Ans = num1-num2
THEN DECLARE marks : INTEGER Dim marks As Integer
PRINT ("You can ride") marks = int(input(" Enter your marks ")) Dim marks As Integer
ELSE if marks>=50: PRINT ("Enter marks") Console.Writeline(“Enter marks”) No
Console.Writeline(“Enter marks”)
PRINT ("Too small, too young or too old") print("Pass") INPUT marks Marks = Console.Readline() Yes Ans = num1 * num2
ENDIF else: print("Fail") Marks = Console.Readline() IF marks >= 80 Opvalue = “ * ”
If marks >= 80 Then
If marks >= 50 Then THEN PRINT ("Grade A")
CASE … OF … OTHERWISE … ENDCASE Console.Writeline(“pass”) ELSE IF marks >= 60
Console.Writeline(“ A ”) No
For a CASE condition the value of the variable decides the path to be taken. Several THEN PRINT ("Grade B") Elseif marks >= 60 Then
Else Opvalue = “/” Ans = num1 / num2
values are usually specified. OTHERWISE is the path taken for all other values. The ELSE IF marks >= 50 Console.Writeline(“ B ”)
Console.Writeline(“fail”) THEN PRINT ("Grade C")
end of the statement is shown by ENDCASE. Elseif marks >= 50 Then No Yes
End If ELSE PRINT ("Grade U")
The algorithm below specifies what happens if the value of Choice is 1, 2, 3 or 4. Console.Writeline(“ C ”)
End Sub END IF
CASE Choice OF Else OUTPUT (“ Invalid Choice”)
END IF
1: Answer ← Num1 + Num2 END IF Console.Writeline(“ U ”)
2: Answer ← Num1 - Num2
End If STOP
3: Answer ← Num1 * Num2 END
4: Answer ← Num1 / Num2 End Sub
OTHERWISE PRINT ("Please enter a valid choice")
ENDCASE

www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 9 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 10 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 11 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 12

9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir
1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com

CASE OF OTHERWISE… Pseudocode CASE OF OTHERWISE… FLOWCHART Program Code in Visual Basic Console Mode: FOR … NEXT LOOP
BEGIN
DECLARE num1, num2, Ans : INTEGER Sub Main() This is to be used when loop is to be repeated a known fixed number of times.
DECLARE Opvalue : CHAR Dim marks As Integer The counter is automatically increased each time the loop is performed.
INPUT num1, num2 START Console.WriteLine("Input your marks")
OUTPUT (“Enter Operator value + add, - sub, * multiply, / divison”) marks = Console.ReadLine() FOR count = 1 to 10
INPUT Opvalue Select Case marks INPUT number
CASE OF OpValue Case >= 80
"+" : Answer ¨ Number1 + Number2
Pseudo code total = total + number
INPUT marks Console.WriteLine("Grade A") NEXT count
"-" : Answer ¨ Number1 - Number2 Case >= 60
"*" : Answer ¨ Number1 * Number2 BEGIN
Console.WriteLine("Grade B")
"/" : Answer ¨ Number1 / Number2 DECLARE marks : Integer Case >= 50 WHILE … Do LOOP
OTHERWISE OUTPUT ("Please enter a valid choice")
ENDCASE OUTPUT Console.WriteLine("Grade C")
PRINT ("Enter your marks") marks>=80? Yes Case Else This loop is used when we don’t know how many times the loop is to be performed. The Loop is
OUTPUT (“Answer is :”,Ans) (“Grade A”)
ended when a certain condition is true.
INPUT marks Console.WriteLine("Grade U")
END This condition is checked before starting the loop.
CASE OF marks no End Select
PYTHON End Sub
num1=int(input("Enter number 1 "))
80 >= :PRINT("Grade A") marks>=70? Yes OUTPUT While COUNT < 10 DO
(“Grade B”) Input NUMBER
70 >= :PRINT("Grade B")
num2=int(input("Enter number 2 ")) Python does’t use CASE Statements so Elif is used: TOTAL = TOTAL + NUMBER
OpValue = ("Enter Opvalue, + is add), - is subract), * is Multiply, / is divide") 60 >= :PRINT("Grade C") no COUNT = COUNT + 1
if OpValue == "+": 60 >= :PRINT("Grade D") PYTHON Code Endwhile
Answer = num1 + num2 OUTPUT
40 >= :PRINT ("Grade E") marks>=60? Yes marks = int(input(" Enter your marks ")) Output TOTAL
elif OpValue == "-": (“Grade C”)
Answer = num1 + num2 OTHERWISE if marks>=80:
elif OpValue == "*": REPEAT … UNTIL LOOP
Answer = num1 + num2
PRINT("Grade U, Repeat Exam") no print("Grade A")
elif OpValue == "/": OUTPUT
elif marks>=60: REPEAT UNTIL Loop is used when we do not know how many times loop will be performed.
Answer = num1 + num2 marks>=50?
END CASE Yes print("Grade B") The Loop is ended when a certain conation is true.
else: print("invalid operator") (“Grade D”)
The Condition is checked at the end of the Loop and so a REPEAT Loop always has to be
print("Answer is : ", Answer) END no elif marks>=50: performed at least once.
Visual Basic (Console mode) . print("Grade C")
Dim Num1, Num2, Answer As Integer yes else: print("Grade U") REPEAT
Dim Opvalue As Char OUTPUT
marks>=40? Input NUMBER
Console.Writeline(“INPUT num1 and num2”) (“Grade D”)
TOTAL = TOTAL + NUMBER
Num1 = Console.Readline()
Num2 = Console.Readline()
LOOPS (Structured statements for iteration (repetition) COUNT = COUNT + 1
Console.Writeline(“Enter Opvalue”) no Many problems involve repeating one or more statements, so it is useful to have Until COUNT = 10
Console.Writeline (+ add, - sub, * multiply, / divison”) structured statements for controlling these iterations or repetitions. Output Total
Opvalue = Console.Readline() OUTPUT
Select CASE OpValue (“Grade U) Exit conditions consist of logical expressions whose truth can be tested, such as FOR Loop PSEUDOCODE
CASE "+" Count = 10 or Score < 0.
Answer = Number1 + Number2
CASE "-" The fore loop repeats statements a set number of time.
Answer = Number1 - Number2 At a particular time, a logical expression is either True or False.
CASE "*" There are three type of Loops
Answer ¨ Number1 * Number2
It uses a variable to count how many time it goes round the loop and stops when it reaches its limit.
CASE "/" STOP FOR…TO…NEXT (Count controlled Loop)
Answer ¨ Number1 / Number2
CASE Else WHILE…DO…ENDWHILE (Pre- Condition Loop)
Console.Writeline ("input valid choice")
End Select REPEAT…UNTIL (Post Condition Loop)
Console.Writeline (“Answer is :” & Answer)

www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 13 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 14 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 15 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 16
9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir
1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com

BEGIN FLOWCHART FOR LOOP WHILE DO ENDWHILE loop VB Code PSEUDOCODE


DECLARE count, number : Integer Sub main()
BEGIN
OUTPUT (“Input a number for its times table") The wile loop is known as a test before loop. The condition is tested before entering the loop, but tested DECLARE name : String
Dim marks As Integer
INPUT number
each time it goes round the loop. The number of times the statements within the loop are executed REPEAT
Do
varies. The test before loop goes round 0 or more times. PRINT (“Enter marks 0 to 100”)
FOR count = 1 To 20 This method is useful when processing files and using “read ahead” data Console.Writeline(“Enter marks 0 to100”)
INPUT marks
PRINT (number , “times" , count , “ = ” number * Count”) Marks = Console.Readline() UNTIL marks>=0 AND marks <=100
Loop Until marks>=100 AND <=100
NEXT if marks >= 50 Then IF marks>=50
Console.Writeline(“ Pass ”) THEN
VB code example FOR LOOP: VB Code example PSEUDOCODE
BEGIN
Else OUTPUT(“Pass”)
Sub main() DECLARE marks : REAL Console.Writeline(“ Fail ”) ELSE
Sub Main(args As String())
Dim marks As Integer INPUT marks End If OUTPUT(“Fail”)
Console.WriteLine("Times Table Program")
Console.Writeline(“Enter marks”) WHILE marks > 100 OR < 0 End Sub END IF
Dim count, num As Integer
Console.WriteLine("please Input a number for its TimesTable") marks = Console.Readline() PRINT (“ERROR, RE-Input “) END
num = Console.ReadLine() While marks > 100 OR marks < 0 INPUT marks
PYTHON Does not have REPEAT LOOP so WHILE Loop is used.
For count = 1 To 20 Console.Writeline(“REINPUT 0 to 100”) END WHILE
Console.WriteLine(num & " Times " & count & " = " & num * count) marks = Console.Readline() IF marks>=50
End While THEN
Next
if marks >= 50 Then OUTPUT (“Pass”)
End Sub
ELSE
Console.Writeline(“ Pass ”)
Output VB OUTPUT (“Fail”)
Else
END IF
Console.Writeline(“ Fail ”) END
PYTHON Code FOR LOOP End If
End Sub PYTHON Code .
print(" Times Table Program ")
num = int(input("Enter a number for its TimesTable"))
for count in range(1,10):
FLOWCHART…WHILE-ENDWHILE
print(num, " X ", count, " = ", num*count)
START
marks

Output PYTHON (“Grade A”)

INPUT marks (“ ”)

(“ ”)

REPEAT UNTIL loop (“ ”)


LOOP
(“ ”)

The repeat loop is similar to the while loop, but it tests the condition after the statements have been (“

executed once. This means that this test after loop goes round 1 or more times.
WHILE
marks >100 OR < 0 OUTPUT
(“ ERROR, Re Input”)
Yes

No
STOP
marks

(“Grade A”)

www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 17 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 18 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 19 www.majidtahir.com (“ ”) WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 20
(“ ”)

(“ ”)

(“ ”)

9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics
(“
CS 9618 with Majid Tahir
1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com 1 at www.majidtahir.com

FLOWCHART…REPEAT-UNTIL Arrays (One-dimensional arrays) VB Code in Console Mode Another example of One-Dimensional Array
In order to use a one-dimensional array in a computer program, you need to consider: Dim name(5) As String Module Module1
START
• What the array is going to be used for, so it can be given a meaningful name Sub Main()
Dim marks(5) As Integer
Dim count As Integer
marks • How many items are going to be stored, so the size of the array can be determined. For count = 1 To 5
Dim name(4) As String
(“Grade A”)
• What sort of data is to be stored, so that the array can be the appropriate data type. Console.WriteLine("input name " & count) Dim marks(4) As Integer
LOOP
(“

(“
”)

”) DECLARATION on Blank Array with 10 slots can be done like this: name(count) = Console.ReadLine() Dim gender(4) As String
(“ ”) Pseudocode: VB code example: Console.WriteLine("input marks " & count) For count = 0 To 4
marks(count) = Console.ReadLine() Console.WriteLine("please enter your name" & count)
(“ ”)

DECLARE names[10]: STRING Dim names(9) As String While marks(count) > 100 Or marks(count) < 0 name(count) = Console.ReadLine()
(“

PYTHON Code Console.WriteLine("Re-Enter marks" & count) Console.WriteLine("please enter your gender" & count)
OUTPUT (“Enter marks 0 to 100”) gender(count) = Console.ReadLine()
name[] marks(count) = Console.ReadLine()
OUTPUT (name) No Console.WriteLine("please enter your marks" & count)
End While
Entering Values in One-Dimension Array Next marks(count) = Console.ReadLine()
BEGIN Next count
UNTIL For count = 1 To 5 For count = 0 To 4
INPUT marks DECLARE count : Integer
marks>=0 AND <=100
DECLARE name [5] : String // for declaring 5 elements in ARRAY
Console.WriteLine(name(count) & " scored: " & marks(count)) Console.WriteLine("your name is : " & name(count))
DECLARE marks [5] : Integer Next Console.WriteLine("your gender is : " & gender(count))
Console.WriteLine("your marks are : " & marks(count))
FOR count = 1 to 5 // for inputting 5 names and grades Output of VB code (Console mode) Next count
Yes
PRINT (“Enter Name “& count) Console.ReadKey()
INPUT name (count) End Sub
STOP PRINT (“Enter grade for “& name(count)) End Module
marks
INPUT marks (count)
10.2 Array Data Type (“Grade A”)
NEXT count
Multi-Dimensional Arrays or Two dimensional Arrays (2D Array):
(“ ”)

FOR count 1 to 5 // for displaying 5 names and grades


PRINT (name (count) & “has marks " & marks(count))
(“ ”)

An array is a special variable that has one name, but can store multiple values. Each value is stored in an A multi-dimensional array can be thought of as a table, each element has a row and column index.
element pointed to by an index.
(“ ”)

NEXT count Following example declares a two-dimensional array called table with 3 rows and 4 colums
The first element in the array has index value 0, the second has index 1, etc (“ ”)

END and would be declared in PseudoCode as follows:


(“

PYTHON Code:
DECLARE table(3, 4) : INTEGER
One Dimensional Arrays
A one dimensional array can be thought as a list. An array with 10 elements, called names, can store 10 name = []
Visual Basic(Console mode)
names and could be visualized as this: Lower bound of ARRAY can start from 1 or 0 marks = []
for count in range(5): Dim table(3, 4) : As Integer
Index Name name.append (str(input("Enter name: ")))
1 Fred marks.append (int(input("Enter marks "))) Python Code
2 James print("Name ", name, " scored ", marks) row, col = 3, 4
3 Tom
table = [[0 for x in range(row)] for y in range(col)]
4 Robert # Creates a list containing 5 lists, each of 8 items, all set to 0

5 Jonah
6 Chris
7 John
8 Matthew
Python One-dimensional array with values in it.
OUTPUT screen num = [1, 2, 3]
9 Mikey num.append(4)
10 Jack num.extend([5, 6])
print(num) # will print this in output [1, 2, 3, 4, 5, 6]

www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 21 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 22 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 23 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 24

9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir 9.2, 10.2, 11.1 to 11.2 Algorithm & Programming Basics CS 9618 with Majid Tahir
1 at www.majidtahir.com 1 at www.majidtahir.com

PSEUDOCODE Example of Two-Dimension Array


BEGIN
DECLARE table(3, 4) : Integer
FOR row = 1 To 3
FOR column = 1 To 4
PRINT("Please Input Value in Row: ",row, "column : ", column)
INPUT table(row, column)
NEXT
NEXT
FOR row = 1 To 3
FOR column = 1 To 4
PRINT ("Row = " & row & "column = " & column & “has Value”)
PRINT (table(row, column))
NEXT
NEXT
END

VB Code Example of Two-Dimension Array


Sub Main()
Dim table(2, 3) As Integer VB Code for 2-D Array is:
For row = 0 To 2
For column = 0 To 3
Console.WriteLine("Please Input Value in Row: " & row & "column : " & column)
table(row, column) = Console.ReadLine()
Next
Next
Console.Clear()

For row = 0 To 2
For column = 0 To 3
Console.WriteLine("Row = " & row & "column = " & column & “has Value”)
Console.WriteLine(matrix(row, column))
Next
Next
Console.ReadKey()
End Sub

Multi-Dimensional Arrays:
A multi-dimensional array can be thought of as a table, each element has a row and
column index.
Refrences:
Following example declares a two-dimensional array called matrix and would be Computer Science by David Watson & Helen Williams
declared by Visual Basic Console Cook Book
Computer Science AS and A level by Sylvia Langfield and Dave Duddell
https://www.sitesbay.com/javascript/javascript-looping-statement
http://wiki.jikexueyuan.com/project/lua/if-else-if-statement.html

www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 25 www.majidtahir.com WhatsApp +923004003666 Enroll in Online classes at www.fiqar.org 26

You might also like