In Visual Basic:
Think of a function, then write its definition and document what the function does. Examples that are appropriate: Check if a number is negative, if a number is even, if a number is odd. Other examples include, a function that returns the the smallest number in an array, the largest number in an array, the average of an array.
Your answer must be unique and not from the book, so make sure you read all posted messages before you post your example.
This is a full program for prime number checking, it uses function. We should have a form named form1, and one label, one textbox and a button. We must change some properties of these controls.
| Control | property | changes |
| Label1 | text | change the text property to " enter an integer" |
| TextBox1 | name | chage name totxtPrime |
| Button1 | txt,name | change name to btnPbtnPrimeOrNot and text to Check Prime |
After change these properties, double click the button, we would redirected to the code window. Write the following code there. Public Class Form1
Private Function PrimeN(num As Integer)As Integer
Dim i as Integer
'This is the called PrimeN Function, note that it has one argument num with Integer data type. The 'As Integer' statement outside the parenthesis indicates the function returns an integer value.
PrimeN=1
'Set PrimeN variable to 1 at first. Then divide each of the variables from 2 to n-1, and take its reminder. If the reminder is 0, which means it is also a factor of num. A prime number has only two factors 1 and the number it self.
For i = 2 To (num – 1)
If num Mod i = 0 Then
PrimeN = 0
'Set PrimeN to 0, if any numbers in the loop give a reminder 0, which means it is not a prime. Then we dont want to check other i values. So exit from loop
Exit For
'Exiting from loopEnd If
'End of if statement
Next
'end of loop
End Function
'end of function
Private Sub btnPrimeOrNot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrimeOrNot.Click
'When double click the button we would be here
Dim num, status As Integer
'declaring num for storing textbox value
num = Val(txtPrime.Text)
'Val() method convert the textbox string data into integer and assign it to num.
status = PrimeN(num)
'calling Function named PrimeN(), and assign the returned value to status variable.
If status = 0 Then
'After returned from called Function status variable should contain either 0 or1. If it is 0, then show message not prime
MessageBox.Show(“Not prime”)
Else
'If status is 1, show message as Prime
MessageBox.Show(“prime”)
End If
'end if stetement
End Sub
'end sub routine
End Class
In Visual Basic: Think of a function, then write its definition and document what the function...
Write a menu based program implementing the following functions: (0) Write a function called displayMenu that does not take any parameters, but returns an integer representing your user's menu choice. Your program's main function should only comprise of the following: a do/while loop with the displayMenu function call inside the loop body switch/case, or if/else if/ ... for handling the calls of the functions based on the menu choice selected in displayMenu. the do/while loop should always continue as long...
Write a C++ function, lastLargestIndex that takes as parameters an int array and its size and returns the index of the "last occurrence" of the largest element in the array. Include another function to print the array. Also, write a program to test your function. [HINTS) Create an array of size 15 in the main function and initialize it with the values shown in the below sample output. Pass the array and its size to function lastLargestindex; function lastLargestindex returns...
1.1. Write a function named "areFirstTwoTheSame AsLast TwoChars" that accepts a string. It returns true if the first two characters and the last two characters of the string are the same. It returns false otherwise. In addition, if the string is empty or has only one character, it also returns false. For example, these are the strings with their expected return values false falsc "AB" true "ABA" false "ABAB" trus "ABBA" false "ABCABC false "ABCCAB" true 1.2 Write a function...
Write a definition for a class named Book with attributes title, price and author, where author is a Contact object and title is a String, and price is a float number. You also need to define the Contact class, which has attributes name and email, where name and email are both String. Instantiate a couple of Book objects that represents books with title, price and author (You can come up with the attributes values for each object) Write a function...
Consider the following program that reads a number of nonnegative integers into an array and prints the contents of the array. Complete the missing parts, add new function prototypes and function definitions, and test the program several times. Add the following to the program: Write a void function that prints the list of nonnegative integers in reverse. Write a void function that prints all the numbers stored in the list that are greater than 10. It will also print the...
Develop a system flowchart and then write a menu-driven C++ program that uses user-defined functions arrays, and a random number generator. Upon program execution, the screen will be cleared and the menu shown below will appear at the top of the screen and centered. The menu items are explained below. Help Smallest Quit H or h ( for Help ) option will invoke a function named help() which will display a help screen. The help screen(s) should guide the user...
Week 5 Programming Lab - Broadway Ticket Group Discount ( Web
Design With Visual Basic)
Submit Assignment
Due No Due Date
Points 100
Submitting a text entry box or a file upload
Complete the following case programming assignment. To upload
and submit the program and materials you created, click the Choose
File button to find and select your saved documents. Make sure that
the files are saved with your last name in the file name (Example:
ch4_case1_Jones.doc).
BROADWAY TICKET GROUP...
In the space below, write a C function definition for a function named StrLower, which will receive one parameter, a pointer to a null-terminated string (i.e., pointer to char), convert each character in the string to lowercase (using the tolower function from <ctype.h>), and return nothing to the caller. Inside the function definition, you may use a for loop or a while loop. If you use any variables other than the incoming parameter, you must define them locally in the...
1. Write a C programme by using visual Studio: a) Write a function with parameters that returen the largest of three integer arguments. So users could call your function (name: max3) to output the maximum of three input values. b) Make a function outside of the main routine. And in the main routine, please call this function and print the harmonic mean. The harmonic mean of two numbers is obtained by taking the inverses of the two numbers, averaging them,...