Tutorial 1 Solution Essay

Submitted By James19940325H
Words: 568
Pages: 3

GENG1002 Introduction to Engineering Computations
TUTORIAL 1 - Week 2
TIME ALLOWED - 2 HOURS
Complete the following exercises. All programs should be suitably commented, formatted (i.e. use indentation) and variables assigned meaningful names.
Parts of this tutorial that you do not complete in class should be completed in your own time before the next tutorial.
Exercise 1
Refer to Lecture notes of Week 1 (Slides 47-55) and develop ‘Hello World’ program by a - MS Visual Studio using a Console Application b - Ms Visual Studio using a Windows Form Application. c - Excel Form using VBA.
Solution: Refer to Lecture Notes of Week 1, Slides 47-55 for a step-by-step procedure.
Exercise 2
Write a VB Console Application program that reads four numbers (two single type numbers and two integer type numbers), and then prints them out onto the screen so you can check that they have been input correctly.
Solution: A typical VB code program for this question may look as follows:
Sub Main()
'
'Aim: As in Question 2, Tutorial 1, Week 2
'Programmer: Majid Nazem
'Last modified: July 2013
'
Dim S1, S2 As Single
Dim I1, I2 As Integer
'Input Single variables:
Console.WriteLine("Please enter first Single Variable:")
S1 = Console.ReadLine()
Console.WriteLine("Please enter second Single Variable:")
S2 = Console.ReadLine()
'Input Integer variables:
Console.WriteLine("Please enter first Integer Variable:")
I1 = Console.ReadLine()
Console.WriteLine("Please enter second Integer Variable:")
I2 = Console.ReadLine()
'Write all variables:
Console.WriteLine("First Single = " & S1)
Console.WriteLine("Second Single = " & S2)
Console.WriteLine("First Integer = " & I1)
Console.WriteLine("Second Integer = " & I2)
Console.ReadKey()

1

End Sub

Exercise 3
Create a new VB Console Application named “T1_Ex3” and type in the following code in Sub Main()
(You can copy (Ctrl+C) the code from this pdf file and paste (Ctrl+V) it into the .VB file).
Locate/correct all errors. Run the program and enter 1.0, 4.0, and 3.0 for a, b, and c respectively. Show the corrected codes and command window results to your tutor. Can you guess what this program does?! Dim a, b, c As Simgle
Dem x1, 2x, Del As Singlet
“Input variables a and b and c.
Console.WriteLin("Please enter a:") a != Console.ReadLine()
Console.WriteLine("Please enter b:’) b2 =