You are on page 1of 5

Class Test 2

DATE:

15 August 2016

SESSION:

9:25 and 14:40

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

INSTRUCTIONAL PROGRAMME CODE:

BCNDIA
EXNDIT

INSTRUCTIONS:
Duration:

1 hour

Maximum Marks:

ANSWER ALL THE QUESTIONS.


THIS PAPER CONSISTS OF 5 PAGES.

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

Which of the following is a difference between a reference parameter and an


output parameter?
a. A reference parameter receives a memory address; an output parameter
does not.
b. A reference parameter occupies a unique memory address; an output
parameter does not.
c. A reference parameter must have an initial value; an output parameter
need not.
d. A reference parameter need not have an initial value; an output parameter
must.

1.7

A parameter array _____.


a.
b.
c.
d.

1.8

Correctly overloaded methods must have the same ____.


a.
b.
c.
d.

1.9

is declared using the keyword params


can accept any number of arguments of the same data type
Both of these are true.
None of these are true.

return type
identifier
parameter list
All of the above.

The process of determining which overloaded version of a method to execute is


overload _____
a.
b.
c.
d.

1.10

confusion
infusion
revolution
resolution

When one of a methods parameters is optional, it means that _____.


a. no arguments are required in a call to the method
b. a default value will be assigned to the parameter if no argument is sent for
it
c. a default value will override any argument value sent to it
d. you are not required to use the parameter within the method body
3

[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]

You might also like