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
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...
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....
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...
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...
• 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.
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the...
C# Programming Using the Example provided in this Week Folder,Create a Console application that solve the following problem: The heating system in a school should be switched on if the average temperature is less than 17 degrees Celsius. The average temperature is found from the temperatures in the Math, English and IT departments. You are required to write a program that allows the user to input 3 temperatures. The program calculates and displays the average temperature and then displays "heating...
Using C++ 1. Create a program that asks the user to create 5 triangles, asking for...
Using C++ 1. Create a program that asks the user to create 5 triangles, asking for 5 bases and 5 heights (you can use an array), have a function to print the triangle bases, heights, and areas 2. Create a structure for the Triangle that holds the base and height of the triangles. Ask the user for 5 triangles, and print them. 3. Create an array of 5 structures - ask the user for 5 triangles, and then print the...
Using C programming Create a function called printMenu( ) with the following properties: Has no function...
Using C programming Create a function called printMenu( ) with the following properties: Has no function inputs or output. Prints the following menu to the screen: 1. Enter user name. 2. Enter scores. 3. Display average score. 4. Display summary. 5. Quit Create a function called printLine( ) with the following properties: Takes as input a char Takes as input an integer corresponding to the number of times to print the character Has no function output. For example, if we...
Create a C# application You are to create a class object called “Employee” which included eight...
Create a C# application You are to create a class object called “Employee” which included eight private variables: firstN lastN dNum wage: holds how much the person makes per hour weekHrsWkd: holds how many total hours the person worked each week. regHrsAmt: initialize to a fixed amount of 40 using constructor. regPay otPay After going over the regular hours, the employee gets 1.5x the wage for each additional hour worked. Methods:  constructor  properties  CalcPay(): Calculate the regular...
(2nd Problem) From Chapter 15 on page 1080, do problem #5. Recursive function that computes the...
(2nd Problem) From Chapter 15 on page 1080, do problem #5. Recursive function that computes the same of values in an array. To test this function in the main, create the following array: int a[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; #15. Write a recursive function that finds and returns the sum of the elements of an int array. Also, write a program to test your function.
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT