Functions: greeting + farewell Write a Visual Basic program whose Main must be like this:
public static void Main()
{
SayHello();
SayGoodbye();
}
SayHello and SayGoodbye are functions that you must define and that will be called from inside Main. |
Function with parameters Write a Visual Basic program whose Main must be like this:
public static void Main()
{
SayHello("John");
SayGoodbye();
}
SayHello and SayGoodbye are functions that you must define and that will be called from inside Main. As you can see in the example. SayHello must accept an string as a parameter. |
Function returning a value Write a Visual Basic program whose Main must be like this:
public static void Main()
{
int x= 3;
int y = 5;
Console.WriteLine( Sum(x,y) );
}
"Sum" is a function that you must define and that will be called from inside Main. As you can see in the example, it must accept two integers as parameters, and it must return an integer number (the sum of those two numbers).
|
Function returning a value V2 Write a Visual Basic program whose Main must be like this:
public static void Main()
{
__Console.WriteLine("\"Hello, how are you\" contains {0} spaces", ____CountSpaces("Hello, how are you") );
}
CountSpaces is a function that you must define and that will be called from inside Main.
As you can see in the example, it must accept an string as a parameter, and it must return an integer number (the amount of spaces in that string). |
Function write centered Write a Visual Basic function to write centered on screen the text that is indicated as a parameter (supposing a screen width of 80 characters):
WriteCentered("Hello!"); |
Function write underlined Write a Visual Basic function able to write centered on screen the text that is indicated as a parameter (supposing a screen width of 80 characters) and then underline it (writing several hyphens under that word):
WriteUnderlined("Hello!"); |
Function sum of array Write a Visual Basic program to calculate the sum of the elements in an array. "Main" should be like this:
public static void Main()
{ int[] example = {20, 10, 5, 2 };
Console.WriteLine(
__"The sum of the example array is {0}", __Sum(example));
}
}
|
Function double Write a Visual Basic function named "Double" to calculate and return an integer number doubled. For example. Double(7) should return 14. |
Function Double reference parameter Write a Visual Basic function named "Double" to calculate the double of an integer number, and modify the data passed as an argument. It must be a "void" function and you must use "refererence parameters". For example.
x = 5;
Double(ref x);
Console.Write(x);
would display 10 |
Function swap reference parameters Write a Visual Basic function named "Swap" to swap the values of two integer numbers, which are passed by reference.
An example of use might be:
int x=5, y=3;
Swap(ref x, ref y);
Console.WriteLine("x={0}, y={1}", x, y);
(which should write "x=3, y=5") |