KEMBAR78
Exercises in Visual Basic | PDF | Boolean Data Type | Software Engineering
0% found this document useful (0 votes)
25 views5 pages

Exercises in Visual Basic

The document contains four exercises on data structures and programming in Visual Basic.NET. The exercises involve managing data related to travel, speed measurements, herbal products, and school data of children.
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)
25 views5 pages

Exercises in Visual Basic

The document contains four exercises on data structures and programming in Visual Basic.NET. The exercises involve managing data related to travel, speed measurements, herbal products, and school data of children.
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/ 5

Exercise 1

A travel agency must prepare a draft catalog with N special trips. For each trip, the following is known:
destination
able to fulfill the following requests:
Load and display the data in appropriate listboxes
2.Enter the amount you have available to spend, display the destinations that have a cost.
less than or equal to (search with for loop)
3. Enter a destination via the keyboard, display the cost and the number of available seats, sending a message.
if it is not present in the list (search with found)
4. Order the trips by destination in alphabetical order and display the resulting list with associated costs.
the available spots in the listboxes.

Exercise 2
A small provincial town has equipped itself with some speed detectors and wishes to automate certain operations.
Two parallel vectors containing the license plate number and the recorded speed of the vehicle should be provided as input.
These data refer to N vehicles circulating on a stretch of road in the municipality, on a specific day. Write a
program that, given N as input, after loading and displaying the vectors in two listboxes, allows to manage the following
requests:
1. Count: to count and show how many vehicles have exceeded the speed limit provided as input
2. Violations: display the vehicle's license plate with maximum speed
3. License-vehicles: given the license plate of a vehicle, display its speed, sending a message if it is not found.

Exercise 3
The products treated in an herbalist's shop are stored in two parallel arrays: name of the medicine, selling price.
After loading the N products into the vectors, write a program that allows managing the following requests:
1. Name-minimum price: sort the vectors (bubble sort) while maintaining data parallelism, then show the
name of the medicine with the lowest price
2. Economical: count and display how many medicines have a price lower than a given input amount.
3. Product-class: given the name of a product, display its price, sending a message if the product does not
it is located
4. Media: calculate and display the price of medications.

