Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

1.

Write a program that will request the user to enter their name, gender(M/F) and if the they
are vaccinated status(Yes/No).
The program will then output the name, gender and True( if answer is Yes for vaccinated)
or False( if answer is No for vaccinated) for vaccinated status.

Note : Use string data type for name, Character data type for gender, Boolean data type for
vaccinated)

Module Module1

Sub Main()
Dim Name As String
Dim Gender As Char
Dim Status As Boolean

Console.WriteLine("Please enter your name:")


Name = Console.ReadLine()
Console.WriteLine("Please enter your gender (M/F):")
Gender = Console.ReadLine()
Console.WriteLine("Vaccinated status (True/False): ")
Status = Console.ReadLine()

If Status = "True" Then


Console.WriteLine("{0}, {1}, {2}", Name, Gender, "True")
Else
Console.WriteLine("{0}, {1}, {2}", Name, Gender, "False")
End If

Console.ReadLine()
End Sub
2. Write a program to calculate the total area of a circle. The program will ask the user to
enter the Radius of the circle.
Formula :Area = Pi * Radius * Radius , Pi = 3.14159

Note : Use Integer data type for Radius, Real data type for Area

Module Module1

Sub Main()
'Write a program to calculate the total area of a circle. The program will ask the user to enter the Radius of the
circle.
' Formula: Area = Pi * Radius * Radius , Pi = 3.14159

Const PI = 3.14159
Dim radius As Integer
Dim area As Single

Console.WriteLine("Please enter radius:")


radius = Console.ReadLine()
area = PI * radius * radius
Console.WriteLine("Area = {0}", area)

Console.ReadLine()

End Sub

End Module
3. Write a program to calculate the hypotenuse of right triangle. Ask the user to input the 2
sides.
Module Module1

Sub Main()
'Write a program to calculate the hypotenuse of right triangle. Ask the user to input the 2 sides.

Dim x, y As Integer
Dim hypotenuse As Single

Console.WriteLine("Please enter length of side 1:")


x = Console.ReadLine()
Console.WriteLine("Please enter length of side 2:")
y = Console.ReadLine()

hypotenuse = Math.Sqrt((x * x) + (y * y))


Console.WriteLine("The length of hypotenuse is {0}", hypotenuse)
Console.ReadLine()

End Sub

End Module

4. Write a program to calculate the volume of a cylinder.


Module Module1

Sub Main()
'Write a program to calculate the volume of a cylinder.

Const PI = 3.14159
Dim radius, height As Integer
Dim volume As Single

Console.WriteLine("Please enter radius:")


radius = Console.ReadLine()
Console.WriteLine("Please enter height of cylinder:")
height = Console.ReadLine()

volume = PI * radius * radius * height


Console.WriteLine("The volume of cylinder is {0}", volume)
Console.ReadLine()

End Sub

End Module
5. According to Plato, a man should marry a woman whose age is half his age plus seven
years. Write a program that requests a man’s age as input and gives the ideal age of his
wife.
Module Module1

Sub Main()
'According to Plato, a man should marry a woman whose age is half his age plus seven years. Write a program
that requests a man’s age as input and gives the ideal age of his wife.

Dim manAge As Integer


Dim womanAge As Integer

Console.WriteLine("Please enter a man's age:")


manAge = Console.ReadLine()
womanAge = manAge / 2
Console.WriteLine("Ideal age of wife is {0}", womanAge)
Console.ReadLine()

End Sub

End Module

6 (a) A marathon runner records their time for a race in hours, minutes and seconds.
An algorithm is shown below in structured English.

INPUT race time as hours, minutes and seconds


CALCULATE race time in seconds
STORE race time in seconds
OUTPUT race time in seconds
(b) The identifier table needs to show the variables required to write a program for this
algorithm.
Complete the table.

Identifi Data type Descripti


er on
RaceHours INTEGER The hours part of the race time.
raceMinutes Integer The minute part of the race time.

raceSeconds Integer The seconds part of the race time.

Total seconds Integer Total seconds of the race time.

Module Module1
Sub Main()
Dim raceHours As Integer
Dim raceMinutes As Integer
Dim raceSeconds As Integer
Dim Totalseconds As Integer

Console.WriteLine("Please enter the hours part of the race time:")


raceHours = Console.ReadLine()
Console.WriteLine("Please enter the minutes part of the race time:")
raceMinutes = Console.ReadLine()
Console.WriteLine("Please enter the seconds part of the race time:")
raceSeconds = Console.ReadLine()
Totalseconds = (raceHours * 3600) + (raceMinutes * 60) + raceSeconds
Console.WriteLine("The total seconds of the race is {0}", Totalseconds)
Console.ReadLine()
End Sub

End Module
7. (a) A program stores data about hospital patients.

Give a suitable identifier name for each of the data items.

- PatientTemp
- RoomTemp
- IDnumber
- NurseName

(b) Write a program to display the variables with the given values as follows:

Module Module1

Sub Main()
Dim MyGreeting As String = "Happy Birthday"
Dim MyInitial As Char = "C"
Dim AgeInYears As Integer = 27
Dim Weight As Decimal = 60.5
Dim Married As Boolean = True
Dim Children As Boolean = True

Console.WriteLine("Greeting is {0}", MyGreeting)

Console.WriteLine("Initial is {0}", MyInitial)

Console.WriteLine("Age is {0}", AgeInYears)

Console.WriteLine("Weight is {0}", Weight)

Console.WriteLine("Marital Status is {0}", Married)

Console.WriteLine("Children is {0}", Children)


Console.ReadLine()
End Sub

End Module

You might also like