Professional Documents
Culture Documents
DATE:
15 August 2016
SESSION:
SUBJECT:
Development Software I
CODE:
OPG10BB
STATIONARY:
Use your question paper for rough work.
All questions must be answered on answer sheets.
Code may be written in pencil.
Calculators may be used.
Place your question paper inside the answer sheet and submit both.
EXAMINER:
Mr G Nel
BCNDIA
EXNDIT
INSTRUCTIONS:
Duration:
1 hour
Maximum Marks:
40
Question 1
Indicate the correct answer for each of the following with an a, b, c or d.
1.1 Which of the following is a good reason for creating methods within a program?
a. Methods are easily reusable.
b. Because all methods must be stored in the same class, they are easy to
find.
c. The Main() method becomes more detailed.
d. All of these are true
1.2 In C#, a method must include all of the following except a _________.
a.
b.
c.
d.
return type
access modifier
body
closing curly brace
1.3 If you want to create a method that other methods in other classes can access
without limitations, you declare the method to be _____.
a.
b.
c.
d.
1.4
unlimited
public
shared
unrestricted
If you use the keyword modifier static in a method header, you indicate that the
method _________.
a.
b.
c.
d.
1.5
cannot be copied
can be called only once
cannot require parameters
is called without an object reference
When an array is passed to a method, the method has access to the arrays
memory address. This means an array is passed by _____.
a.
b.
c.
d.
reference
value
alias
orientation
1.6
1.7
1.8
1.9
return type
identifier
parameter list
All of the above.
1.10
confusion
infusion
revolution
resolution
[10]
Question 2
Use the following C# Main method to answer the questions that follow:
static void Main(string[] args)
{
int firstValue;
double[] numbers = new double[] { 1.1, 2.2, 3.3, 4.4 };
InitializeValue(out firstValue);
Console.WriteLine(MultiplyBy1_5(firstValue));
MultiplyNumbers(numbers, 10);
Console.WriteLine(CountNumbers(numbers));
Console.WriteLine(CountNumbers(1,2,3,4,5,6,7,8,9,10));
Console.WriteLine(CountNumbers(1.7,1.9,1.2,7.5,3.4));
}
Implement the following methods according to the calls made in the Main method:
2.1
Implement the method named InitializeValue. The method must have a prompt
statement that displays the message "Enter an integer value: ". Then the program
has to read in a value, convert it to an integer and assign it to the parameter. Make
use of the built-in TryParse method to ensure that a value of 1 is assigned to the
parameter if the user enters an invalid value. This method must have no return
statement.
(6)
2.2
Implement the method named MultiplyBy1_5. The method must have one
parameter as shown in the call in the main method. This method must return the
parameter multiplied by 1.5.
(4)
2.3
Implement the method named MultiplyNumbers. The method must receive two
parameters (an array and an integer) as shown in the call in the main method. It
must multiply each of the elements of the received array by the received integer.
This method must have no return statement.
(6)
2.4
Implement the method named CountNumbers. The method receive any number of
values as called in the main method and should count and return how many
numbers it received. Take note that the method is called three times in the main
method. You need to implement one method that can handle any of these calls.
(4)
[20]
4
Question 3
You are given the following C# code. Write down the 10 lines of output that will be
displayed by this program:
static void Main(string[] args)
{
int number1 = 10; int number2 = 20; int number3;
methodA(number1);
Console.WriteLine("2. {0}",number1);
methodB(ref number2);
Console.WriteLine("4. {0}",number2);
methodC(out number3, number1, number2);
Console.WriteLine("6. {0}", number3);
methodD(10);
methodE(2);
methodF("9",1, num3: 1);
methodF("10", num3: 1, num1: 3);
}//end main
static void methodA(int number1)
{
number1 += 10;
Console.WriteLine("1. {0}", number1);
number1 += 10;
}//end method
static void methodB(ref int number2)
{
number2 += 10;
Console.WriteLine("3. {0}", number2);
number2 += 10;
}//end method
static void methodC(out int number3, int number1, int number2)
{
number3 = 50;
Console.WriteLine("5. {0}", number3);
number3 = 10;
}//end methodC
static void methodD(double value)
{
Console.WriteLine("7. {0} as a double", value);
}//end methodD
static void methodD(float value)
{
Console.WriteLine("7. {0} as a float", value);
}//end methodD
static void methodE(int num1 = 1, int num2 = 2, int num3 = 3)
{ Console.WriteLine("8. {0}", (num1 * num2 * num3));
}//end methodE
static void methodF(string s, int num1 =1, int num2 =2, int num3 =3)
{ Console.WriteLine("{0}. {1}",s , (num1 * num2 * num3));
}//end method
[10]
Total [40]