Question

Questions: 1. (5 marks) Create a VB.NET Console Application that defines a function Smallest and calls...

Questions:
1. Create a VB.NET Console Application that defines a function Smallest and calls this function from the main program. The function Smallest takes three parameters, all of the Integer data type, and returns the value of the smallest among the three parameters. The main program should
(1) Prompt a message (using Console.WriteLine) to ask the user to input three integers.
(2) Call the built-in function Console.ReadLine() three times to get the user’s input.
(3) Convert the user’s input from strings to integers.
(4) Call the function Smallest, with the user’s input as its parameters.
(5) Display the result of the function Smallest in the Console window using Console.WriteLine.
You may assume that the user always correctly inputs integers from the keyboard, and your program does not have to check whether the user inputs something other than integers. Print your program and handwrite the user’s input and output at the end of the printout of your program.
2. Create a VB.NET Console Application that does the following:
(1) Create an Integer array which contains 10 elements.
(2) Assign the following values to the elements in the array:
9, 1, 8, 4, 2, 6, 7, 3, 5, 10
(3) Use the For-Each-loop to compute and printout the sum of all elements of the array in the Console window.

Homework Answers

Answer #1

1.SmallestOfThree.vb

Module SmallestOfThree
'function that takes three parameters and returns the smallest of the three integers
Function Smallest(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) As Integer
'declare a variable that hold the smallest number
Dim min As Integer

'check if a is less than b and c
If a < b And a < c Then
'if yes then set a to min
min = a

'check if b is less than a and c
ElseIf b < a And b < c Then
'if yes then set b to min
min = b

'check if c is less than a and b
ElseIf c < a And c < b Then
'if yes then set c to min
min = c
End If

'return min
Smallest = min

End Function
Sub Main()
'declare thre variables to hold integers
Dim a, b, c As Integer
'prompt a message to the user
Console.Write("Enter three integers: ")
'read three integers from the user
a = Convert.ToInt32(Console.ReadLine())
b = Convert.ToInt32(Console.ReadLine())
c = Convert.ToInt32(Console.ReadLine())

Dim min As Integer
'by the smallest number by callinf the Smallest function by passing a, b and c as parameters
min = Smallest(a, b, c)
'display the result to the user
Console.WriteLine(vbNewLine + "The smallest of the given numbers is: " + min.ToString())
Console.ReadKey()
End Sub

End Module

Output

2.Sum of Elements in Array

Module Array
Sub Main()

'declare an array of 10 elements
Dim myArray(10) As Integer

'assign values to the elements in the array
myArray = {9, 1, 8, 4, 2, 6, 7, 3, 5, 10}

'declare a variable to hold the sum
Dim sum As Integer = 0

'using a for each loop get the sum of the elements in the array
For Each ele As Integer In myArray
sum = sum + ele 'add ele to sum
Next

'display the sum to the console
Console.WriteLine("The sum of the elements in the array is: " + sum.ToString())
Console.ReadKey()
End Sub
End Module

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input...
Java Code: Console IO Practice Exercise The purpose of this exercise is to practice console input and output with the Java console. Setup: Create a class called ConsolePractice with a main method. Create a static field in your class that stores a scanner object. You will use this scanner for all user input. private static Scanner scanner = new Scanner(System.in); Part A: Create a static method called “divide”. Your method should do the following: Accept two integers as parameters, a...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns...
Write a function in c using #include <stdio.h> that takes a one-dimensional integer array and returns the index of the first occurance of the smallest value in the array. Your function must be able to process all the elements in the array. Create a function prototype and function definition (after the main function). Your main function should declare a 100 element integer array. Prompt the user for the number of integers to enter and then prompt the user for each...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
Write a program in c++ to Convert an array of inches to an array of centimeters....
Write a program in c++ to Convert an array of inches to an array of centimeters. The program should contain a function called inchesTOcm with three parameters (inches array that contains the values in inches, cm array to save the result in, and an integer variable that defines the length of the array). In the main function: 1. Define an array (inches) of length 3. 2. Initialize the array by asking the user to input the values of its elements....
Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays) Part 1: Create...
Class work # 12 / Chapter 6 –> Arrays 3 (two dimensional arrays) Part 1: Create a 2-by-3 integer array and initialize it with 6 integers of your choice. Using nested for loops, display the contents of the array on the screen Part 2: (Continue on part 1) Display the sum of all the integers in the array that you created in part 1. Create a function Part 3: Create a function that will display the elements of the array...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to...
c++ Write a program that calls a function calculateSum to calculate the sum from -1 to N. The function calculateSum has one parameter N of type integer and returns an integer which represents the sum from -1 to N, inclusive. Write another function calculateAverage that calculates an average. This function will have two parameters: the sum and the number of items. It returns the average (of type float). The main function should be responsible for all inputs and outputs. Your...
Write a function that accepts an int array and the array’s size as arguments. The function...
Write a function that accepts an int array and the array’s size as arguments. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array, and initialize the unused elements of the second array with 0. The function should return a pointer to the new array. Demonstrate the function by using it in a main program that reads an integer N...
FOR PYTHON Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay...
FOR PYTHON Rewrite your pay computation with time-and-a-half for overtime and create a function called compute_pay which takes two parameters (hours and rate). Enter Hours: 45 Enter Rate: 10 Pay: 475.0 YOU WILL NEED THREE FUNCTIONS: the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) Call the functions and passing the arguments in the "main" function. Example: def main(): the_hours, the_rate = get_input() the_pay = compute_pay(the_hours, the_rate) print_output(the_pay) main() ----- Testing the outputs of your code: 1 for the valid...
• First, create a function called addNumber, which has a formal parameter for an array of...
• First, create a function called addNumber, which has a formal parameter for an array of integers and increase the value of each array element by a random integer number between 1 to 10. o Add any other formal parameters that are needed. • Second, create another function called printReverse that prints this array in reverse order. • Then, you need to write a C++ program to test the use of these two functions.
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the...
Subject- ( App Development for Web) ( language C#, software -visual studio) Exact question is-Firstly the console calculator is created which perform multiply,divide,sub and add, operation and it accept all type of data (divide by 0 case as well ).Now the main motive is to create the library project from the console calculator project .Than we have to create a unit test project which test the functionality of added library.Make test like Test 1. multiply two positive number,Test 2. Add...