basic vb problems

32
MS LAB ASSIGNMENT #1 Mukesh Kumar Das 015A029 Page 1 Problem Statement: WAP to input two integers and print their sum. Source Code: Module Module1 Dim a, b, sum As Integer Sub Main() Console.WriteLine("Enter first number") a = Console.ReadLine Console.WriteLine("Enter Next number") b = Console.ReadLine sum = a + b Console.WriteLine(" The sum is" & sum) End Sub End Module Result Screen:

Upload: mukesh-das

Post on 16-Apr-2017

229 views

Category:

Software


1 download

TRANSCRIPT

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 1

Problem Statement:

WAP to input two integers and print their sum.

Source Code:

Module Module1 Dim a, b, sum As Integer Sub Main() Console.WriteLine("Enter first number") a = Console.ReadLine Console.WriteLine("Enter Next number") b = Console.ReadLine sum = a + b Console.WriteLine(" The sum is" & sum) End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 2

Problem Statement:

WAP to input two integers and print their difference.

Source Code:

Module Module1 Dim a, b, diff As Integer Sub Main() Console.WriteLine("Enter first number") a = Console.ReadLine Console.WriteLine("Enter Next number") b = Console.ReadLine diff = a - b Console.WriteLine(" The difference is" & diff) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 3

Problem Statement:

WAP to input two integers and print their product.

Source Code:

Module Module1 Dim a, b, Pro As Integer Sub Main() Console.WriteLine("Enter first number") a = Console.ReadLine Console.WriteLine("Enter Next number") b = Console.ReadLine Pro = a * b Console.WriteLine(" The Product is" & Pro) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 4

Problem Statement:

WAP to input two integers and print their quotient.

Source Code:

Module Module1 Dim a, b As Integer Dim QnAs Double Sub Main() Console.WriteLine("Enter first number") a = Console.ReadLine Console.WriteLine("Enter Next number") b = Console.ReadLine Qn = a / b Console.WriteLine(" The Quotient is" &Qn) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 5

Problem Statement:

WAP to input an integer and print its square.

Source Code:

Module Module1 Dim a, SqAs Integer Sub Main() Console.WriteLine("Enter number") a = Console.ReadLine Sq = a ^ 2 Console.WriteLine(" The Square is" &Sq) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 6

Problem Statement:

WAP to input an integer and print its cube.

Source Code:

Module Module1 Dim a, CbAs Integer Sub Main() Console.WriteLine("Enter number") a = Console.ReadLine Cb = a ^ 3 Console.WriteLine(" The Cube is" &Cb) Console.ReadLine() End Sub End Module

Result Screen:

Problem Statement:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 7

WAP to input an integer and print its square root.

Source Code:

Module Module1 Dim a As Integer Dim SqrAs Double Sub Main() Console.WriteLine("Enter number") a = Console.ReadLine Sqr = a ^ (1 / 2) Console.WriteLine(" The Square root is" &Sqr) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 8

Problem Statement:

WAP to input an integer and print its cube root.

Source Code:

Module Module1 Dim a As Integer Dim CbrAs Double Sub Main() Console.WriteLine("Enter number") a = Console.ReadLine Cbr = a ^ (1 / 3) Console.WriteLine(" The Cube root is" &Cbr) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 9

Problem Statement:

WAP to calculate the area of a rectangle

Source Code:

Module Module1 Dim l, b, area As Integer Sub Main() Console.WriteLine("Enter length") l = Console.ReadLine Console.WriteLine("Enter Breadth") b = Console.ReadLine area = l * b Console.WriteLine(" The area is" & area) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 10

Problem Statement:

WAP to calculate the perimeter of a rectangle

Source Code:

Module Module1 Dim l, b, pm As Integer Sub Main() Console.WriteLine("Enter length") l = Console.ReadLine Console.WriteLine("Enter Breadth") b = Console.ReadLine pm = 2 * (l + b) Console.WriteLine(" The perimeter is" & pm) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 11

Problem Statement:

WAP to calculate the volume of sphere

Source Code:

Module Module1 Dim r, vol As Integer Sub Main() Console.WriteLine("Enter radius") r = Console.ReadLine vol = 4 / 3 * (22 / 7 * r ^ 3) Console.WriteLine(" The volume of sphere is" &vol) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 12

Problem Statement:

WAP to calculate the area of circle

Source Code:

Module Module1 Dim r, area As Integer Sub Main() Console.WriteLine("Enter radius") r = Console.ReadLine area = 22 / 7 * r ^ 2 Console.WriteLine(" The area of circle is" & area) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 13

Problem Statement:

WAP to calculate the circumference of circle

Source Code:

Module Module1 Dim r, circum As Integer Sub Main() Console.WriteLine("Enter radius") r = Console.ReadLine circum = 2 * 22 / 7 * r Console.WriteLine(" The circumference of circle is" &circum) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 14

