[[In Pseudocode in no particular programming language, but if you need one then in Visual Basic]]
Design a program that reads an arbitrary number of runners’ names and their times and outputs the name of the runner or runners with the fastest time.
Design a module that reads all the runners’ names and times and stores the names and times in parallel arrays. What are this module’s parameters and what does it return?
Use parameters and returns in all of your modules.
Expert Answer
‘The vb console application that prompts user to enter names
‘of five runners and time taken in seconds to complete running.
‘Then finds the name of the runner who finisih in less time.
Module Module1
Dim size As Integer = 5
Sub Main()
Dim names(size) As String
Dim timeTaken(size) As Integer
Dim pos As Integer
Console.WriteLine(“Enter Names”)
‘calling readNames module
readNames(names)
Console.WriteLine(“Enter time in seconds”)
‘calling readTime module
readTime(timeTaken)
‘calling function findFastestRunner
findFastestRunner(timeTaken)
‘print fastest runner and time he taken
Console.WriteLine(“Fasteset Runner Name: {0}”, names(pos))
Console.WriteLine(“Fasteset Runner Time taken MM:SS = {0}:{1}”,
timeTaken(pos) / 60, timeTaken(pos) Mod 60)
Console.ReadKey()
End Sub
‘Function that takes time array and find the position
‘of fastest runner
Public Function findFastestRunner(ByRef timeTaken() As Integer) As Integer
Dim pos As Integer = -1
Dim fastestTime As Integer = timeTaken(0)
For index = 1 To size – 1
If timeTaken(index) < fastestTime Then
pos = index
End If
Next
Return pos
End Function
‘Procedure that read names of the runners
Public Sub readNames(ByRef names() As String)
For index = 0 To size – 1
Console.WriteLine(“Enter name {0}”, index + 1)
names(index) = Console.ReadLine()
Next
End Sub
‘function that reads time of runners in seconds
Public Sub readTime(ByRef timeTaken() As Integer)
For index = 0 To size – 1
Console.WriteLine(“Enter time taken {0}”, index + 1)
timeTaken(index) = Convert.ToInt32(Console.ReadLine())
Next
End Sub
End Module
———————————————————————————————–
The following is a sample output: