0% found this document useful (0 votes)
1K views6 pages

Computer Science 9608 Programmed Examples PDF

This document contains code examples demonstrating different programming concepts in Visual Basic.NET, including: 1) Defining and populating 1D, 2D, and 3D arrays to store and process student data such as names, test scores, and totals. Loops are used to input and output the data. 2) Demonstrating the differences between local and global variables through subroutines that modify variable values. 3) Examples of passing parameters between subroutines using ByVal and ByRef keywords to control whether the parameters are passed by value or reference.

Uploaded by

NushanKhan
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)
1K views6 pages

Computer Science 9608 Programmed Examples PDF

This document contains code examples demonstrating different programming concepts in Visual Basic.NET, including: 1) Defining and populating 1D, 2D, and 3D arrays to store and process student data such as names, test scores, and totals. Loops are used to input and output the data. 2) Demonstrating the differences between local and global variables through subroutines that modify variable values. 3) Examples of passing parameters between subroutines using ByVal and ByRef keywords to control whether the parameters are passed by value or reference.

Uploaded by

NushanKhan
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/ 6

COMPUTER SCIENCE 9608 (PROGRAMMED

EXAMPLES)

MODULES
MODULE MODULE1
DIM NAME(3) AS STRING
DIM WEIGHT(3) AS SINGLE
DIM DIFF(3) AS SINGLE
SUB MAIN()
DIM COUNT AS INTEGER
COUNT = 0
FOR COUNT = 1 TO 3
NAME(COUNT) = ""
WEIGHT(COUNT) = 0
DIFF(COUNT) = 0
NEXT
CALL TASK1()
CALL TASK2()
CALL TASK3()
CONSOLE.READKEY()
END SUB
SUB TASK1()
DIM COUNT AS INTEGER
FOR COUNT = 1 TO 3
CONSOLE.WRITELINE("INPUT THE NAME OF STUDENT " & COUNT)
NAME(COUNT) = CONSOLE.READLINE
CONSOLE.WRITELINE("INPUT THE WEIGHT OF STUDENT AT THE START OF TERM")

WEIGHT(COUNT) = CONSOLE.READLINE
CONSOLE.WRITELINE("INPUT THE WEIGHT OF STUDENT AT THE END OF TERM")
DIFF(COUNT) = CONSOLE.READLINE - WEIGHT(COUNT)
NEXT
END SUB
SUB TASK2()
DIM COUNT AS INTEGER
FOR COUNT = 1 TO 3
CONSOLE.WRITELINE(NAME(COUNT) & " WEIGHED " & WEIGHT(COUNT) & " KGS, THE DIFFERENCE AT THE
END OF TERM IS " & MATH.ABS(DIFF(COUNT)) & "KGS")
NEXT
END SUB
SUB TASK3()
DIM COUNT AS INTEGER
FOR COUNT = 1 TO 3
IF DIFF(COUNT) > 2.5 THEN
CONSOLE.WRITELINE("THE WEIGHT OF " & NAME(COUNT) & " HAS INCREASED BY " & DIFF(COUNT) & "KGS")
END IF
IF DIFF(COUNT) < -2.5 THEN
CONSOLE.WRITELINE("THE WEIGHT OF " & NAME(COUNT) & " HAS DECREASED BY " &
MATH.ABS(DIFF(COUNT)) & "KGS")
END IF
NEXT
END SUB
END MODULE

Local variable, Global Variable

MODULE MODULE1
DIM A, B AS INTEGER 'GLOBAL VARIABLE
SUB MAIN()
A=1
B=2
CONSOLE.WRITELINE("A = " & A & " B =" & B)
CONSOLE.READKEY()
CALL ZAFAR()
CONSOLE.WRITELINE("A = " & A & " B =" & B)
CONSOLE.READKEY()
CALL AZHAR()
CONSOLE.WRITELINE("A = " & A & " B =" & B)
CONSOLE.READKEY()
CALL AHMED()
CONSOLE.WRITELINE("A = " & A & " B =" & B)
CONSOLE.READKEY()
END SUB
SUB ZAFAR()
A=4
END SUB
SUB AZHAR()
B=0
END SUB
SUB AHMED()
DIM B AS INTEGER 'LOCAL VARIABLE
B = 100
END SUB
END MODULE

Passing parameters ByVal & ByRef

Module Module1
Sub Main()
Dim a, b, c As Integer
a=9
b=2
c=7
Console.WriteLine("a = " & a & " b = " & b & " c = " & c)
Console.ReadKey()
Call zafar(a, b, c)
Console.WriteLine("a = " & a & " b = " & b & " c = " & c)
Console.ReadKey()
End Sub
Sub zafar(ByVal n As Integer, ByRef m As Integer, ByVal As Integer)
n = 10
m = 11
o = 12
End Sub
End Module

3-d Arrays
Dim Names(30) As String
Dim Test1(30) As Single
Dim Test2(30) As Single
Dim Test3(30) As Single
Dim T As Single
Dim Total(30) As Single
Dim Count As Integer
Dim ConsolidatedTotal As Single 'Changed Here
Dim Highest As Single
Dim ClassAverage As Single 'Changed here
'Initilization of Variables
T=0
Highest = 0
Count = 0
ConsolidatedTotal = 0 'Changed Here
'Initialization of Arrays
For Count = 1 To 30
Names(Count) = "" 'Changed Here
Test1(Count) = 0
Test2(Count) = 0
Test3(Count) = 0
Total(Count) = 0
Next
'Reading Data into Array
For Count = 1 To 30 'Changed Here
Console.WriteLine("Enter Student Name" & Count & " ") 'Changed Here
Names(Count) = Console.ReadLine 'Changed Here
Console.WriteLine("Enter marks for Test1" & "")
Test1(Count) = Console.ReadLine
'If 20 < Console.ReadLine < 0 Then 'changed here
'Console.WriteLine("Error") 'changed here
'End If 'changed here
Console.WriteLine("Enter marks for Test2" & "")
Test2(Count) = Console.ReadLine
'If 25 < Console.ReadLine < 0 Then 'changed here

'Console.WriteLine("Error") 'changed here


'End If 'changed here
Console.WriteLine("Enter marks for Test3" & "")
Test3(Count) = Console.ReadLine
'If 35 < Console.ReadLine < 0 Then 'changed here
'Console.WriteLine("Error") 'changed here
'End If 'changed here
Next
'Writing Data into Arrays
For Count = 1 To 30
T = Test1(Count) + Test2(Count) +
Test3(Count)
Total(Count) = T
ConsolidatedTotal = ConsolidatedTotal + Total(Count) 'Changed Here
Next
ClassAverage = ConsolidatedTotal / 30 'Changed Here
For Count = 1 To 30
Console.WriteLine(Names(Count) & Total(Count)) 'Changed Here
Next
Console.WriteLine(ClassAverage) 'Changed here
For Count = 1 To 30
If Total(Count) > Highest Then
Console.WriteLine(Names(Count) & Total(Count)) 'Changed here
End If
Next
Console.ReadKey()

You might also like