Problem Statement:

WAP to calculate the distance between two points using

distance formula

Source Code:

Module Module1 Dim x1, y1, x2, y2, dis As Integer Sub Main() Console.WriteLine("Enter first x- cordinate of 1st point") x1 = Console.ReadLine Console.WriteLine("Enter first y- cordinate of 1st point") y1 = Console.ReadLine Console.WriteLine("Enter first x- cordinate of 2nd point") x2 = Console.ReadLine Console.WriteLine("Enter first y- cordinate of 2nd point") y2 = Console.ReadLine dis = ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) * 0.5 Console.WriteLine(" The distance between given points is" & dis) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 15

Problem Statement:

WAP to calculate the roots of a quadratic equation

Source Code:

Module Module1 Dim a, b, c, r1, r2 As Double Sub Main() Console.WriteLine("Write Coeffoecient a") a = Console.ReadLine Console.WriteLine("Write Coeffoecient b") b = Console.ReadLine Console.WriteLine("Write Coeffoecient c") c = Console.ReadLine r1 = (-b + (b ^ 2 - 4 * a * c) ^ 0.5) / (2 * a) r2 = (-b - (b ^ 2 - 4 * a * c) ^ 0.5) / (2 * a) Console.WriteLine("The first root is" & r1) Console.WriteLine("The second root is" & r2) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 16

Problem Statement:

WAP to calculate the simple interest and amount of any

principal amount

Source Code:

Module Module1 Dim amount, SI, principal As Decimal Dim rate As Double Dim year As Integer Sub Main() Console.WriteLine("Enter principal") principal = Console.ReadLine Console.WriteLine(" Enter Rate") rate = Console.ReadLine Console.WriteLine("Enter year") year = Console.ReadLine SI = (principal * rate * year) / 100 amount = principal + SI Console.WriteLine(" The Simple Interest is" & SI) Console.ReadLine() Console.WriteLine(" The amount is" & amount) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 17

Problem Statement:

WAP to calculate the area of a triangle using Heron’s formula

Source Code:

Module Module1 Dim a, b, c, s, area As Integer Sub Main() Console.WriteLine("Enter side a") a = Console.ReadLine Console.WriteLine(" Enter side b") b = Console.ReadLine Console.WriteLine("Enter side c") c = Console.ReadLine s = (a + b + c) / 2 Console.WriteLine(" The semi perimeter is" & s) Console.ReadLine() area = (s * (s - a) * (s - b) * (s - c)) * 1 / 2 Console.WriteLine(" The The area of triangle is" & area) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 18

Problem Statement:

WAP to input temperature in Celsius and convert into

Fahrenheit

Source Code:

Module Module1 Dim ºC, ºF As Double Sub Main() Console.WriteLine("Enter Temperature in Celsius") ºC = Console.ReadLine ºF = ºC * 1.8 + 32.0 Console.WriteLine(" Temperature in Fahrenheit" & ºF) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 19

Problem Statement:

WAP to Display the area of 4 walls.[A=2H(L+B)]

Source Code:

Module Module1 Dim l, b, h, area As Integer Sub Main() Console.WriteLine("Enter length") l = Console.ReadLine Console.WriteLine("Enter Breadth") b = Console.ReadLine Console.WriteLine("Enter height") h = Console.ReadLine area = 2 * h * (l + b) Console.WriteLine(" The area of the four walls is" & area) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 20

Problem Statement:

WAP to display the area of 4 walls and ceiling.[A=2H(L+B)+LB]

Source Code:

Module Module1 Dim l, b, h, area As Integer Sub Main() Console.WriteLine("Enter length") l = Console.ReadLine Console.WriteLine("Enter Breadth") b = Console.ReadLine Console.WriteLine("Enter height") h = Console.ReadLine area = 2 * h * (l + b) + l * b Console.WriteLine(" The area of the four walls and ceiling is" & area) Console.ReadLine() End Sub End Module

Source Code:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 21

Problem Statement:

WAP to display volume of hemisphere.[V=(2/3)πR3]

Source Code:

Module Module1 Dim r, vol As Integer Sub Main() Console.WriteLine("Enter radius") r = Console.ReadLine vol = 2 / 3 * (22 / 7 * r ^ 3) Console.WriteLine(" The volume of hemisphere is" &vol) Console.ReadLine() End Sub End Module

Source Code:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 22

Problem Statement:

WAP to convert Nepali currency into Dollar and Indian Currency.

Source Code:

Module Module1 Dim ncr, icr, USD As Double Sub Main() Console.WriteLine("Enter Nepali currency") ncr = Console.ReadLine icr = ncr * 0.65 Console.WriteLine(" The equivalent indian currency is" &icr) Console.ReadLine() USD = ncr * 0.0095 Console.WriteLine(" The equivalent Us Dollar is" & USD) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 23

