Вы находитесь на странице: 1из 4

Program – 1

'Project : Console application to display total


value of all products sold
'Programmer : Suresh Chinta (A00068024)
'Date started and completed : 09/21/2007
'Description : Reads a series of pairs as input to calculate the
total value of individual products

Module modTotalCalculation 'Name of the module changed for easy identification

Sub Main()

'Variable declaration to assign user input / calculated values


'All values are initialized to zero to avoid any possible mathematical
errors
Dim Product As Integer = 0
Dim Quantity As Integer = 0
Dim Total1 As Double = 0
Dim Total2 As Double = 0
Dim Total3 As Double = 0
Dim Total4 As Double = 0
Dim Total5 As Double = 0

'Sentinel controlled loop structure to achieve the program task


While Product <> -10 '-10 is a value used to exit the control loop
Console.WriteLine()
Console.Write("Enter the product number (Between 1 and 5), -10 to
quit: ")
Product = Console.ReadLine()
Console.WriteLine() 'To space between the product code and quantity

Select Case Product 'A Product case is chosen to calculate sub-


totals of various individual items

Case 1
Console.Write("Enter the required quantity : ")
Quantity = Console.ReadLine()
Total1 = Total1 + (Quantity * 2.98)

Case 2

Console.Write("Enter the required quantity : ")


Quantity = Console.ReadLine()
Total2 = Total2 + (Quantity * 4.5)

Case 3

Console.Write("Enter the required quantity : ")


Quantity = Console.ReadLine()
Total3 = Total3 + (Quantity * 9.98)

Case 4
Console.Write("Enter the required quantity : ")
Quantity = Console.ReadLine()
Total4 = Total4 + (Quantity * 4.49)

Case 5

Console.Write("Enter the required quantity : ")


Quantity = Console.ReadLine()
Total5 = Total5 + (Quantity * 6.87)

Case Else
If Product <> -10 Then
Console.WriteLine("Invalid Entry. Please enter an
integer between 1 and 5")
Else
'Console.WriteLine("Program executed successfully.
Results printed.")
End If
End Select

End While

'Print the total product values individually


Console.Write("Product totals are :" & vbCrLf & "Product 1: " & Total1
& vbCrLf & "Product 2: " & Total2 _
& vbCrLf & "Product 3: " & Total3 & vbCrLf & "Product 4: " & Total4 &
vbCrLf & "Product 5: " & Total5)

Console.Read()

End Sub

End Module
Program – 2

'Project : Console application to display factorial


of numbers upto 20
'Programmer : Suresh Chinta (A00068024)
'Date started and completed : 09/22/2007
'Description : Displays a series of numbers from 1 to 20 and
their respective factorials against it

Module modFactorial 'Module name changed for clarity

Sub Main()
Dim Number As Integer = 1 'Number declared to iterate it from 1 to 20
Dim Factorial As Long = 1 'To display the factorial after calculation

'While loop to iterate the numbers from 1 to 20

While Number <= 20


Factorial = Factorial * Number 'Factorial number is multiplied to
each number iteratively
Console.WriteLine("Number is: {0}", Number & vbTab & "Factorial is:
" & Factorial & vbCrLf)
Number += 1

End While
Console.Read()

End Sub

End Module
Program - 3

'Project : Console application to display values of


both sides in a right angle triangle upto 30
'Programmer : Suresh Chinta (A00068024)
'Date started and completed : 09/23/2007
'Description : Displays a series of numbers from 1 to 30 in a
right angle triangle and their respective hypotenuse value

Module modPytho 'Module name changed for clarity

Sub Main()
'Declaration of variables to store values
Dim side1, Side2, Hypotenuse As Integer

'Program logic (Recursive) to display a set of values from 1 to 30 in a


right angle triangle to display possible values of two sides and the hypotenuse
For side1 = 1 To 30 'For loop from 1 to 30 for side 1

For Side2 = 1 To 30 ' For loop from 1 to 30 for side 2

For Hypotenuse = 1 To 30 'For loop from 1 to 30 for hypotenuse

If (Hypotenuse ^ 2) = (side1 ^ 2) + (Side2 ^ 2) Then 'Check


whether the hypotenuse matches the possible sides

Console.WriteLine("Side 1 : {0}", side1 & vbTab & "Side


2 : " & Side2 & vbTab & "Hypotenuse is : " & Hypotenuse & vbCrLf)

End If

Next
Next
Next

Console.ReadLine()

End Sub

End Module

Вам также может понравиться