Exercise 4
Given 3 vectors with children's names from a school, age, and gender.
The name of the child up to age
2. The average age of females
3.Sort the vectors based on the age of the children (from oldest to youngest)
4. Given a child's name, display their age and gender, sending a message if the name is not found.
Public ClassForm1
Dim N As Integer
Dimi As Integer
DimImp As Integer
DimD(50) As String
DimP(50) As Integer
DimC(50) As Integer
DimTrovatoAs Boolean
DimKey As String
Private Sub BtnCarica_Click(sender As Object, e As EventArgs) Handles BtnCarica.Click
TxtN.Text
For i = 0 to N - 1
D(i) = InputBox("Enter the destination of the " + Str(i + 1) + "th trip",
Destination
P(i) = Val(InputBox("How many available seats are there for " + D(i) + "?", "Seats
available
C(i) = Val(InputBox("How much does the trip to " + D(i) + " cost?", "Cost of the trip"))
ListaD.Items.Add(D(i))
ListaP.Items.Add(P(i))
ListaC.Items.Add(C(i))
Next
End Sub

Private Sub BtnTrova_Click(sender As Object, e As EventArgs) Handles BtnTrova.Click


TxtImp.Text
For i = 0 to N - 1
IfImp >= C(i) Then
ListDest.Items.Add(D(i))
End If
Next
End Sub

Private Sub BtnTrovaD_Click(sender As Object, e As EventArgs) Handles BtnTrovaD.Click


Key = TxtDest.Text
Trovato =False
i=0
Do
If Key = D(i) Then
Found
TxtPD.Text = P(i)
TxtCV.Text = C(i)
Else
i=i+1
End If
Loop Until Found = True Or = N
If Trovato = False Then
MsgBox("The destination is not available", "Search destination")
End If
End Sub
End Class
Public Class Form1
Dim N As Integer
DimV(50) As Integer
DimT(50) As String
Dim L As Integer
DimKey As String
DimTrovatoAs Boolean
DimVMAs Integer
Dimi As Integer
DimCont As Integer
Dim Max As Integer

Private Sub BtnCarica_Click(sender As Object, e As EventArgs) Handles BtnCarica.Click


N = Val(TxtN.Text)
LV = Val(TxtLV.Text)
For i = 0 to N - 1
InputBox("Enter the license plate number of the " + Str(i + 1) + " vehicle","License Plate")
V(i) = Value(InputBox("Enter the speed of the vehicle " + T(i), "Speed"))
ListaTarga.Items.Add(T(i))
ListaV.Items.Add(V(i))
Next
Cont = 0
i=0
For i = 0 to N - 1
If V(i) > LV Then
ListaLimite.Items.Add(T(i))
Cont = Cont + 1
End If
Next
TxtNVL.Text = Cont
Max = -32678
i=0
Fori = 0ToN - 1
If V(i) > Max Then
Max = V(i)
End If
Next
Max
End Sub

Private Sub BtnTrova_Click(sender As Object, e As EventArgs) Handles BtnTrova.Click


Key = TxtTarga.Text
i=0
Trovato =False
Do
If Key = T(i) Then
Found
TxtVC.Text = V(i)
Else
i=i+1
End If
Loop Until Found = True Or = N
IfTrovato = False Then
MsgBox("The license plate is not present")
End If
End Sub
End Class
Public Class Form1
Dim N As Integer
DimiAs Integer
DimName(50) As String
DimAge(50) As Integer
DimSesso(50) As String
DimContAs Integer
DimEFAs Integer
DimEMAs Integer
DimKey As String
DimTrovatoAs Boolean
DimOrdinato As Boolean
DimSup As Integer
DimComodoNAs String
DimComodoEAs Integer
DimComodoSAs String
Private Sub BtnCarica_Click(sender As Object, e As EventArgs) Handles BtnCarica.Click
N = TxtN.Text
For i = 0 to N - 1
InputBox("Enter the name of the
Age(i) = Val(InputBox("Enter the age of " + Name(i), "Student Age"))
InputBox("insert the gender of " + Nome(i) + " (F/M)", "Student's gender")
ListNames.Items.Add(Name(i))
ListaEtà.Items.Add(Age(i))
ListaSesso.Items.Add(Sesso(i))
Next
Cont = 0
EF = 0
i=0
For i = 0 to N - 1
If Sesso(i) = 'F' Then
Cont = Cont + 1
EF = EF + Age(i)
End If
Next
EM = EF / Cont
TxtMF.Text = EM
End Sub

Private Sub BtnOrdina_Click(sender As Object, e As EventArgs) Handles BtnOrdina.Click


Sup = N
Ordinato =False
i=0
Do While(Sup > 1 And Ordnated = False)
Ordinato =True
Fori = 0 to Sup - 1
If Age(i) > Age(i + 1) Then
Age(i)
Age(i) = Age(i + 1)
Age(i + 1) = ComfortableE
ComodoN = Name(i)
Name(i) = Name(i + 1)
Name(i + 1) = CommodityN
Sex(i)
Gender(i) = Gender(i + 1)
Sex(i + 1) = ComfortableS
End If
Next
Sup = Sup - 1
Loop
End Sub

Private Sub BtnTrova_Click(sender As Object, e As EventArgs) Handles BtnTrova.Click


i=0
Key
Trovato =False
Do
If Key = Name(i) Then
Found
TxtEA.Text = Age(i)
TxtSA.Text = Gender(i)
Else
i=i+1
End If
Loop Not found = True Ori = N
If Found = False Then
Key = MsgBox("The student is not present")
End If
End Sub

Private Sub BtnCancella_Click(sender As Object, e As EventArgs) Handles BtnCancella.Click


ListaNomi.Items.Clear()
ListAge.Items.Clear()
ListaSesso.Items.Clear()
End Sub
End Class

You might also like