Problem Statement:

WAP to input cost price and selling price and calculate profit. [P=SP-CP] Source Code:

Module Module1 Dim cp, sp, p As Integer Sub Main() Console.WriteLine("Enter Cost Price") cp = Console.ReadLine Console.WriteLine("Enter Selling Price") sp = Console.ReadLine p = sp - cp Console.WriteLine(" The profit is" & p) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 24

Problem Statement:

WAP to input cost price and selling price and calculate profit percentage. [PP=((SP-CP)/CP)*100] Source Code:

Module Module1 Dim cp, sp, pp As Integer Sub Main() Console.WriteLine("Enter Cost Price") cp = Console.ReadLine Console.WriteLine("Enter Selling Price") sp = Console.ReadLine pp = ((sp - cp) / cp) * 100 Console.WriteLine(" The profit percentage is" & pp) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 25

Problem Statement:

WAP to input cost price and selling price and calculate loss percentage.[LP=((CP-SP)/CP)*100] Source Code:

Module Module1 Dim cp, sp, lp As Integer Sub Main() Console.WriteLine("Enter Cost Price") cp = Console.ReadLine Console.WriteLine("Enter Selling Price") sp = Console.ReadLine lp = ((cp - sp) / cp) * 100 Console.WriteLine(" The lost percentage is" &lp) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 26

Problem Statement:

WAP to calculate distance.[S=UT+1/2(AT2)]

Source Code:

Module Module1 Dim s, u, t, a As Double Sub Main() Console.WriteLine("Enter initial velocity") u = Console.ReadLine Console.WriteLine("Enter acceleration") a = Console.ReadLine Console.WriteLine("Enter time") t = Console.ReadLine s = u * t + 1 / 2 * (a * t ^ 2) Console.WriteLine(" The diatance is" & s) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 27

Problem Statement:

WAP to find potential energy of body. [PE=MGH where G=9.8] Source Code:

Module Module1 Dim m, g, h, pe As Double Sub Main() Console.WriteLine("Enter mass") m = Console.ReadLine Console.WriteLine("Enter acceleration due to gravity") g = Console.ReadLine Console.WriteLine("Enter height") h = Console.ReadLine pe = m * g * h Console.WriteLine(" The potential energy is" &pe) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 28

Problem Statement:

WAP to find selling price where profit percentage and cost price is given. [SP=CP(100+PROFIT%)/100]

Source Code:

Module Module1 Dim cp, sp, pp As Integer Sub Main() Console.WriteLine("Enter Cost Price") cp = Console.ReadLine Console.WriteLine("Enter Profit Percentage") pp = (Console.ReadLine) sp = cp * (100 + pp) / 100 Console.WriteLine(" The selling price" &sp) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 29

Problem Statement:

WAP to ask time in seconds and convert into hours, minutes and seconds. Source Code:

Module Module1 Dim s, a, m, b, h As Double Sub Main() Console.Write("enter time in second: ") s = Console.ReadLine() m = s \ 60 a = s Mod 60 h = m \ 60 b = m Mod 60 Console.WriteLine("time in hour=" & h) Console.WriteLine("time in minute=" & b) Console.WriteLine("time in second=" & a) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 30

Problem Statement:

WAP to ask time in hours and convert into minutes and seconds.

Source Code:

Module Module1 Dim s, a, m, b, h As Double Sub Main() Console.Write("enter time in hour : ") h = Console.ReadLine() s = h * 3600 m = s \ 60 a = s Mod 60 h = m \ 60 b = m Mod 60 Console.WriteLine("time in hour=" & h) Console.WriteLine("time in minute=" & b) Console.WriteLine("time in second=" & a) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 31

Problem Statement:

WAP to ask distance in kilometers and convert into meters and centimeters

Source Code:

Module Module1 Dim km, m, cm, a, b As Double Sub Main() Console.Write("enter length in km: ") km = Console.ReadLine() cm = km * 100000 m = cm \ 100 a = cm Mod 100 km = m \ 1000 b = m Mod 1000 Console.WriteLine(" the length in km is " & km) Console.WriteLine("length in metre=" & b) Console.WriteLine("length in cm=" & a) Console.ReadLine() End Sub End Module

Result Screen:

MS LAB ASSIGNMENT #1

Mukesh Kumar Das 015A029 Page 32

Problem Statement:

WAP to ask distance in meters and convert into kilometers and centimeters.

Source Code:

Module Module1 Dim km, m, cm, a, b As Double Sub Main() Console.Write("enter length in m: ") m = Console.ReadLine() cm = m * 100 m = cm \ 100 a = cm Mod 100 km = m \ 1000 b = m Mod 1000 Console.WriteLine(" the length in km is " & km) Console.WriteLine("length in metre=" & b) Console.WriteLine("length in cm=" & a) Console.ReadLine() End Sub End Module

Result Screen: